]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
128bddac | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
3e21d1cb | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
c44ce173 | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
10 | * * |
11 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
12 | * modify it under the terms of version 2 of the GNU General * |
13 | * Public License as published by the Free Software Foundation. * | |
14 | * This program is distributed in the hope that it will be useful. * | |
15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
20 | * more details, a copy of which can be found in the file COPYING * | |
21 | * included with this package. * | |
dea3101e JB |
22 | *******************************************************************/ |
23 | ||
dea3101e JB |
24 | #include <linux/blkdev.h> |
25 | #include <linux/pci.h> | |
26 | #include <linux/interrupt.h> | |
27 | #include <linux/delay.h> | |
5a0e3ad6 | 28 | #include <linux/slab.h> |
1c2ba475 | 29 | #include <linux/lockdep.h> |
dea3101e | 30 | |
91886523 | 31 | #include <scsi/scsi.h> |
dea3101e JB |
32 | #include <scsi/scsi_cmnd.h> |
33 | #include <scsi/scsi_device.h> | |
34 | #include <scsi/scsi_host.h> | |
f888ba3c | 35 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 36 | #include <scsi/fc/fc_fs.h> |
0d878419 | 37 | #include <linux/aer.h> |
1351e69f JS |
38 | #ifdef CONFIG_X86 |
39 | #include <asm/set_memory.h> | |
40 | #endif | |
dea3101e | 41 | |
895427bd JS |
42 | #include <linux/nvme-fc-driver.h> |
43 | ||
da0436e9 | 44 | #include "lpfc_hw4.h" |
dea3101e JB |
45 | #include "lpfc_hw.h" |
46 | #include "lpfc_sli.h" | |
da0436e9 | 47 | #include "lpfc_sli4.h" |
ea2151b4 | 48 | #include "lpfc_nl.h" |
dea3101e | 49 | #include "lpfc_disc.h" |
dea3101e | 50 | #include "lpfc.h" |
895427bd JS |
51 | #include "lpfc_scsi.h" |
52 | #include "lpfc_nvme.h" | |
f358dd0c | 53 | #include "lpfc_nvmet.h" |
dea3101e JB |
54 | #include "lpfc_crtn.h" |
55 | #include "lpfc_logmsg.h" | |
56 | #include "lpfc_compat.h" | |
858c9f6c | 57 | #include "lpfc_debugfs.h" |
04c68496 | 58 | #include "lpfc_vport.h" |
61bda8f7 | 59 | #include "lpfc_version.h" |
dea3101e JB |
60 | |
61 | /* There are only four IOCB completion types. */ | |
62 | typedef enum _lpfc_iocb_type { | |
63 | LPFC_UNKNOWN_IOCB, | |
64 | LPFC_UNSOL_IOCB, | |
65 | LPFC_SOL_IOCB, | |
66 | LPFC_ABORT_IOCB | |
67 | } lpfc_iocb_type; | |
68 | ||
4f774513 JS |
69 | |
70 | /* Provide function prototypes local to this module. */ | |
71 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
72 | uint32_t); | |
73 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
74 | uint8_t *, uint32_t *); |
75 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
76 | struct lpfc_iocbq *); | |
6669f9bb JS |
77 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
78 | struct hbq_dmabuf *); | |
ae9e28f3 JS |
79 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
80 | struct hbq_dmabuf *dmabuf); | |
895427bd | 81 | static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba *, struct lpfc_queue *, |
0558056c | 82 | struct lpfc_cqe *); |
895427bd | 83 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
8a9d2e80 | 84 | int); |
f485c18d DK |
85 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
86 | struct lpfc_eqe *eqe, uint32_t qidx); | |
e8d3c3b1 JS |
87 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
88 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); | |
895427bd JS |
89 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
90 | struct lpfc_sli_ring *pring, | |
91 | struct lpfc_iocbq *cmdiocb); | |
0558056c | 92 | |
4f774513 JS |
93 | static IOCB_t * |
94 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
95 | { | |
96 | return &iocbq->iocb; | |
97 | } | |
98 | ||
48f8fdb4 JS |
99 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
100 | /** | |
101 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function | |
102 | * @srcp: Source memory pointer. | |
103 | * @destp: Destination memory pointer. | |
104 | * @cnt: Number of words required to be copied. | |
105 | * Must be a multiple of sizeof(uint64_t) | |
106 | * | |
107 | * This function is used for copying data between driver memory | |
108 | * and the SLI WQ. This function also changes the endianness | |
109 | * of each word if native endianness is different from SLI | |
110 | * endianness. This function can be called with or without | |
111 | * lock. | |
112 | **/ | |
113 | void | |
114 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
115 | { | |
116 | uint64_t *src = srcp; | |
117 | uint64_t *dest = destp; | |
118 | int i; | |
119 | ||
120 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) | |
121 | *dest++ = *src++; | |
122 | } | |
123 | #else | |
124 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) | |
125 | #endif | |
126 | ||
4f774513 JS |
127 | /** |
128 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
129 | * @q: The Work Queue to operate on. | |
130 | * @wqe: The work Queue Entry to put on the Work queue. | |
131 | * | |
132 | * This routine will copy the contents of @wqe to the next available entry on | |
133 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
134 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
135 | * successful. If no entries are available on @q then this function will return | |
136 | * -ENOMEM. | |
137 | * The caller is expected to hold the hbalock when calling this routine. | |
138 | **/ | |
cd22d605 | 139 | static int |
205e8240 | 140 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
4f774513 | 141 | { |
2e90f4b5 | 142 | union lpfc_wqe *temp_wqe; |
4f774513 JS |
143 | struct lpfc_register doorbell; |
144 | uint32_t host_index; | |
027140ea | 145 | uint32_t idx; |
1351e69f JS |
146 | uint32_t i = 0; |
147 | uint8_t *tmp; | |
5cc167dd | 148 | u32 if_type; |
4f774513 | 149 | |
2e90f4b5 JS |
150 | /* sanity check on queue memory */ |
151 | if (unlikely(!q)) | |
152 | return -ENOMEM; | |
153 | temp_wqe = q->qe[q->host_index].wqe; | |
154 | ||
4f774513 | 155 | /* If the host has not yet processed the next entry then we are done */ |
027140ea JS |
156 | idx = ((q->host_index + 1) % q->entry_count); |
157 | if (idx == q->hba_index) { | |
b84daac9 | 158 | q->WQ_overflow++; |
cd22d605 | 159 | return -EBUSY; |
b84daac9 JS |
160 | } |
161 | q->WQ_posted++; | |
4f774513 | 162 | /* set consumption flag every once in a while */ |
ff78d8f9 | 163 | if (!((q->host_index + 1) % q->entry_repost)) |
f0d9bccc | 164 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
04673e38 JS |
165 | else |
166 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); | |
fedd3b7b JS |
167 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
168 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
48f8fdb4 | 169 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
1351e69f JS |
170 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
171 | /* write to DPP aperture taking advatage of Combined Writes */ | |
4c06619f JS |
172 | tmp = (uint8_t *)temp_wqe; |
173 | #ifdef __raw_writeq | |
1351e69f | 174 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
4c06619f JS |
175 | __raw_writeq(*((uint64_t *)(tmp + i)), |
176 | q->dpp_regaddr + i); | |
177 | #else | |
178 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) | |
179 | __raw_writel(*((uint32_t *)(tmp + i)), | |
180 | q->dpp_regaddr + i); | |
181 | #endif | |
1351e69f JS |
182 | } |
183 | /* ensure WQE bcopy and DPP flushed before doorbell write */ | |
6b3b3bdb | 184 | wmb(); |
4f774513 JS |
185 | |
186 | /* Update the host index before invoking device */ | |
187 | host_index = q->host_index; | |
027140ea JS |
188 | |
189 | q->host_index = idx; | |
4f774513 JS |
190 | |
191 | /* Ring Doorbell */ | |
192 | doorbell.word0 = 0; | |
962bc51b | 193 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
1351e69f JS |
194 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
195 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); | |
196 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); | |
197 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, | |
198 | q->dpp_id); | |
199 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, | |
200 | q->queue_id); | |
201 | } else { | |
202 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); | |
1351e69f | 203 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
5cc167dd JS |
204 | |
205 | /* Leave bits <23:16> clear for if_type 6 dpp */ | |
206 | if_type = bf_get(lpfc_sli_intf_if_type, | |
207 | &q->phba->sli4_hba.sli_intf); | |
208 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) | |
209 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, | |
210 | host_index); | |
1351e69f | 211 | } |
962bc51b JS |
212 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
213 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); | |
214 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); | |
215 | } else { | |
216 | return -EINVAL; | |
217 | } | |
218 | writel(doorbell.word0, q->db_regaddr); | |
4f774513 JS |
219 | |
220 | return 0; | |
221 | } | |
222 | ||
223 | /** | |
224 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
225 | * @q: The Work Queue to operate on. | |
226 | * @index: The index to advance the hba index to. | |
227 | * | |
228 | * This routine will update the HBA index of a queue to reflect consumption of | |
229 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
230 | * an entry the host calls this function to update the queue's internal | |
231 | * pointers. This routine returns the number of entries that were consumed by | |
232 | * the HBA. | |
233 | **/ | |
234 | static uint32_t | |
235 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
236 | { | |
237 | uint32_t released = 0; | |
238 | ||
2e90f4b5 JS |
239 | /* sanity check on queue memory */ |
240 | if (unlikely(!q)) | |
241 | return 0; | |
242 | ||
4f774513 JS |
243 | if (q->hba_index == index) |
244 | return 0; | |
245 | do { | |
246 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
247 | released++; | |
248 | } while (q->hba_index != index); | |
249 | return released; | |
250 | } | |
251 | ||
252 | /** | |
253 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
254 | * @q: The Mailbox Queue to operate on. | |
255 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
256 | * | |
257 | * This routine will copy the contents of @mqe to the next available entry on | |
258 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
259 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
260 | * successful. If no entries are available on @q then this function will return | |
261 | * -ENOMEM. | |
262 | * The caller is expected to hold the hbalock when calling this routine. | |
263 | **/ | |
264 | static uint32_t | |
265 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
266 | { | |
2e90f4b5 | 267 | struct lpfc_mqe *temp_mqe; |
4f774513 | 268 | struct lpfc_register doorbell; |
4f774513 | 269 | |
2e90f4b5 JS |
270 | /* sanity check on queue memory */ |
271 | if (unlikely(!q)) | |
272 | return -ENOMEM; | |
273 | temp_mqe = q->qe[q->host_index].mqe; | |
274 | ||
4f774513 JS |
275 | /* If the host has not yet processed the next entry then we are done */ |
276 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
277 | return -ENOMEM; | |
48f8fdb4 | 278 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
4f774513 JS |
279 | /* Save off the mailbox pointer for completion */ |
280 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
281 | ||
282 | /* Update the host index before invoking device */ | |
4f774513 JS |
283 | q->host_index = ((q->host_index + 1) % q->entry_count); |
284 | ||
285 | /* Ring Doorbell */ | |
286 | doorbell.word0 = 0; | |
287 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
288 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
289 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
4f774513 JS |
290 | return 0; |
291 | } | |
292 | ||
293 | /** | |
294 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
295 | * @q: The Mailbox Queue to operate on. | |
296 | * | |
297 | * This routine will update the HBA index of a queue to reflect consumption of | |
298 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
299 | * an entry the host calls this function to update the queue's internal | |
300 | * pointers. This routine returns the number of entries that were consumed by | |
301 | * the HBA. | |
302 | **/ | |
303 | static uint32_t | |
304 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
305 | { | |
2e90f4b5 JS |
306 | /* sanity check on queue memory */ |
307 | if (unlikely(!q)) | |
308 | return 0; | |
309 | ||
4f774513 JS |
310 | /* Clear the mailbox pointer for completion */ |
311 | q->phba->mbox = NULL; | |
312 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
313 | return 1; | |
314 | } | |
315 | ||
316 | /** | |
317 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
318 | * @q: The Event Queue to get the first valid EQE from | |
319 | * | |
320 | * This routine will get the first valid Event Queue Entry from @q, update | |
321 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
322 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
323 | * processed, but not popped back to the HBA then this routine will return NULL. | |
324 | **/ | |
325 | static struct lpfc_eqe * | |
326 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
327 | { | |
7365f6fd | 328 | struct lpfc_hba *phba; |
2e90f4b5 | 329 | struct lpfc_eqe *eqe; |
027140ea | 330 | uint32_t idx; |
2e90f4b5 JS |
331 | |
332 | /* sanity check on queue memory */ | |
333 | if (unlikely(!q)) | |
334 | return NULL; | |
7365f6fd | 335 | phba = q->phba; |
2e90f4b5 | 336 | eqe = q->qe[q->hba_index].eqe; |
4f774513 JS |
337 | |
338 | /* If the next EQE is not valid then we are done */ | |
7365f6fd | 339 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
4f774513 JS |
340 | return NULL; |
341 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
342 | idx = ((q->hba_index + 1) % q->entry_count); |
343 | if (idx == q->host_index) | |
4f774513 JS |
344 | return NULL; |
345 | ||
027140ea | 346 | q->hba_index = idx; |
7365f6fd JS |
347 | /* if the index wrapped around, toggle the valid bit */ |
348 | if (phba->sli4_hba.pc_sli4_params.eqav && !q->hba_index) | |
349 | q->qe_valid = (q->qe_valid) ? 0 : 1; | |
350 | ||
27f344eb JS |
351 | |
352 | /* | |
353 | * insert barrier for instruction interlock : data from the hardware | |
354 | * must have the valid bit checked before it can be copied and acted | |
2ea259ee JS |
355 | * upon. Speculative instructions were allowing a bcopy at the start |
356 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately | |
357 | * after our return, to copy data before the valid bit check above | |
358 | * was done. As such, some of the copied data was stale. The barrier | |
359 | * ensures the check is before any data is copied. | |
27f344eb JS |
360 | */ |
361 | mb(); | |
4f774513 JS |
362 | return eqe; |
363 | } | |
364 | ||
ba20c853 JS |
365 | /** |
366 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ | |
367 | * @q: The Event Queue to disable interrupts | |
368 | * | |
369 | **/ | |
b71413dd | 370 | inline void |
ba20c853 JS |
371 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
372 | { | |
373 | struct lpfc_register doorbell; | |
374 | ||
375 | doorbell.word0 = 0; | |
376 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
377 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
378 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, | |
379 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
380 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
9dd35425 | 381 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
ba20c853 JS |
382 | } |
383 | ||
27d6ac0a JS |
384 | /** |
385 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ | |
386 | * @q: The Event Queue to disable interrupts | |
387 | * | |
388 | **/ | |
389 | inline void | |
390 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) | |
391 | { | |
392 | struct lpfc_register doorbell; | |
393 | ||
394 | doorbell.word0 = 0; | |
aad59d5d | 395 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
27d6ac0a JS |
396 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
397 | } | |
398 | ||
4f774513 JS |
399 | /** |
400 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
401 | * @q: The Event Queue that the host has completed processing for. | |
402 | * @arm: Indicates whether the host wants to arms this CQ. | |
403 | * | |
404 | * This routine will mark all Event Queue Entries on @q, from the last | |
405 | * known completed entry to the last entry that was processed, as completed | |
406 | * by clearing the valid bit for each completion queue entry. Then it will | |
407 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
408 | * The internal host index in the @q will be updated by this routine to indicate | |
409 | * that the host has finished processing the entries. The @arm parameter | |
410 | * indicates that the queue should be rearmed when ringing the doorbell. | |
411 | * | |
412 | * This function will return the number of EQEs that were popped. | |
413 | **/ | |
414 | uint32_t | |
415 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
416 | { | |
417 | uint32_t released = 0; | |
7365f6fd | 418 | struct lpfc_hba *phba; |
4f774513 JS |
419 | struct lpfc_eqe *temp_eqe; |
420 | struct lpfc_register doorbell; | |
421 | ||
2e90f4b5 JS |
422 | /* sanity check on queue memory */ |
423 | if (unlikely(!q)) | |
424 | return 0; | |
7365f6fd | 425 | phba = q->phba; |
2e90f4b5 | 426 | |
4f774513 JS |
427 | /* while there are valid entries */ |
428 | while (q->hba_index != q->host_index) { | |
7365f6fd JS |
429 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
430 | temp_eqe = q->qe[q->host_index].eqe; | |
431 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); | |
432 | } | |
4f774513 JS |
433 | released++; |
434 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
435 | } | |
436 | if (unlikely(released == 0 && !arm)) | |
437 | return 0; | |
438 | ||
439 | /* ring doorbell for number popped */ | |
440 | doorbell.word0 = 0; | |
441 | if (arm) { | |
442 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
443 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
444 | } | |
445 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
446 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
6b5151fd JS |
447 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
448 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
449 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
9dd35425 | 450 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
a747c9ce JS |
451 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
452 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
9dd35425 | 453 | readl(q->phba->sli4_hba.EQDBregaddr); |
4f774513 JS |
454 | return released; |
455 | } | |
456 | ||
27d6ac0a JS |
457 | /** |
458 | * lpfc_sli4_if6_eq_release - Indicates the host has finished processing an EQ | |
459 | * @q: The Event Queue that the host has completed processing for. | |
460 | * @arm: Indicates whether the host wants to arms this CQ. | |
461 | * | |
462 | * This routine will mark all Event Queue Entries on @q, from the last | |
463 | * known completed entry to the last entry that was processed, as completed | |
464 | * by clearing the valid bit for each completion queue entry. Then it will | |
465 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
466 | * The internal host index in the @q will be updated by this routine to indicate | |
467 | * that the host has finished processing the entries. The @arm parameter | |
468 | * indicates that the queue should be rearmed when ringing the doorbell. | |
469 | * | |
470 | * This function will return the number of EQEs that were popped. | |
471 | **/ | |
472 | uint32_t | |
473 | lpfc_sli4_if6_eq_release(struct lpfc_queue *q, bool arm) | |
474 | { | |
475 | uint32_t released = 0; | |
7365f6fd | 476 | struct lpfc_hba *phba; |
27d6ac0a JS |
477 | struct lpfc_eqe *temp_eqe; |
478 | struct lpfc_register doorbell; | |
479 | ||
480 | /* sanity check on queue memory */ | |
481 | if (unlikely(!q)) | |
482 | return 0; | |
7365f6fd | 483 | phba = q->phba; |
27d6ac0a JS |
484 | |
485 | /* while there are valid entries */ | |
486 | while (q->hba_index != q->host_index) { | |
7365f6fd JS |
487 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
488 | temp_eqe = q->qe[q->host_index].eqe; | |
489 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); | |
490 | } | |
27d6ac0a JS |
491 | released++; |
492 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
493 | } | |
494 | if (unlikely(released == 0 && !arm)) | |
495 | return 0; | |
496 | ||
497 | /* ring doorbell for number popped */ | |
498 | doorbell.word0 = 0; | |
499 | if (arm) | |
500 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); | |
501 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, released); | |
502 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); | |
503 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); | |
504 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ | |
505 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
506 | readl(q->phba->sli4_hba.EQDBregaddr); | |
507 | return released; | |
508 | } | |
509 | ||
4f774513 JS |
510 | /** |
511 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
512 | * @q: The Completion Queue to get the first valid CQE from | |
513 | * | |
514 | * This routine will get the first valid Completion Queue Entry from @q, update | |
515 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
516 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
517 | * processed, but not popped back to the HBA then this routine will return NULL. | |
518 | **/ | |
519 | static struct lpfc_cqe * | |
520 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
521 | { | |
7365f6fd | 522 | struct lpfc_hba *phba; |
4f774513 | 523 | struct lpfc_cqe *cqe; |
027140ea | 524 | uint32_t idx; |
4f774513 | 525 | |
2e90f4b5 JS |
526 | /* sanity check on queue memory */ |
527 | if (unlikely(!q)) | |
528 | return NULL; | |
7365f6fd JS |
529 | phba = q->phba; |
530 | cqe = q->qe[q->hba_index].cqe; | |
2e90f4b5 | 531 | |
4f774513 | 532 | /* If the next CQE is not valid then we are done */ |
7365f6fd | 533 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
4f774513 JS |
534 | return NULL; |
535 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
536 | idx = ((q->hba_index + 1) % q->entry_count); |
537 | if (idx == q->host_index) | |
4f774513 JS |
538 | return NULL; |
539 | ||
027140ea | 540 | q->hba_index = idx; |
7365f6fd JS |
541 | /* if the index wrapped around, toggle the valid bit */ |
542 | if (phba->sli4_hba.pc_sli4_params.cqav && !q->hba_index) | |
543 | q->qe_valid = (q->qe_valid) ? 0 : 1; | |
27f344eb JS |
544 | |
545 | /* | |
546 | * insert barrier for instruction interlock : data from the hardware | |
547 | * must have the valid bit checked before it can be copied and acted | |
2ea259ee JS |
548 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
549 | * instructions allowing action on content before valid bit checked, | |
550 | * add barrier here as well. May not be needed as "content" is a | |
551 | * single 32-bit entity here (vs multi word structure for cq's). | |
27f344eb JS |
552 | */ |
553 | mb(); | |
4f774513 JS |
554 | return cqe; |
555 | } | |
556 | ||
557 | /** | |
558 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
559 | * @q: The Completion Queue that the host has completed processing for. | |
560 | * @arm: Indicates whether the host wants to arms this CQ. | |
561 | * | |
562 | * This routine will mark all Completion queue entries on @q, from the last | |
563 | * known completed entry to the last entry that was processed, as completed | |
564 | * by clearing the valid bit for each completion queue entry. Then it will | |
565 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
566 | * The internal host index in the @q will be updated by this routine to indicate | |
567 | * that the host has finished processing the entries. The @arm parameter | |
568 | * indicates that the queue should be rearmed when ringing the doorbell. | |
569 | * | |
570 | * This function will return the number of CQEs that were released. | |
571 | **/ | |
572 | uint32_t | |
573 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
574 | { | |
575 | uint32_t released = 0; | |
7365f6fd | 576 | struct lpfc_hba *phba; |
4f774513 JS |
577 | struct lpfc_cqe *temp_qe; |
578 | struct lpfc_register doorbell; | |
579 | ||
2e90f4b5 JS |
580 | /* sanity check on queue memory */ |
581 | if (unlikely(!q)) | |
582 | return 0; | |
7365f6fd JS |
583 | phba = q->phba; |
584 | ||
4f774513 JS |
585 | /* while there are valid entries */ |
586 | while (q->hba_index != q->host_index) { | |
7365f6fd JS |
587 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
588 | temp_qe = q->qe[q->host_index].cqe; | |
589 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); | |
590 | } | |
4f774513 JS |
591 | released++; |
592 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
593 | } | |
594 | if (unlikely(released == 0 && !arm)) | |
595 | return 0; | |
596 | ||
597 | /* ring doorbell for number popped */ | |
598 | doorbell.word0 = 0; | |
599 | if (arm) | |
600 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
601 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
602 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
6b5151fd JS |
603 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
604 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); | |
605 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); | |
9dd35425 | 606 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
4f774513 JS |
607 | return released; |
608 | } | |
609 | ||
27d6ac0a JS |
610 | /** |
611 | * lpfc_sli4_if6_cq_release - Indicates the host has finished processing a CQ | |
612 | * @q: The Completion Queue that the host has completed processing for. | |
613 | * @arm: Indicates whether the host wants to arms this CQ. | |
614 | * | |
615 | * This routine will mark all Completion queue entries on @q, from the last | |
616 | * known completed entry to the last entry that was processed, as completed | |
617 | * by clearing the valid bit for each completion queue entry. Then it will | |
618 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
619 | * The internal host index in the @q will be updated by this routine to indicate | |
620 | * that the host has finished processing the entries. The @arm parameter | |
621 | * indicates that the queue should be rearmed when ringing the doorbell. | |
622 | * | |
623 | * This function will return the number of CQEs that were released. | |
624 | **/ | |
625 | uint32_t | |
626 | lpfc_sli4_if6_cq_release(struct lpfc_queue *q, bool arm) | |
627 | { | |
628 | uint32_t released = 0; | |
7365f6fd | 629 | struct lpfc_hba *phba; |
27d6ac0a JS |
630 | struct lpfc_cqe *temp_qe; |
631 | struct lpfc_register doorbell; | |
632 | ||
633 | /* sanity check on queue memory */ | |
634 | if (unlikely(!q)) | |
635 | return 0; | |
7365f6fd JS |
636 | phba = q->phba; |
637 | ||
27d6ac0a JS |
638 | /* while there are valid entries */ |
639 | while (q->hba_index != q->host_index) { | |
7365f6fd JS |
640 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
641 | temp_qe = q->qe[q->host_index].cqe; | |
642 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); | |
643 | } | |
27d6ac0a JS |
644 | released++; |
645 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
646 | } | |
647 | if (unlikely(released == 0 && !arm)) | |
648 | return 0; | |
649 | ||
650 | /* ring doorbell for number popped */ | |
651 | doorbell.word0 = 0; | |
652 | if (arm) | |
653 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); | |
654 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, released); | |
655 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); | |
656 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); | |
657 | return released; | |
658 | } | |
659 | ||
4f774513 JS |
660 | /** |
661 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
662 | * @q: The Header Receive Queue to operate on. | |
663 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
664 | * | |
665 | * This routine will copy the contents of @wqe to the next available entry on | |
666 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
667 | * HBA to start processing the Receive Queue Entry. This function returns the | |
668 | * index that the rqe was copied to if successful. If no entries are available | |
669 | * on @q then this function will return -ENOMEM. | |
670 | * The caller is expected to hold the hbalock when calling this routine. | |
671 | **/ | |
895427bd | 672 | int |
4f774513 JS |
673 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
674 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
675 | { | |
2e90f4b5 JS |
676 | struct lpfc_rqe *temp_hrqe; |
677 | struct lpfc_rqe *temp_drqe; | |
4f774513 | 678 | struct lpfc_register doorbell; |
cbc5de1b JS |
679 | int hq_put_index; |
680 | int dq_put_index; | |
4f774513 | 681 | |
2e90f4b5 JS |
682 | /* sanity check on queue memory */ |
683 | if (unlikely(!hq) || unlikely(!dq)) | |
684 | return -ENOMEM; | |
cbc5de1b JS |
685 | hq_put_index = hq->host_index; |
686 | dq_put_index = dq->host_index; | |
687 | temp_hrqe = hq->qe[hq_put_index].rqe; | |
688 | temp_drqe = dq->qe[dq_put_index].rqe; | |
2e90f4b5 | 689 | |
4f774513 JS |
690 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
691 | return -EINVAL; | |
cbc5de1b | 692 | if (hq_put_index != dq_put_index) |
4f774513 JS |
693 | return -EINVAL; |
694 | /* If the host has not yet processed the next entry then we are done */ | |
cbc5de1b | 695 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
4f774513 | 696 | return -EBUSY; |
48f8fdb4 JS |
697 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
698 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
4f774513 JS |
699 | |
700 | /* Update the host index to point to the next slot */ | |
cbc5de1b JS |
701 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
702 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); | |
61f3d4bf | 703 | hq->RQ_buf_posted++; |
4f774513 JS |
704 | |
705 | /* Ring The Header Receive Queue Doorbell */ | |
73d91e50 | 706 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 | 707 | doorbell.word0 = 0; |
962bc51b JS |
708 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
709 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, | |
710 | hq->entry_repost); | |
711 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); | |
712 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { | |
713 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, | |
714 | hq->entry_repost); | |
715 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, | |
716 | hq->host_index); | |
717 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); | |
718 | } else { | |
719 | return -EINVAL; | |
720 | } | |
721 | writel(doorbell.word0, hq->db_regaddr); | |
4f774513 | 722 | } |
cbc5de1b | 723 | return hq_put_index; |
4f774513 JS |
724 | } |
725 | ||
726 | /** | |
727 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
728 | * @q: The Header Receive Queue to operate on. | |
729 | * | |
730 | * This routine will update the HBA index of a queue to reflect consumption of | |
731 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
732 | * consumed an entry the host calls this function to update the queue's | |
733 | * internal pointers. This routine returns the number of entries that were | |
734 | * consumed by the HBA. | |
735 | **/ | |
736 | static uint32_t | |
737 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
738 | { | |
2e90f4b5 JS |
739 | /* sanity check on queue memory */ |
740 | if (unlikely(!hq) || unlikely(!dq)) | |
741 | return 0; | |
742 | ||
4f774513 JS |
743 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
744 | return 0; | |
745 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
746 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
747 | return 1; | |
748 | } | |
749 | ||
e59058c4 | 750 | /** |
3621a710 | 751 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
752 | * @phba: Pointer to HBA context object. |
753 | * @pring: Pointer to driver SLI ring object. | |
754 | * | |
755 | * This function returns pointer to next command iocb entry | |
756 | * in the command ring. The caller must hold hbalock to prevent | |
757 | * other threads consume the next command iocb. | |
758 | * SLI-2/SLI-3 provide different sized iocbs. | |
759 | **/ | |
ed957684 JS |
760 | static inline IOCB_t * |
761 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
762 | { | |
7e56aa25 JS |
763 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
764 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); | |
ed957684 JS |
765 | } |
766 | ||
e59058c4 | 767 | /** |
3621a710 | 768 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
769 | * @phba: Pointer to HBA context object. |
770 | * @pring: Pointer to driver SLI ring object. | |
771 | * | |
772 | * This function returns pointer to next response iocb entry | |
773 | * in the response ring. The caller must hold hbalock to make sure | |
774 | * that no other thread consume the next response iocb. | |
775 | * SLI-2/SLI-3 provide different sized iocbs. | |
776 | **/ | |
ed957684 JS |
777 | static inline IOCB_t * |
778 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
779 | { | |
7e56aa25 JS |
780 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
781 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); | |
ed957684 JS |
782 | } |
783 | ||
e59058c4 | 784 | /** |
3621a710 | 785 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
786 | * @phba: Pointer to HBA context object. |
787 | * | |
788 | * This function is called with hbalock held. This function | |
789 | * allocates a new driver iocb object from the iocb pool. If the | |
790 | * allocation is successful, it returns pointer to the newly | |
791 | * allocated iocb object else it returns NULL. | |
792 | **/ | |
4f2e66c6 | 793 | struct lpfc_iocbq * |
2e0fef85 | 794 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
0bd4ca25 JSEC |
795 | { |
796 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
797 | struct lpfc_iocbq * iocbq = NULL; | |
798 | ||
1c2ba475 JT |
799 | lockdep_assert_held(&phba->hbalock); |
800 | ||
0bd4ca25 | 801 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
2a9bf3d0 JS |
802 | if (iocbq) |
803 | phba->iocb_cnt++; | |
804 | if (phba->iocb_cnt > phba->iocb_max) | |
805 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
806 | return iocbq; |
807 | } | |
808 | ||
da0436e9 JS |
809 | /** |
810 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
811 | * @phba: Pointer to HBA context object. | |
812 | * @xritag: XRI value. | |
813 | * | |
814 | * This function clears the sglq pointer from the array of acive | |
815 | * sglq's. The xritag that is passed in is used to index into the | |
816 | * array. Before the xritag can be used it needs to be adjusted | |
817 | * by subtracting the xribase. | |
818 | * | |
819 | * Returns sglq ponter = success, NULL = Failure. | |
820 | **/ | |
895427bd | 821 | struct lpfc_sglq * |
da0436e9 JS |
822 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
823 | { | |
da0436e9 | 824 | struct lpfc_sglq *sglq; |
6d368e53 JS |
825 | |
826 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
827 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
828 | return sglq; |
829 | } | |
830 | ||
831 | /** | |
832 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
833 | * @phba: Pointer to HBA context object. | |
834 | * @xritag: XRI value. | |
835 | * | |
836 | * This function returns the sglq pointer from the array of acive | |
837 | * sglq's. The xritag that is passed in is used to index into the | |
838 | * array. Before the xritag can be used it needs to be adjusted | |
839 | * by subtracting the xribase. | |
840 | * | |
841 | * Returns sglq ponter = success, NULL = Failure. | |
842 | **/ | |
0f65ff68 | 843 | struct lpfc_sglq * |
da0436e9 JS |
844 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
845 | { | |
da0436e9 | 846 | struct lpfc_sglq *sglq; |
6d368e53 JS |
847 | |
848 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
849 | return sglq; |
850 | } | |
851 | ||
19ca7609 | 852 | /** |
1151e3ec | 853 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
854 | * @phba: Pointer to HBA context object. |
855 | * @xritag: xri used in this exchange. | |
856 | * @rrq: The RRQ to be cleared. | |
857 | * | |
19ca7609 | 858 | **/ |
1151e3ec JS |
859 | void |
860 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
861 | uint16_t xritag, | |
862 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 863 | { |
1151e3ec | 864 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 865 | |
1151e3ec JS |
866 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
867 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
868 | |
869 | /* The target DID could have been swapped (cable swap) | |
870 | * we should use the ndlp from the findnode if it is | |
871 | * available. | |
872 | */ | |
1151e3ec | 873 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
874 | ndlp = rrq->ndlp; |
875 | ||
1151e3ec JS |
876 | if (!ndlp) |
877 | goto out; | |
878 | ||
cff261f6 | 879 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
19ca7609 JS |
880 | rrq->send_rrq = 0; |
881 | rrq->xritag = 0; | |
882 | rrq->rrq_stop_time = 0; | |
883 | } | |
1151e3ec | 884 | out: |
19ca7609 JS |
885 | mempool_free(rrq, phba->rrq_pool); |
886 | } | |
887 | ||
888 | /** | |
889 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
890 | * @phba: Pointer to HBA context object. | |
891 | * | |
892 | * This function is called with hbalock held. This function | |
893 | * Checks if stop_time (ratov from setting rrq active) has | |
894 | * been reached, if it has and the send_rrq flag is set then | |
895 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
896 | * then it will just call the routine to clear the rrq and | |
897 | * free the rrq resource. | |
898 | * The timer is set to the next rrq that is going to expire before | |
899 | * leaving the routine. | |
900 | * | |
901 | **/ | |
902 | void | |
903 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
904 | { | |
905 | struct lpfc_node_rrq *rrq; | |
906 | struct lpfc_node_rrq *nextrrq; | |
907 | unsigned long next_time; | |
908 | unsigned long iflags; | |
1151e3ec | 909 | LIST_HEAD(send_rrq); |
19ca7609 JS |
910 | |
911 | spin_lock_irqsave(&phba->hbalock, iflags); | |
912 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
256ec0d0 | 913 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
19ca7609 | 914 | list_for_each_entry_safe(rrq, nextrrq, |
1151e3ec JS |
915 | &phba->active_rrq_list, list) { |
916 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
917 | list_move(&rrq->list, &send_rrq); | |
918 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
919 | next_time = rrq->rrq_stop_time; |
920 | } | |
921 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
06918ac5 JS |
922 | if ((!list_empty(&phba->active_rrq_list)) && |
923 | (!(phba->pport->load_flag & FC_UNLOADING))) | |
19ca7609 | 924 | mod_timer(&phba->rrq_tmr, next_time); |
1151e3ec JS |
925 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
926 | list_del(&rrq->list); | |
927 | if (!rrq->send_rrq) | |
928 | /* this call will free the rrq */ | |
929 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
930 | else if (lpfc_send_rrq(phba, rrq)) { | |
931 | /* if we send the rrq then the completion handler | |
932 | * will clear the bit in the xribitmap. | |
933 | */ | |
934 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
935 | rrq); | |
936 | } | |
937 | } | |
19ca7609 JS |
938 | } |
939 | ||
940 | /** | |
941 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
942 | * @vport: Pointer to vport context object. | |
943 | * @xri: The xri used in the exchange. | |
944 | * @did: The targets DID for this exchange. | |
945 | * | |
946 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
947 | * rrq = rrq for this xri and target. | |
948 | **/ | |
949 | struct lpfc_node_rrq * | |
950 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
951 | { | |
952 | struct lpfc_hba *phba = vport->phba; | |
953 | struct lpfc_node_rrq *rrq; | |
954 | struct lpfc_node_rrq *nextrrq; | |
955 | unsigned long iflags; | |
956 | ||
957 | if (phba->sli_rev != LPFC_SLI_REV4) | |
958 | return NULL; | |
959 | spin_lock_irqsave(&phba->hbalock, iflags); | |
960 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
961 | if (rrq->vport == vport && rrq->xritag == xri && | |
962 | rrq->nlp_DID == did){ | |
963 | list_del(&rrq->list); | |
964 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
965 | return rrq; | |
966 | } | |
967 | } | |
968 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
969 | return NULL; | |
970 | } | |
971 | ||
972 | /** | |
973 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
974 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
975 | * @ndlp: Pointer to the lpfc_node_list structure. |
976 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
977 | * phba->active_rrq_list and clear the rrq. | |
978 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
979 | **/ |
980 | void | |
1151e3ec | 981 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
982 | |
983 | { | |
984 | struct lpfc_hba *phba = vport->phba; | |
985 | struct lpfc_node_rrq *rrq; | |
986 | struct lpfc_node_rrq *nextrrq; | |
987 | unsigned long iflags; | |
1151e3ec | 988 | LIST_HEAD(rrq_list); |
19ca7609 JS |
989 | |
990 | if (phba->sli_rev != LPFC_SLI_REV4) | |
991 | return; | |
1151e3ec JS |
992 | if (!ndlp) { |
993 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
994 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 995 | } |
1151e3ec JS |
996 | spin_lock_irqsave(&phba->hbalock, iflags); |
997 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
998 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
999 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 1000 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
1001 | |
1002 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
1003 | list_del(&rrq->list); | |
1004 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
1005 | } | |
19ca7609 JS |
1006 | } |
1007 | ||
19ca7609 | 1008 | /** |
1151e3ec | 1009 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
1010 | * @phba: Pointer to HBA context object. |
1011 | * @ndlp: Targets nodelist pointer for this exchange. | |
1012 | * @xritag the xri in the bitmap to test. | |
1013 | * | |
1014 | * This function is called with hbalock held. This function | |
1015 | * returns 0 = rrq not active for this xri | |
1016 | * 1 = rrq is valid for this xri. | |
1017 | **/ | |
1151e3ec JS |
1018 | int |
1019 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
1020 | uint16_t xritag) |
1021 | { | |
1c2ba475 | 1022 | lockdep_assert_held(&phba->hbalock); |
19ca7609 JS |
1023 | if (!ndlp) |
1024 | return 0; | |
cff261f6 JS |
1025 | if (!ndlp->active_rrqs_xri_bitmap) |
1026 | return 0; | |
1027 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
19ca7609 JS |
1028 | return 1; |
1029 | else | |
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | /** | |
1034 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
1035 | * @phba: Pointer to HBA context object. | |
1036 | * @ndlp: nodelist pointer for this target. | |
1037 | * @xritag: xri used in this exchange. | |
1038 | * @rxid: Remote Exchange ID. | |
1039 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
1040 | * | |
1041 | * This function takes the hbalock. | |
1042 | * The active bit is always set in the active rrq xri_bitmap even | |
1043 | * if there is no slot avaiable for the other rrq information. | |
1044 | * | |
1045 | * returns 0 rrq actived for this xri | |
1046 | * < 0 No memory or invalid ndlp. | |
1047 | **/ | |
1048 | int | |
1049 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
b42c07c8 | 1050 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
19ca7609 | 1051 | { |
19ca7609 | 1052 | unsigned long iflags; |
b42c07c8 JS |
1053 | struct lpfc_node_rrq *rrq; |
1054 | int empty; | |
1055 | ||
1056 | if (!ndlp) | |
1057 | return -EINVAL; | |
1058 | ||
1059 | if (!phba->cfg_enable_rrq) | |
1060 | return -EINVAL; | |
19ca7609 JS |
1061 | |
1062 | spin_lock_irqsave(&phba->hbalock, iflags); | |
b42c07c8 JS |
1063 | if (phba->pport->load_flag & FC_UNLOADING) { |
1064 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
1065 | goto out; | |
1066 | } | |
1067 | ||
1068 | /* | |
1069 | * set the active bit even if there is no mem available. | |
1070 | */ | |
1071 | if (NLP_CHK_FREE_REQ(ndlp)) | |
1072 | goto out; | |
1073 | ||
1074 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
1075 | goto out; | |
1076 | ||
cff261f6 JS |
1077 | if (!ndlp->active_rrqs_xri_bitmap) |
1078 | goto out; | |
1079 | ||
1080 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) | |
b42c07c8 JS |
1081 | goto out; |
1082 | ||
19ca7609 | 1083 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
b42c07c8 JS |
1084 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
1085 | if (!rrq) { | |
1086 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
1087 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" | |
1088 | " DID:0x%x Send:%d\n", | |
1089 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
1090 | return -EINVAL; | |
1091 | } | |
e5771b4d JS |
1092 | if (phba->cfg_enable_rrq == 1) |
1093 | rrq->send_rrq = send_rrq; | |
1094 | else | |
1095 | rrq->send_rrq = 0; | |
b42c07c8 | 1096 | rrq->xritag = xritag; |
256ec0d0 JS |
1097 | rrq->rrq_stop_time = jiffies + |
1098 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); | |
b42c07c8 JS |
1099 | rrq->ndlp = ndlp; |
1100 | rrq->nlp_DID = ndlp->nlp_DID; | |
1101 | rrq->vport = ndlp->vport; | |
1102 | rrq->rxid = rxid; | |
b42c07c8 JS |
1103 | spin_lock_irqsave(&phba->hbalock, iflags); |
1104 | empty = list_empty(&phba->active_rrq_list); | |
1105 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
1106 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
1107 | if (empty) | |
1108 | lpfc_worker_wake_up(phba); | |
1109 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1110 | return 0; | |
1111 | out: | |
1112 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1113 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
1114 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
1115 | " DID:0x%x Send:%d\n", | |
1116 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
1117 | return -EINVAL; | |
19ca7609 JS |
1118 | } |
1119 | ||
da0436e9 | 1120 | /** |
895427bd | 1121 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
da0436e9 | 1122 | * @phba: Pointer to HBA context object. |
19ca7609 | 1123 | * @piocb: Pointer to the iocbq. |
da0436e9 | 1124 | * |
dafe8cea | 1125 | * This function is called with the ring lock held. This function |
6d368e53 | 1126 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
1127 | * list is not empty then it is successful, it returns pointer to the newly |
1128 | * allocated sglq object else it returns NULL. | |
1129 | **/ | |
1130 | static struct lpfc_sglq * | |
895427bd | 1131 | __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 | 1132 | { |
895427bd | 1133 | struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list; |
da0436e9 | 1134 | struct lpfc_sglq *sglq = NULL; |
19ca7609 | 1135 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
1136 | struct lpfc_scsi_buf *lpfc_cmd; |
1137 | struct lpfc_nodelist *ndlp; | |
1138 | int found = 0; | |
1139 | ||
1c2ba475 JT |
1140 | lockdep_assert_held(&phba->hbalock); |
1141 | ||
19ca7609 JS |
1142 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
1143 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
1144 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 | 1145 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
6c7cf486 | 1146 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
19ca7609 | 1147 | ndlp = piocbq->context_un.ndlp; |
6c7cf486 JS |
1148 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
1149 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) | |
1150 | ndlp = NULL; | |
1151 | else | |
1152 | ndlp = piocbq->context_un.ndlp; | |
1153 | } else { | |
19ca7609 | 1154 | ndlp = piocbq->context1; |
6c7cf486 | 1155 | } |
19ca7609 | 1156 | |
895427bd JS |
1157 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
1158 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); | |
19ca7609 JS |
1159 | start_sglq = sglq; |
1160 | while (!found) { | |
1161 | if (!sglq) | |
d11f54b7 | 1162 | break; |
895427bd JS |
1163 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
1164 | test_bit(sglq->sli4_lxritag, | |
1165 | ndlp->active_rrqs_xri_bitmap)) { | |
19ca7609 JS |
1166 | /* This xri has an rrq outstanding for this DID. |
1167 | * put it back in the list and get another xri. | |
1168 | */ | |
895427bd | 1169 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
19ca7609 | 1170 | sglq = NULL; |
895427bd | 1171 | list_remove_head(lpfc_els_sgl_list, sglq, |
19ca7609 JS |
1172 | struct lpfc_sglq, list); |
1173 | if (sglq == start_sglq) { | |
14041bd1 | 1174 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
19ca7609 JS |
1175 | sglq = NULL; |
1176 | break; | |
1177 | } else | |
1178 | continue; | |
1179 | } | |
1180 | sglq->ndlp = ndlp; | |
1181 | found = 1; | |
6d368e53 | 1182 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
1183 | sglq->state = SGL_ALLOCATED; |
1184 | } | |
895427bd | 1185 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
da0436e9 JS |
1186 | return sglq; |
1187 | } | |
1188 | ||
f358dd0c JS |
1189 | /** |
1190 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool | |
1191 | * @phba: Pointer to HBA context object. | |
1192 | * @piocb: Pointer to the iocbq. | |
1193 | * | |
1194 | * This function is called with the sgl_list lock held. This function | |
1195 | * gets a new driver sglq object from the sglq list. If the | |
1196 | * list is not empty then it is successful, it returns pointer to the newly | |
1197 | * allocated sglq object else it returns NULL. | |
1198 | **/ | |
1199 | struct lpfc_sglq * | |
1200 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) | |
1201 | { | |
1202 | struct list_head *lpfc_nvmet_sgl_list; | |
1203 | struct lpfc_sglq *sglq = NULL; | |
1204 | ||
1205 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; | |
1206 | ||
1207 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); | |
1208 | ||
1209 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); | |
1210 | if (!sglq) | |
1211 | return NULL; | |
1212 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; | |
1213 | sglq->state = SGL_ALLOCATED; | |
da0436e9 JS |
1214 | return sglq; |
1215 | } | |
1216 | ||
e59058c4 | 1217 | /** |
3621a710 | 1218 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
1219 | * @phba: Pointer to HBA context object. |
1220 | * | |
1221 | * This function is called with no lock held. This function | |
1222 | * allocates a new driver iocb object from the iocb pool. If the | |
1223 | * allocation is successful, it returns pointer to the newly | |
1224 | * allocated iocb object else it returns NULL. | |
1225 | **/ | |
2e0fef85 JS |
1226 | struct lpfc_iocbq * |
1227 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
1228 | { | |
1229 | struct lpfc_iocbq * iocbq = NULL; | |
1230 | unsigned long iflags; | |
1231 | ||
1232 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1233 | iocbq = __lpfc_sli_get_iocbq(phba); | |
1234 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1235 | return iocbq; | |
1236 | } | |
1237 | ||
4f774513 JS |
1238 | /** |
1239 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
1240 | * @phba: Pointer to HBA context object. | |
1241 | * @iocbq: Pointer to driver iocb object. | |
1242 | * | |
1243 | * This function is called with hbalock held to release driver | |
1244 | * iocb object to the iocb pool. The iotag in the iocb object | |
1245 | * does not change for each use of the iocb object. This function | |
1246 | * clears all other fields of the iocb object when it is freed. | |
1247 | * The sqlq structure that holds the xritag and phys and virtual | |
1248 | * mappings for the scatter gather list is retrieved from the | |
1249 | * active array of sglq. The get of the sglq pointer also clears | |
1250 | * the entry in the array. If the status of the IO indiactes that | |
1251 | * this IO was aborted then the sglq entry it put on the | |
1252 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
1253 | * IO has good status or fails for any other reason then the sglq | |
895427bd | 1254 | * entry is added to the free list (lpfc_els_sgl_list). |
4f774513 JS |
1255 | **/ |
1256 | static void | |
1257 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1258 | { | |
1259 | struct lpfc_sglq *sglq; | |
1260 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 | 1261 | unsigned long iflag = 0; |
895427bd | 1262 | struct lpfc_sli_ring *pring; |
4f774513 | 1263 | |
1c2ba475 JT |
1264 | lockdep_assert_held(&phba->hbalock); |
1265 | ||
4f774513 JS |
1266 | if (iocbq->sli4_xritag == NO_XRI) |
1267 | sglq = NULL; | |
1268 | else | |
6d368e53 JS |
1269 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
1270 | ||
0e9bb8d7 | 1271 | |
4f774513 | 1272 | if (sglq) { |
f358dd0c JS |
1273 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
1274 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, | |
1275 | iflag); | |
1276 | sglq->state = SGL_FREED; | |
1277 | sglq->ndlp = NULL; | |
1278 | list_add_tail(&sglq->list, | |
1279 | &phba->sli4_hba.lpfc_nvmet_sgl_list); | |
1280 | spin_unlock_irqrestore( | |
1281 | &phba->sli4_hba.sgl_list_lock, iflag); | |
1282 | goto out; | |
1283 | } | |
1284 | ||
895427bd | 1285 | pring = phba->sli4_hba.els_wq->pring; |
0f65ff68 JS |
1286 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
1287 | (sglq->state != SGL_XRI_ABORTED)) { | |
895427bd JS |
1288 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
1289 | iflag); | |
4f774513 | 1290 | list_add(&sglq->list, |
895427bd | 1291 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
4f774513 | 1292 | spin_unlock_irqrestore( |
895427bd | 1293 | &phba->sli4_hba.sgl_list_lock, iflag); |
0f65ff68 | 1294 | } else { |
895427bd JS |
1295 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
1296 | iflag); | |
0f65ff68 | 1297 | sglq->state = SGL_FREED; |
19ca7609 | 1298 | sglq->ndlp = NULL; |
fedd3b7b | 1299 | list_add_tail(&sglq->list, |
895427bd JS |
1300 | &phba->sli4_hba.lpfc_els_sgl_list); |
1301 | spin_unlock_irqrestore( | |
1302 | &phba->sli4_hba.sgl_list_lock, iflag); | |
2a9bf3d0 JS |
1303 | |
1304 | /* Check if TXQ queue needs to be serviced */ | |
0e9bb8d7 | 1305 | if (!list_empty(&pring->txq)) |
2a9bf3d0 | 1306 | lpfc_worker_wake_up(phba); |
0f65ff68 | 1307 | } |
4f774513 JS |
1308 | } |
1309 | ||
f358dd0c | 1310 | out: |
4f774513 JS |
1311 | /* |
1312 | * Clean all volatile data fields, preserve iotag and node struct. | |
1313 | */ | |
1314 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 1315 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 | 1316 | iocbq->sli4_xritag = NO_XRI; |
f358dd0c JS |
1317 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
1318 | LPFC_IO_NVME_LS); | |
4f774513 JS |
1319 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1320 | } | |
1321 | ||
2a9bf3d0 | 1322 | |
e59058c4 | 1323 | /** |
3772a991 | 1324 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
1325 | * @phba: Pointer to HBA context object. |
1326 | * @iocbq: Pointer to driver iocb object. | |
1327 | * | |
1328 | * This function is called with hbalock held to release driver | |
1329 | * iocb object to the iocb pool. The iotag in the iocb object | |
1330 | * does not change for each use of the iocb object. This function | |
1331 | * clears all other fields of the iocb object when it is freed. | |
1332 | **/ | |
a6ababd2 | 1333 | static void |
3772a991 | 1334 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1335 | { |
2e0fef85 | 1336 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 | 1337 | |
1c2ba475 | 1338 | lockdep_assert_held(&phba->hbalock); |
0e9bb8d7 | 1339 | |
604a3e30 JB |
1340 | /* |
1341 | * Clean all volatile data fields, preserve iotag and node struct. | |
1342 | */ | |
1343 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1344 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1345 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1346 | } | |
1347 | ||
3772a991 JS |
1348 | /** |
1349 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1350 | * @phba: Pointer to HBA context object. | |
1351 | * @iocbq: Pointer to driver iocb object. | |
1352 | * | |
1353 | * This function is called with hbalock held to release driver | |
1354 | * iocb object to the iocb pool. The iotag in the iocb object | |
1355 | * does not change for each use of the iocb object. This function | |
1356 | * clears all other fields of the iocb object when it is freed. | |
1357 | **/ | |
1358 | static void | |
1359 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1360 | { | |
1c2ba475 JT |
1361 | lockdep_assert_held(&phba->hbalock); |
1362 | ||
3772a991 | 1363 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
2a9bf3d0 | 1364 | phba->iocb_cnt--; |
3772a991 JS |
1365 | } |
1366 | ||
e59058c4 | 1367 | /** |
3621a710 | 1368 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1369 | * @phba: Pointer to HBA context object. |
1370 | * @iocbq: Pointer to driver iocb object. | |
1371 | * | |
1372 | * This function is called with no lock held to release the iocb to | |
1373 | * iocb pool. | |
1374 | **/ | |
2e0fef85 JS |
1375 | void |
1376 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1377 | { | |
1378 | unsigned long iflags; | |
1379 | ||
1380 | /* | |
1381 | * Clean all volatile data fields, preserve iotag and node struct. | |
1382 | */ | |
1383 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1384 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1385 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1386 | } | |
1387 | ||
a257bf90 JS |
1388 | /** |
1389 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1390 | * @phba: Pointer to HBA context object. | |
1391 | * @iocblist: List of IOCBs. | |
1392 | * @ulpstatus: ULP status in IOCB command field. | |
1393 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1394 | * | |
1395 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1396 | * on the list by invoking the complete callback function associated with the | |
1397 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1398 | * fields. | |
1399 | **/ | |
1400 | void | |
1401 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1402 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1403 | { | |
1404 | struct lpfc_iocbq *piocb; | |
1405 | ||
1406 | while (!list_empty(iocblist)) { | |
1407 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
a257bf90 JS |
1408 | if (!piocb->iocb_cmpl) |
1409 | lpfc_sli_release_iocbq(phba, piocb); | |
1410 | else { | |
1411 | piocb->iocb.ulpStatus = ulpstatus; | |
1412 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1413 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1414 | } | |
1415 | } | |
1416 | return; | |
1417 | } | |
1418 | ||
e59058c4 | 1419 | /** |
3621a710 JS |
1420 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1421 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1422 | * |
1423 | * This function is called by ring event handler function to get the iocb type. | |
1424 | * This function translates the iocb command to an iocb command type used to | |
1425 | * decide the final disposition of each completed IOCB. | |
1426 | * The function returns | |
1427 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1428 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1429 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1430 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1431 | * | |
1432 | * The caller is not required to hold any lock. | |
1433 | **/ | |
dea3101e JB |
1434 | static lpfc_iocb_type |
1435 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1436 | { | |
1437 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1438 | ||
1439 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1440 | return 0; | |
1441 | ||
1442 | switch (iocb_cmnd) { | |
1443 | case CMD_XMIT_SEQUENCE_CR: | |
1444 | case CMD_XMIT_SEQUENCE_CX: | |
1445 | case CMD_XMIT_BCAST_CN: | |
1446 | case CMD_XMIT_BCAST_CX: | |
1447 | case CMD_ELS_REQUEST_CR: | |
1448 | case CMD_ELS_REQUEST_CX: | |
1449 | case CMD_CREATE_XRI_CR: | |
1450 | case CMD_CREATE_XRI_CX: | |
1451 | case CMD_GET_RPI_CN: | |
1452 | case CMD_XMIT_ELS_RSP_CX: | |
1453 | case CMD_GET_RPI_CR: | |
1454 | case CMD_FCP_IWRITE_CR: | |
1455 | case CMD_FCP_IWRITE_CX: | |
1456 | case CMD_FCP_IREAD_CR: | |
1457 | case CMD_FCP_IREAD_CX: | |
1458 | case CMD_FCP_ICMND_CR: | |
1459 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1460 | case CMD_FCP_TSEND_CX: |
1461 | case CMD_FCP_TRSP_CX: | |
1462 | case CMD_FCP_TRECEIVE_CX: | |
1463 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1464 | case CMD_ADAPTER_MSG: |
1465 | case CMD_ADAPTER_DUMP: | |
1466 | case CMD_XMIT_SEQUENCE64_CR: | |
1467 | case CMD_XMIT_SEQUENCE64_CX: | |
1468 | case CMD_XMIT_BCAST64_CN: | |
1469 | case CMD_XMIT_BCAST64_CX: | |
1470 | case CMD_ELS_REQUEST64_CR: | |
1471 | case CMD_ELS_REQUEST64_CX: | |
1472 | case CMD_FCP_IWRITE64_CR: | |
1473 | case CMD_FCP_IWRITE64_CX: | |
1474 | case CMD_FCP_IREAD64_CR: | |
1475 | case CMD_FCP_IREAD64_CX: | |
1476 | case CMD_FCP_ICMND64_CR: | |
1477 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1478 | case CMD_FCP_TSEND64_CX: |
1479 | case CMD_FCP_TRSP64_CX: | |
1480 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1481 | case CMD_GEN_REQUEST64_CR: |
1482 | case CMD_GEN_REQUEST64_CX: | |
1483 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1484 | case DSSCMD_IWRITE64_CR: |
1485 | case DSSCMD_IWRITE64_CX: | |
1486 | case DSSCMD_IREAD64_CR: | |
1487 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1488 | type = LPFC_SOL_IOCB; |
1489 | break; | |
1490 | case CMD_ABORT_XRI_CN: | |
1491 | case CMD_ABORT_XRI_CX: | |
1492 | case CMD_CLOSE_XRI_CN: | |
1493 | case CMD_CLOSE_XRI_CX: | |
1494 | case CMD_XRI_ABORTED_CX: | |
1495 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1496 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1497 | type = LPFC_ABORT_IOCB; |
1498 | break; | |
1499 | case CMD_RCV_SEQUENCE_CX: | |
1500 | case CMD_RCV_ELS_REQ_CX: | |
1501 | case CMD_RCV_SEQUENCE64_CX: | |
1502 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1503 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1504 | case CMD_IOCB_RCV_SEQ64_CX: |
1505 | case CMD_IOCB_RCV_ELS64_CX: | |
1506 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1507 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1508 | type = LPFC_UNSOL_IOCB; |
1509 | break; | |
3163f725 JS |
1510 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1511 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1512 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1513 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1514 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1515 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1516 | case CMD_IOCB_RET_HBQE64_CN: | |
1517 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1518 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1519 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1520 | case CMD_IOCB_LOGENTRY_CN: | |
1521 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1522 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1523 | __func__, iocb_cmnd); |
3163f725 JS |
1524 | type = LPFC_UNKNOWN_IOCB; |
1525 | break; | |
dea3101e JB |
1526 | default: |
1527 | type = LPFC_UNKNOWN_IOCB; | |
1528 | break; | |
1529 | } | |
1530 | ||
1531 | return type; | |
1532 | } | |
1533 | ||
e59058c4 | 1534 | /** |
3621a710 | 1535 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1536 | * @phba: Pointer to HBA context object. |
1537 | * | |
1538 | * This function is called from SLI initialization code | |
1539 | * to configure every ring of the HBA's SLI interface. The | |
1540 | * caller is not required to hold any lock. This function issues | |
1541 | * a config_ring mailbox command for each ring. | |
1542 | * This function returns zero if successful else returns a negative | |
1543 | * error code. | |
1544 | **/ | |
dea3101e | 1545 | static int |
ed957684 | 1546 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1547 | { |
1548 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1549 | LPFC_MBOXQ_t *pmb; |
1550 | MAILBOX_t *pmbox; | |
1551 | int i, rc, ret = 0; | |
dea3101e | 1552 | |
ed957684 JS |
1553 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1554 | if (!pmb) | |
1555 | return -ENOMEM; | |
04c68496 | 1556 | pmbox = &pmb->u.mb; |
ed957684 | 1557 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1558 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1559 | lpfc_config_ring(phba, i, pmb); |
1560 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1561 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1563 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1564 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1565 | "ring %d\n", | |
e8b62011 JS |
1566 | rc, pmbox->mbxCommand, |
1567 | pmbox->mbxStatus, i); | |
2e0fef85 | 1568 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1569 | ret = -ENXIO; |
1570 | break; | |
dea3101e JB |
1571 | } |
1572 | } | |
ed957684 JS |
1573 | mempool_free(pmb, phba->mbox_mem_pool); |
1574 | return ret; | |
dea3101e JB |
1575 | } |
1576 | ||
e59058c4 | 1577 | /** |
3621a710 | 1578 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1579 | * @phba: Pointer to HBA context object. |
1580 | * @pring: Pointer to driver SLI ring object. | |
1581 | * @piocb: Pointer to the driver iocb object. | |
1582 | * | |
1583 | * This function is called with hbalock held. The function adds the | |
1584 | * new iocb to txcmplq of the given ring. This function always returns | |
1585 | * 0. If this function is called for ELS ring, this function checks if | |
1586 | * there is a vport associated with the ELS command. This function also | |
1587 | * starts els_tmofunc timer if this is an ELS command. | |
1588 | **/ | |
dea3101e | 1589 | static int |
2e0fef85 JS |
1590 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1591 | struct lpfc_iocbq *piocb) | |
dea3101e | 1592 | { |
1c2ba475 JT |
1593 | lockdep_assert_held(&phba->hbalock); |
1594 | ||
2319f847 | 1595 | BUG_ON(!piocb); |
22466da5 | 1596 | |
dea3101e | 1597 | list_add_tail(&piocb->list, &pring->txcmplq); |
4f2e66c6 | 1598 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 1599 | |
92d7f7b0 JS |
1600 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1601 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
2319f847 MFO |
1602 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
1603 | BUG_ON(!piocb->vport); | |
1604 | if (!(piocb->vport->load_flag & FC_UNLOADING)) | |
1605 | mod_timer(&piocb->vport->els_tmofunc, | |
1606 | jiffies + | |
1607 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); | |
1608 | } | |
dea3101e | 1609 | |
2e0fef85 | 1610 | return 0; |
dea3101e JB |
1611 | } |
1612 | ||
e59058c4 | 1613 | /** |
3621a710 | 1614 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1615 | * @phba: Pointer to HBA context object. |
1616 | * @pring: Pointer to driver SLI ring object. | |
1617 | * | |
1618 | * This function is called with hbalock held to get next | |
1619 | * iocb in txq of the given ring. If there is any iocb in | |
1620 | * the txq, the function returns first iocb in the list after | |
1621 | * removing the iocb from the list, else it returns NULL. | |
1622 | **/ | |
2a9bf3d0 | 1623 | struct lpfc_iocbq * |
2e0fef85 | 1624 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1625 | { |
dea3101e JB |
1626 | struct lpfc_iocbq *cmd_iocb; |
1627 | ||
1c2ba475 JT |
1628 | lockdep_assert_held(&phba->hbalock); |
1629 | ||
858c9f6c | 1630 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
2e0fef85 | 1631 | return cmd_iocb; |
dea3101e JB |
1632 | } |
1633 | ||
e59058c4 | 1634 | /** |
3621a710 | 1635 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1636 | * @phba: Pointer to HBA context object. |
1637 | * @pring: Pointer to driver SLI ring object. | |
1638 | * | |
1639 | * This function is called with hbalock held and the caller must post the | |
1640 | * iocb without releasing the lock. If the caller releases the lock, | |
1641 | * iocb slot returned by the function is not guaranteed to be available. | |
1642 | * The function returns pointer to the next available iocb slot if there | |
1643 | * is available slot in the ring, else it returns NULL. | |
1644 | * If the get index of the ring is ahead of the put index, the function | |
1645 | * will post an error attention event to the worker thread to take the | |
1646 | * HBA to offline state. | |
1647 | **/ | |
dea3101e JB |
1648 | static IOCB_t * |
1649 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1650 | { | |
34b02dcd | 1651 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
7e56aa25 | 1652 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
1c2ba475 JT |
1653 | |
1654 | lockdep_assert_held(&phba->hbalock); | |
1655 | ||
7e56aa25 JS |
1656 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
1657 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) | |
1658 | pring->sli.sli3.next_cmdidx = 0; | |
dea3101e | 1659 | |
7e56aa25 JS |
1660 | if (unlikely(pring->sli.sli3.local_getidx == |
1661 | pring->sli.sli3.next_cmdidx)) { | |
dea3101e | 1662 | |
7e56aa25 | 1663 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 1664 | |
7e56aa25 | 1665 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
dea3101e | 1666 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1667 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1668 | "is bigger than cmd ring %d\n", |
e8b62011 | 1669 | pring->ringno, |
7e56aa25 JS |
1670 | pring->sli.sli3.local_getidx, |
1671 | max_cmd_idx); | |
dea3101e | 1672 | |
2e0fef85 | 1673 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1674 | /* |
1675 | * All error attention handlers are posted to | |
1676 | * worker thread | |
1677 | */ | |
1678 | phba->work_ha |= HA_ERATT; | |
1679 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1680 | |
5e9d9b82 | 1681 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1682 | |
1683 | return NULL; | |
1684 | } | |
1685 | ||
7e56aa25 | 1686 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
dea3101e JB |
1687 | return NULL; |
1688 | } | |
1689 | ||
ed957684 | 1690 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1691 | } |
1692 | ||
e59058c4 | 1693 | /** |
3621a710 | 1694 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1695 | * @phba: Pointer to HBA context object. |
1696 | * @iocbq: Pointer to driver iocb object. | |
1697 | * | |
1698 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1699 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1700 | * array and assigns a new iotag. | |
1701 | * The function returns the allocated iotag if successful, else returns zero. | |
1702 | * Zero is not a valid iotag. | |
1703 | * The caller is not required to hold any lock. | |
1704 | **/ | |
604a3e30 | 1705 | uint16_t |
2e0fef85 | 1706 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1707 | { |
2e0fef85 JS |
1708 | struct lpfc_iocbq **new_arr; |
1709 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1710 | size_t new_len; |
1711 | struct lpfc_sli *psli = &phba->sli; | |
1712 | uint16_t iotag; | |
dea3101e | 1713 | |
2e0fef85 | 1714 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1715 | iotag = psli->last_iotag; |
1716 | if(++iotag < psli->iocbq_lookup_len) { | |
1717 | psli->last_iotag = iotag; | |
1718 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1719 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1720 | iocbq->iotag = iotag; |
1721 | return iotag; | |
2e0fef85 | 1722 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1723 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1724 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 | 1725 | spin_unlock_irq(&phba->hbalock); |
6396bb22 | 1726 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
604a3e30 JB |
1727 | GFP_KERNEL); |
1728 | if (new_arr) { | |
2e0fef85 | 1729 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1730 | old_arr = psli->iocbq_lookup; |
1731 | if (new_len <= psli->iocbq_lookup_len) { | |
1732 | /* highly unprobable case */ | |
1733 | kfree(new_arr); | |
1734 | iotag = psli->last_iotag; | |
1735 | if(++iotag < psli->iocbq_lookup_len) { | |
1736 | psli->last_iotag = iotag; | |
1737 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1738 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1739 | iocbq->iotag = iotag; |
1740 | return iotag; | |
1741 | } | |
2e0fef85 | 1742 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1743 | return 0; |
1744 | } | |
1745 | if (psli->iocbq_lookup) | |
1746 | memcpy(new_arr, old_arr, | |
1747 | ((psli->last_iotag + 1) * | |
311464ec | 1748 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1749 | psli->iocbq_lookup = new_arr; |
1750 | psli->iocbq_lookup_len = new_len; | |
1751 | psli->last_iotag = iotag; | |
1752 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1753 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1754 | iocbq->iotag = iotag; |
1755 | kfree(old_arr); | |
1756 | return iotag; | |
1757 | } | |
8f6d98d2 | 1758 | } else |
2e0fef85 | 1759 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1760 | |
bc73905a | 1761 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1762 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1763 | psli->last_iotag); | |
dea3101e | 1764 | |
604a3e30 | 1765 | return 0; |
dea3101e JB |
1766 | } |
1767 | ||
e59058c4 | 1768 | /** |
3621a710 | 1769 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1770 | * @phba: Pointer to HBA context object. |
1771 | * @pring: Pointer to driver SLI ring object. | |
1772 | * @iocb: Pointer to iocb slot in the ring. | |
1773 | * @nextiocb: Pointer to driver iocb object which need to be | |
1774 | * posted to firmware. | |
1775 | * | |
1776 | * This function is called with hbalock held to post a new iocb to | |
1777 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1778 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1779 | * a completion call back for this iocb else the function will free the | |
1780 | * iocb object. | |
1781 | **/ | |
dea3101e JB |
1782 | static void |
1783 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1784 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1785 | { | |
1c2ba475 | 1786 | lockdep_assert_held(&phba->hbalock); |
dea3101e | 1787 | /* |
604a3e30 | 1788 | * Set up an iotag |
dea3101e | 1789 | */ |
604a3e30 | 1790 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1791 | |
e2a0a9d6 | 1792 | |
a58cbd52 JS |
1793 | if (pring->ringno == LPFC_ELS_RING) { |
1794 | lpfc_debugfs_slow_ring_trc(phba, | |
1795 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1796 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1797 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1798 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1799 | } | |
1800 | ||
dea3101e JB |
1801 | /* |
1802 | * Issue iocb command to adapter | |
1803 | */ | |
92d7f7b0 | 1804 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1805 | wmb(); |
1806 | pring->stats.iocb_cmd++; | |
1807 | ||
1808 | /* | |
1809 | * If there is no completion routine to call, we can release the | |
1810 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1811 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1812 | */ | |
1813 | if (nextiocb->iocb_cmpl) | |
1814 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1815 | else |
2e0fef85 | 1816 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1817 | |
1818 | /* | |
1819 | * Let the HBA know what IOCB slot will be the next one the | |
1820 | * driver will put a command into. | |
1821 | */ | |
7e56aa25 JS |
1822 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
1823 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); | |
dea3101e JB |
1824 | } |
1825 | ||
e59058c4 | 1826 | /** |
3621a710 | 1827 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1828 | * @phba: Pointer to HBA context object. |
1829 | * @pring: Pointer to driver SLI ring object. | |
1830 | * | |
1831 | * The caller is not required to hold any lock for calling this function. | |
1832 | * This function updates the chip attention bits for the ring to inform firmware | |
1833 | * that there are pending work to be done for this ring and requests an | |
1834 | * interrupt when there is space available in the ring. This function is | |
1835 | * called when the driver is unable to post more iocbs to the ring due | |
1836 | * to unavailability of space in the ring. | |
1837 | **/ | |
dea3101e | 1838 | static void |
2e0fef85 | 1839 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1840 | { |
1841 | int ringno = pring->ringno; | |
1842 | ||
1843 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1844 | ||
1845 | wmb(); | |
1846 | ||
1847 | /* | |
1848 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1849 | * The HBA will tell us when an IOCB entry is available. | |
1850 | */ | |
1851 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1852 | readl(phba->CAregaddr); /* flush */ | |
1853 | ||
1854 | pring->stats.iocb_cmd_full++; | |
1855 | } | |
1856 | ||
e59058c4 | 1857 | /** |
3621a710 | 1858 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1859 | * @phba: Pointer to HBA context object. |
1860 | * @pring: Pointer to driver SLI ring object. | |
1861 | * | |
1862 | * This function updates the chip attention register bit for the | |
1863 | * given ring to inform HBA that there is more work to be done | |
1864 | * in this ring. The caller is not required to hold any lock. | |
1865 | **/ | |
dea3101e | 1866 | static void |
2e0fef85 | 1867 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1868 | { |
1869 | int ringno = pring->ringno; | |
1870 | ||
1871 | /* | |
1872 | * Tell the HBA that there is work to do in this ring. | |
1873 | */ | |
34b02dcd JS |
1874 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1875 | wmb(); | |
1876 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1877 | readl(phba->CAregaddr); /* flush */ | |
1878 | } | |
dea3101e JB |
1879 | } |
1880 | ||
e59058c4 | 1881 | /** |
3621a710 | 1882 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1883 | * @phba: Pointer to HBA context object. |
1884 | * @pring: Pointer to driver SLI ring object. | |
1885 | * | |
1886 | * This function is called with hbalock held to post pending iocbs | |
1887 | * in the txq to the firmware. This function is called when driver | |
1888 | * detects space available in the ring. | |
1889 | **/ | |
dea3101e | 1890 | static void |
2e0fef85 | 1891 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1892 | { |
1893 | IOCB_t *iocb; | |
1894 | struct lpfc_iocbq *nextiocb; | |
1895 | ||
1c2ba475 JT |
1896 | lockdep_assert_held(&phba->hbalock); |
1897 | ||
dea3101e JB |
1898 | /* |
1899 | * Check to see if: | |
1900 | * (a) there is anything on the txq to send | |
1901 | * (b) link is up | |
1902 | * (c) link attention events can be processed (fcp ring only) | |
1903 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1904 | */ | |
0e9bb8d7 JS |
1905 | |
1906 | if (lpfc_is_link_up(phba) && | |
1907 | (!list_empty(&pring->txq)) && | |
895427bd | 1908 | (pring->ringno != LPFC_FCP_RING || |
0b727fea | 1909 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1910 | |
1911 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1912 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1913 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1914 | ||
1915 | if (iocb) | |
1916 | lpfc_sli_update_ring(phba, pring); | |
1917 | else | |
1918 | lpfc_sli_update_full_ring(phba, pring); | |
1919 | } | |
1920 | ||
1921 | return; | |
1922 | } | |
1923 | ||
e59058c4 | 1924 | /** |
3621a710 | 1925 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1926 | * @phba: Pointer to HBA context object. |
1927 | * @hbqno: HBQ number. | |
1928 | * | |
1929 | * This function is called with hbalock held to get the next | |
1930 | * available slot for the given HBQ. If there is free slot | |
1931 | * available for the HBQ it will return pointer to the next available | |
1932 | * HBQ entry else it will return NULL. | |
1933 | **/ | |
a6ababd2 | 1934 | static struct lpfc_hbq_entry * |
ed957684 JS |
1935 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1936 | { | |
1937 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1938 | ||
1c2ba475 JT |
1939 | lockdep_assert_held(&phba->hbalock); |
1940 | ||
ed957684 JS |
1941 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
1942 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1943 | hbqp->next_hbqPutIdx = 0; | |
1944 | ||
1945 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1946 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1947 | uint32_t getidx = le32_to_cpu(raw_index); |
1948 | ||
1949 | hbqp->local_hbqGetIdx = getidx; | |
1950 | ||
1951 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1952 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1953 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1954 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1955 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1956 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1957 | hbqp->entry_count); |
1958 | ||
1959 | phba->link_state = LPFC_HBA_ERROR; | |
1960 | return NULL; | |
1961 | } | |
1962 | ||
1963 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1964 | return NULL; | |
1965 | } | |
1966 | ||
51ef4c26 JS |
1967 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1968 | hbqp->hbqPutIdx; | |
ed957684 JS |
1969 | } |
1970 | ||
e59058c4 | 1971 | /** |
3621a710 | 1972 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1973 | * @phba: Pointer to HBA context object. |
1974 | * | |
1975 | * This function is called with no lock held to free all the | |
1976 | * hbq buffers while uninitializing the SLI interface. It also | |
1977 | * frees the HBQ buffers returned by the firmware but not yet | |
1978 | * processed by the upper layers. | |
1979 | **/ | |
ed957684 JS |
1980 | void |
1981 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1982 | { | |
92d7f7b0 JS |
1983 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1984 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1985 | unsigned long flags; |
51ef4c26 | 1986 | int i, hbq_count; |
ed957684 | 1987 | |
51ef4c26 | 1988 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1989 | /* Return all memory used by all HBQs */ |
3163f725 | 1990 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1991 | for (i = 0; i < hbq_count; ++i) { |
1992 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1993 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1994 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1995 | list_del(&hbq_buf->dbuf.list); | |
1996 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1997 | } | |
a8adb832 | 1998 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1999 | } |
3163f725 JS |
2000 | |
2001 | /* Mark the HBQs not in use */ | |
2002 | phba->hbq_in_use = 0; | |
2003 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
2004 | } |
2005 | ||
e59058c4 | 2006 | /** |
3621a710 | 2007 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
2008 | * @phba: Pointer to HBA context object. |
2009 | * @hbqno: HBQ number. | |
2010 | * @hbq_buf: Pointer to HBQ buffer. | |
2011 | * | |
2012 | * This function is called with the hbalock held to post a | |
2013 | * hbq buffer to the firmware. If the function finds an empty | |
2014 | * slot in the HBQ, it will post the buffer. The function will return | |
2015 | * pointer to the hbq entry if it successfully post the buffer | |
2016 | * else it will return NULL. | |
2017 | **/ | |
3772a991 | 2018 | static int |
ed957684 | 2019 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 2020 | struct hbq_dmabuf *hbq_buf) |
3772a991 | 2021 | { |
1c2ba475 | 2022 | lockdep_assert_held(&phba->hbalock); |
3772a991 JS |
2023 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
2024 | } | |
2025 | ||
2026 | /** | |
2027 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
2028 | * @phba: Pointer to HBA context object. | |
2029 | * @hbqno: HBQ number. | |
2030 | * @hbq_buf: Pointer to HBQ buffer. | |
2031 | * | |
2032 | * This function is called with the hbalock held to post a hbq buffer to the | |
2033 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
2034 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
2035 | * it successfully post the buffer else it will return an error. | |
2036 | **/ | |
2037 | static int | |
2038 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
2039 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
2040 | { |
2041 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 2042 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 | 2043 | |
1c2ba475 | 2044 | lockdep_assert_held(&phba->hbalock); |
ed957684 JS |
2045 | /* Get next HBQ entry slot to use */ |
2046 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
2047 | if (hbqe) { | |
2048 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
2049 | ||
92d7f7b0 JS |
2050 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
2051 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
895427bd | 2052 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
ed957684 | 2053 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
2054 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
2055 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
2056 | /* Sync SLIM */ | |
ed957684 JS |
2057 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
2058 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 2059 | /* flush */ |
ed957684 | 2060 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 2061 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
2062 | return 0; |
2063 | } else | |
2064 | return -ENOMEM; | |
ed957684 JS |
2065 | } |
2066 | ||
4f774513 JS |
2067 | /** |
2068 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
2069 | * @phba: Pointer to HBA context object. | |
2070 | * @hbqno: HBQ number. | |
2071 | * @hbq_buf: Pointer to HBQ buffer. | |
2072 | * | |
2073 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
2074 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
2075 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
2076 | **/ | |
2077 | static int | |
2078 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
2079 | struct hbq_dmabuf *hbq_buf) | |
2080 | { | |
2081 | int rc; | |
2082 | struct lpfc_rqe hrqe; | |
2083 | struct lpfc_rqe drqe; | |
895427bd JS |
2084 | struct lpfc_queue *hrq; |
2085 | struct lpfc_queue *drq; | |
2086 | ||
2087 | if (hbqno != LPFC_ELS_HBQ) | |
2088 | return 1; | |
2089 | hrq = phba->sli4_hba.hdr_rq; | |
2090 | drq = phba->sli4_hba.dat_rq; | |
4f774513 | 2091 | |
1c2ba475 | 2092 | lockdep_assert_held(&phba->hbalock); |
4f774513 JS |
2093 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
2094 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
2095 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
2096 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
895427bd | 2097 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
4f774513 JS |
2098 | if (rc < 0) |
2099 | return rc; | |
895427bd | 2100 | hbq_buf->tag = (rc | (hbqno << 16)); |
4f774513 JS |
2101 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
2102 | return 0; | |
2103 | } | |
2104 | ||
e59058c4 | 2105 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
2106 | static struct lpfc_hbq_init lpfc_els_hbq = { |
2107 | .rn = 1, | |
def9c7a9 | 2108 | .entry_count = 256, |
92d7f7b0 JS |
2109 | .mask_count = 0, |
2110 | .profile = 0, | |
51ef4c26 | 2111 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 2112 | .buffer_count = 0, |
a257bf90 JS |
2113 | .init_count = 40, |
2114 | .add_count = 40, | |
92d7f7b0 | 2115 | }; |
ed957684 | 2116 | |
e59058c4 | 2117 | /* Array of HBQs */ |
78b2d852 | 2118 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 JS |
2119 | &lpfc_els_hbq, |
2120 | }; | |
ed957684 | 2121 | |
e59058c4 | 2122 | /** |
3621a710 | 2123 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
2124 | * @phba: Pointer to HBA context object. |
2125 | * @hbqno: HBQ number. | |
2126 | * @count: Number of HBQ buffers to be posted. | |
2127 | * | |
d7c255b2 JS |
2128 | * This function is called with no lock held to post more hbq buffers to the |
2129 | * given HBQ. The function returns the number of HBQ buffers successfully | |
2130 | * posted. | |
e59058c4 | 2131 | **/ |
311464ec | 2132 | static int |
92d7f7b0 | 2133 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 2134 | { |
d7c255b2 | 2135 | uint32_t i, posted = 0; |
3163f725 | 2136 | unsigned long flags; |
92d7f7b0 | 2137 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 2138 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 2139 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 2140 | return 0; |
51ef4c26 | 2141 | |
d7c255b2 JS |
2142 | if ((phba->hbqs[hbqno].buffer_count + count) > |
2143 | lpfc_hbq_defs[hbqno]->entry_count) | |
2144 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
2145 | phba->hbqs[hbqno].buffer_count; | |
2146 | if (!count) | |
2147 | return 0; | |
2148 | /* Allocate HBQ entries */ | |
2149 | for (i = 0; i < count; i++) { | |
2150 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
2151 | if (!hbq_buffer) | |
2152 | break; | |
2153 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
2154 | } | |
3163f725 JS |
2155 | /* Check whether HBQ is still in use */ |
2156 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 2157 | if (!phba->hbq_in_use) |
d7c255b2 JS |
2158 | goto err; |
2159 | while (!list_empty(&hbq_buf_list)) { | |
2160 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
2161 | dbuf.list); | |
2162 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
2163 | (hbqno << 16)); | |
3772a991 | 2164 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 2165 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
2166 | posted++; |
2167 | } else | |
51ef4c26 | 2168 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 2169 | } |
3163f725 | 2170 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
2171 | return posted; |
2172 | err: | |
eafe1df9 | 2173 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
2174 | while (!list_empty(&hbq_buf_list)) { |
2175 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
2176 | dbuf.list); | |
2177 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
2178 | } | |
2179 | return 0; | |
ed957684 JS |
2180 | } |
2181 | ||
e59058c4 | 2182 | /** |
3621a710 | 2183 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
2184 | * @phba: Pointer to HBA context object. |
2185 | * @qno: HBQ number. | |
2186 | * | |
2187 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
2188 | * is called with no lock held. The function returns the number of HBQ entries |
2189 | * successfully allocated. | |
e59058c4 | 2190 | **/ |
92d7f7b0 JS |
2191 | int |
2192 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 2193 | { |
def9c7a9 JS |
2194 | if (phba->sli_rev == LPFC_SLI_REV4) |
2195 | return 0; | |
2196 | else | |
2197 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
2198 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 2199 | } |
ed957684 | 2200 | |
e59058c4 | 2201 | /** |
3621a710 | 2202 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
2203 | * @phba: Pointer to HBA context object. |
2204 | * @qno: HBQ queue number. | |
2205 | * | |
2206 | * This function is called from SLI initialization code path with | |
2207 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 2208 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 2209 | **/ |
a6ababd2 | 2210 | static int |
92d7f7b0 JS |
2211 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
2212 | { | |
def9c7a9 JS |
2213 | if (phba->sli_rev == LPFC_SLI_REV4) |
2214 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
73d91e50 | 2215 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
2216 | else |
2217 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
2218 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
2219 | } |
2220 | ||
3772a991 JS |
2221 | /** |
2222 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
2223 | * @phba: Pointer to HBA context object. | |
2224 | * @hbqno: HBQ number. | |
2225 | * | |
2226 | * This function removes the first hbq buffer on an hbq list and returns a | |
2227 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
2228 | **/ | |
2229 | static struct hbq_dmabuf * | |
2230 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
2231 | { | |
2232 | struct lpfc_dmabuf *d_buf; | |
2233 | ||
2234 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
2235 | if (!d_buf) | |
2236 | return NULL; | |
2237 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
2238 | } | |
2239 | ||
2d7dbc4c JS |
2240 | /** |
2241 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list | |
2242 | * @phba: Pointer to HBA context object. | |
2243 | * @hbqno: HBQ number. | |
2244 | * | |
2245 | * This function removes the first RQ buffer on an RQ buffer list and returns a | |
2246 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
2247 | **/ | |
2248 | static struct rqb_dmabuf * | |
2249 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) | |
2250 | { | |
2251 | struct lpfc_dmabuf *h_buf; | |
2252 | struct lpfc_rqb *rqbp; | |
2253 | ||
2254 | rqbp = hrq->rqbp; | |
2255 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, | |
2256 | struct lpfc_dmabuf, list); | |
2257 | if (!h_buf) | |
2258 | return NULL; | |
2259 | rqbp->buffer_count--; | |
2260 | return container_of(h_buf, struct rqb_dmabuf, hbuf); | |
2261 | } | |
2262 | ||
e59058c4 | 2263 | /** |
3621a710 | 2264 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
2265 | * @phba: Pointer to HBA context object. |
2266 | * @tag: Tag of the hbq buffer. | |
2267 | * | |
71892418 SH |
2268 | * This function searches for the hbq buffer associated with the given tag in |
2269 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer | |
2270 | * otherwise it returns NULL. | |
e59058c4 | 2271 | **/ |
a6ababd2 | 2272 | static struct hbq_dmabuf * |
92d7f7b0 | 2273 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 2274 | { |
92d7f7b0 JS |
2275 | struct lpfc_dmabuf *d_buf; |
2276 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
2277 | uint32_t hbqno; |
2278 | ||
2279 | hbqno = tag >> 16; | |
a0a74e45 | 2280 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 2281 | return NULL; |
ed957684 | 2282 | |
3772a991 | 2283 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 2284 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 2285 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 2286 | if (hbq_buf->tag == tag) { |
3772a991 | 2287 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2288 | return hbq_buf; |
ed957684 JS |
2289 | } |
2290 | } | |
3772a991 | 2291 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 2293 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 2294 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 2295 | return NULL; |
ed957684 JS |
2296 | } |
2297 | ||
e59058c4 | 2298 | /** |
3621a710 | 2299 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
2300 | * @phba: Pointer to HBA context object. |
2301 | * @hbq_buffer: Pointer to HBQ buffer. | |
2302 | * | |
2303 | * This function is called with hbalock. This function gives back | |
2304 | * the hbq buffer to firmware. If the HBQ does not have space to | |
2305 | * post the buffer, it will free the buffer. | |
2306 | **/ | |
ed957684 | 2307 | void |
51ef4c26 | 2308 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
2309 | { |
2310 | uint32_t hbqno; | |
2311 | ||
51ef4c26 JS |
2312 | if (hbq_buffer) { |
2313 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 2314 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 2315 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
2316 | } |
2317 | } | |
2318 | ||
e59058c4 | 2319 | /** |
3621a710 | 2320 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
2321 | * @mbxCommand: mailbox command code. |
2322 | * | |
2323 | * This function is called by the mailbox event handler function to verify | |
2324 | * that the completed mailbox command is a legitimate mailbox command. If the | |
2325 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
2326 | * and the mailbox event handler will take the HBA offline. | |
2327 | **/ | |
dea3101e JB |
2328 | static int |
2329 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
2330 | { | |
2331 | uint8_t ret; | |
2332 | ||
2333 | switch (mbxCommand) { | |
2334 | case MBX_LOAD_SM: | |
2335 | case MBX_READ_NV: | |
2336 | case MBX_WRITE_NV: | |
a8adb832 | 2337 | case MBX_WRITE_VPARMS: |
dea3101e JB |
2338 | case MBX_RUN_BIU_DIAG: |
2339 | case MBX_INIT_LINK: | |
2340 | case MBX_DOWN_LINK: | |
2341 | case MBX_CONFIG_LINK: | |
2342 | case MBX_CONFIG_RING: | |
2343 | case MBX_RESET_RING: | |
2344 | case MBX_READ_CONFIG: | |
2345 | case MBX_READ_RCONFIG: | |
2346 | case MBX_READ_SPARM: | |
2347 | case MBX_READ_STATUS: | |
2348 | case MBX_READ_RPI: | |
2349 | case MBX_READ_XRI: | |
2350 | case MBX_READ_REV: | |
2351 | case MBX_READ_LNK_STAT: | |
2352 | case MBX_REG_LOGIN: | |
2353 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
2354 | case MBX_CLEAR_LA: |
2355 | case MBX_DUMP_MEMORY: | |
2356 | case MBX_DUMP_CONTEXT: | |
2357 | case MBX_RUN_DIAGS: | |
2358 | case MBX_RESTART: | |
2359 | case MBX_UPDATE_CFG: | |
2360 | case MBX_DOWN_LOAD: | |
2361 | case MBX_DEL_LD_ENTRY: | |
2362 | case MBX_RUN_PROGRAM: | |
2363 | case MBX_SET_MASK: | |
09372820 | 2364 | case MBX_SET_VARIABLE: |
dea3101e | 2365 | case MBX_UNREG_D_ID: |
41415862 | 2366 | case MBX_KILL_BOARD: |
dea3101e | 2367 | case MBX_CONFIG_FARP: |
41415862 | 2368 | case MBX_BEACON: |
dea3101e JB |
2369 | case MBX_LOAD_AREA: |
2370 | case MBX_RUN_BIU_DIAG64: | |
2371 | case MBX_CONFIG_PORT: | |
2372 | case MBX_READ_SPARM64: | |
2373 | case MBX_READ_RPI64: | |
2374 | case MBX_REG_LOGIN64: | |
76a95d75 | 2375 | case MBX_READ_TOPOLOGY: |
09372820 | 2376 | case MBX_WRITE_WWN: |
dea3101e JB |
2377 | case MBX_SET_DEBUG: |
2378 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2379 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2380 | case MBX_REG_VPI: |
2381 | case MBX_UNREG_VPI: | |
858c9f6c | 2382 | case MBX_HEARTBEAT: |
84774a4d JS |
2383 | case MBX_PORT_CAPABILITIES: |
2384 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2385 | case MBX_SLI4_CONFIG: |
2386 | case MBX_SLI4_REQ_FTRS: | |
2387 | case MBX_REG_FCFI: | |
2388 | case MBX_UNREG_FCFI: | |
2389 | case MBX_REG_VFI: | |
2390 | case MBX_UNREG_VFI: | |
2391 | case MBX_INIT_VPI: | |
2392 | case MBX_INIT_VFI: | |
2393 | case MBX_RESUME_RPI: | |
c7495937 JS |
2394 | case MBX_READ_EVENT_LOG_STATUS: |
2395 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2396 | case MBX_SECURITY_MGMT: |
2397 | case MBX_AUTH_PORT: | |
940eb687 | 2398 | case MBX_ACCESS_VDATA: |
dea3101e JB |
2399 | ret = mbxCommand; |
2400 | break; | |
2401 | default: | |
2402 | ret = MBX_SHUTDOWN; | |
2403 | break; | |
2404 | } | |
2e0fef85 | 2405 | return ret; |
dea3101e | 2406 | } |
e59058c4 JS |
2407 | |
2408 | /** | |
3621a710 | 2409 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2410 | * @phba: Pointer to HBA context object. |
2411 | * @pmboxq: Pointer to mailbox command. | |
2412 | * | |
2413 | * This is completion handler function for mailbox commands issued from | |
2414 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2415 | * mailbox event handler function with no lock held. This function | |
2416 | * will wake up thread waiting on the wait queue pointed by context1 | |
2417 | * of the mailbox. | |
2418 | **/ | |
04c68496 | 2419 | void |
2e0fef85 | 2420 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e | 2421 | { |
858c9f6c | 2422 | unsigned long drvr_flag; |
e29d74f8 | 2423 | struct completion *pmbox_done; |
dea3101e JB |
2424 | |
2425 | /* | |
e29d74f8 | 2426 | * If pmbox_done is empty, the driver thread gave up waiting and |
dea3101e JB |
2427 | * continued running. |
2428 | */ | |
7054a606 | 2429 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2430 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
e29d74f8 JS |
2431 | pmbox_done = (struct completion *)pmboxq->context3; |
2432 | if (pmbox_done) | |
2433 | complete(pmbox_done); | |
858c9f6c | 2434 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2435 | return; |
2436 | } | |
2437 | ||
e59058c4 JS |
2438 | |
2439 | /** | |
3621a710 | 2440 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2441 | * @phba: Pointer to HBA context object. |
2442 | * @pmb: Pointer to mailbox object. | |
2443 | * | |
2444 | * This function is the default mailbox completion handler. It | |
2445 | * frees the memory resources associated with the completed mailbox | |
2446 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2447 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2448 | **/ | |
dea3101e | 2449 | void |
2e0fef85 | 2450 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2451 | { |
d439d286 | 2452 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2453 | struct lpfc_dmabuf *mp; |
d439d286 | 2454 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2455 | struct Scsi_Host *shost; |
04c68496 | 2456 | uint16_t rpi, vpi; |
7054a606 JS |
2457 | int rc; |
2458 | ||
3e1f0718 | 2459 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
7054a606 | 2460 | |
dea3101e JB |
2461 | if (mp) { |
2462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2463 | kfree(mp); | |
2464 | } | |
7054a606 JS |
2465 | |
2466 | /* | |
2467 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2468 | * is in re-discovery driver need to cleanup the RPI. | |
2469 | */ | |
2e0fef85 | 2470 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2471 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2472 | !pmb->u.mb.mbxStatus) { | |
2473 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2474 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2475 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
de96e9c5 | 2476 | pmb->vport = vport; |
92d7f7b0 | 2477 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2478 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2479 | if (rc != MBX_NOT_FINISHED) | |
2480 | return; | |
2481 | } | |
2482 | ||
695a814e JS |
2483 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2484 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2485 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2486 | shost = lpfc_shost_from_vport(vport); |
2487 | spin_lock_irq(shost->host_lock); | |
2488 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2489 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2490 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2491 | } |
2492 | ||
d439d286 | 2493 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
3e1f0718 | 2494 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
d439d286 | 2495 | lpfc_nlp_put(ndlp); |
dea16bda JS |
2496 | pmb->ctx_buf = NULL; |
2497 | pmb->ctx_ndlp = NULL; | |
2498 | } | |
2499 | ||
2500 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { | |
2501 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; | |
2502 | ||
2503 | /* Check to see if there are any deferred events to process */ | |
2504 | if (ndlp) { | |
2505 | lpfc_printf_vlog( | |
2506 | vport, | |
2507 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, | |
2508 | "1438 UNREG cmpl deferred mbox x%x " | |
2509 | "on NPort x%x Data: x%x x%x %p\n", | |
2510 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
2511 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); | |
2512 | ||
2513 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && | |
2514 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { | |
2515 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; | |
2516 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
2517 | } | |
2518 | ndlp->nlp_flag &= ~NLP_UNREG_INP; | |
2519 | } | |
3e1f0718 | 2520 | pmb->ctx_ndlp = NULL; |
d439d286 JS |
2521 | } |
2522 | ||
dcf2a4e0 JS |
2523 | /* Check security permission status on INIT_LINK mailbox command */ |
2524 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2525 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2526 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2527 | "2860 SLI authentication is required " | |
2528 | "for INIT_LINK but has not done yet\n"); | |
2529 | ||
04c68496 JS |
2530 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2531 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2532 | else | |
2533 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 2534 | } |
be6bb941 JS |
2535 | /** |
2536 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler | |
2537 | * @phba: Pointer to HBA context object. | |
2538 | * @pmb: Pointer to mailbox object. | |
2539 | * | |
2540 | * This function is the unreg rpi mailbox completion handler. It | |
2541 | * frees the memory resources associated with the completed mailbox | |
2542 | * command. An additional refrenece is put on the ndlp to prevent | |
2543 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before | |
2544 | * the unreg mailbox command completes, this routine puts the | |
2545 | * reference back. | |
2546 | * | |
2547 | **/ | |
2548 | void | |
2549 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
2550 | { | |
2551 | struct lpfc_vport *vport = pmb->vport; | |
2552 | struct lpfc_nodelist *ndlp; | |
2553 | ||
3e1f0718 | 2554 | ndlp = pmb->ctx_ndlp; |
be6bb941 JS |
2555 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
2556 | if (phba->sli_rev == LPFC_SLI_REV4 && | |
2557 | (bf_get(lpfc_sli_intf_if_type, | |
27d6ac0a | 2558 | &phba->sli4_hba.sli_intf) >= |
be6bb941 JS |
2559 | LPFC_SLI_INTF_IF_TYPE_2)) { |
2560 | if (ndlp) { | |
dea16bda JS |
2561 | lpfc_printf_vlog( |
2562 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, | |
2563 | "0010 UNREG_LOGIN vpi:%x " | |
2564 | "rpi:%x DID:%x defer x%x flg x%x " | |
2565 | "map:%x %p\n", | |
2566 | vport->vpi, ndlp->nlp_rpi, | |
2567 | ndlp->nlp_DID, ndlp->nlp_defer_did, | |
2568 | ndlp->nlp_flag, | |
2569 | ndlp->nlp_usg_map, ndlp); | |
7c5e518c | 2570 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
be6bb941 | 2571 | lpfc_nlp_put(ndlp); |
dea16bda JS |
2572 | |
2573 | /* Check to see if there are any deferred | |
2574 | * events to process | |
2575 | */ | |
2576 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && | |
2577 | (ndlp->nlp_defer_did != | |
2578 | NLP_EVT_NOTHING_PENDING)) { | |
2579 | lpfc_printf_vlog( | |
2580 | vport, KERN_INFO, LOG_DISCOVERY, | |
2581 | "4111 UNREG cmpl deferred " | |
2582 | "clr x%x on " | |
2583 | "NPort x%x Data: x%x %p\n", | |
2584 | ndlp->nlp_rpi, ndlp->nlp_DID, | |
2585 | ndlp->nlp_defer_did, ndlp); | |
2586 | ndlp->nlp_defer_did = | |
2587 | NLP_EVT_NOTHING_PENDING; | |
2588 | lpfc_issue_els_plogi( | |
2589 | vport, ndlp->nlp_DID, 0); | |
2590 | } | |
2591 | ndlp->nlp_flag &= ~NLP_UNREG_INP; | |
be6bb941 JS |
2592 | } |
2593 | } | |
2594 | } | |
2595 | ||
2596 | mempool_free(pmb, phba->mbox_mem_pool); | |
2597 | } | |
dea3101e | 2598 | |
e59058c4 | 2599 | /** |
3621a710 | 2600 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2601 | * @phba: Pointer to HBA context object. |
2602 | * | |
2603 | * This function is called with no lock held. This function processes all | |
2604 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2605 | * service routine processes mailbox completion interrupt and adds completed | |
2606 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2607 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2608 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2609 | * function returns the mailbox commands to the upper layer by calling the | |
2610 | * completion handler function of each mailbox. | |
2611 | **/ | |
dea3101e | 2612 | int |
2e0fef85 | 2613 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2614 | { |
92d7f7b0 | 2615 | MAILBOX_t *pmbox; |
dea3101e | 2616 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2617 | int rc; |
2618 | LIST_HEAD(cmplq); | |
dea3101e JB |
2619 | |
2620 | phba->sli.slistat.mbox_event++; | |
2621 | ||
92d7f7b0 JS |
2622 | /* Get all completed mailboxe buffers into the cmplq */ |
2623 | spin_lock_irq(&phba->hbalock); | |
2624 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2625 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2626 | |
92d7f7b0 JS |
2627 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2628 | do { | |
2629 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2630 | if (pmb == NULL) | |
2631 | break; | |
2e0fef85 | 2632 | |
04c68496 | 2633 | pmbox = &pmb->u.mb; |
dea3101e | 2634 | |
858c9f6c JS |
2635 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2636 | if (pmb->vport) { | |
2637 | lpfc_debugfs_disc_trc(pmb->vport, | |
2638 | LPFC_DISC_TRC_MBOX_VPORT, | |
2639 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2640 | (uint32_t)pmbox->mbxCommand, | |
2641 | pmbox->un.varWords[0], | |
2642 | pmbox->un.varWords[1]); | |
2643 | } | |
2644 | else { | |
2645 | lpfc_debugfs_disc_trc(phba->pport, | |
2646 | LPFC_DISC_TRC_MBOX, | |
2647 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2648 | (uint32_t)pmbox->mbxCommand, | |
2649 | pmbox->un.varWords[0], | |
2650 | pmbox->un.varWords[1]); | |
2651 | } | |
2652 | } | |
2653 | ||
dea3101e JB |
2654 | /* |
2655 | * It is a fatal error if unknown mbox command completion. | |
2656 | */ | |
2657 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2658 | MBX_SHUTDOWN) { | |
af901ca1 | 2659 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2660 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2661 | "(%d):0323 Unknown Mailbox command " |
a183a15f | 2662 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2663 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2664 | pmbox->mbxCommand, |
a183a15f JS |
2665 | lpfc_sli_config_mbox_subsys_get(phba, |
2666 | pmb), | |
2667 | lpfc_sli_config_mbox_opcode_get(phba, | |
2668 | pmb)); | |
2e0fef85 | 2669 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2670 | phba->work_hs = HS_FFER3; |
2671 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2672 | continue; |
dea3101e JB |
2673 | } |
2674 | ||
dea3101e JB |
2675 | if (pmbox->mbxStatus) { |
2676 | phba->sli.slistat.mbox_stat_err++; | |
2677 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2678 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2679 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2680 | LOG_MBOX | LOG_SLI, |
2681 | "(%d):0305 Mbox cmd cmpl " | |
2682 | "error - RETRYing Data: x%x " | |
2683 | "(x%x/x%x) x%x x%x x%x\n", | |
2684 | pmb->vport ? pmb->vport->vpi : 0, | |
2685 | pmbox->mbxCommand, | |
2686 | lpfc_sli_config_mbox_subsys_get(phba, | |
2687 | pmb), | |
2688 | lpfc_sli_config_mbox_opcode_get(phba, | |
2689 | pmb), | |
2690 | pmbox->mbxStatus, | |
2691 | pmbox->un.varWords[0], | |
2692 | pmb->vport->port_state); | |
dea3101e JB |
2693 | pmbox->mbxStatus = 0; |
2694 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2695 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2696 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2697 | continue; |
dea3101e JB |
2698 | } |
2699 | } | |
2700 | ||
2701 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2702 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2703 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
e74c03c8 JS |
2704 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
2705 | "x%x x%x x%x\n", | |
92d7f7b0 | 2706 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2707 | pmbox->mbxCommand, |
a183a15f JS |
2708 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2709 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e JB |
2710 | pmb->mbox_cmpl, |
2711 | *((uint32_t *) pmbox), | |
2712 | pmbox->un.varWords[0], | |
2713 | pmbox->un.varWords[1], | |
2714 | pmbox->un.varWords[2], | |
2715 | pmbox->un.varWords[3], | |
2716 | pmbox->un.varWords[4], | |
2717 | pmbox->un.varWords[5], | |
2718 | pmbox->un.varWords[6], | |
e74c03c8 JS |
2719 | pmbox->un.varWords[7], |
2720 | pmbox->un.varWords[8], | |
2721 | pmbox->un.varWords[9], | |
2722 | pmbox->un.varWords[10]); | |
dea3101e | 2723 | |
92d7f7b0 | 2724 | if (pmb->mbox_cmpl) |
dea3101e | 2725 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2726 | } while (1); |
2727 | return 0; | |
2728 | } | |
dea3101e | 2729 | |
e59058c4 | 2730 | /** |
3621a710 | 2731 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2732 | * @phba: Pointer to HBA context object. |
2733 | * @pring: Pointer to driver SLI ring object. | |
2734 | * @tag: buffer tag. | |
2735 | * | |
2736 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2737 | * is set in the tag the buffer is posted for a particular exchange, | |
2738 | * the function will return the buffer without replacing the buffer. | |
2739 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2740 | * returns the buffer and also posts another buffer to the firmware. | |
2741 | **/ | |
76bb24ef JS |
2742 | static struct lpfc_dmabuf * |
2743 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2744 | struct lpfc_sli_ring *pring, |
2745 | uint32_t tag) | |
76bb24ef | 2746 | { |
9f1e1b50 JS |
2747 | struct hbq_dmabuf *hbq_entry; |
2748 | ||
76bb24ef JS |
2749 | if (tag & QUE_BUFTAG_BIT) |
2750 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2751 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2752 | if (!hbq_entry) | |
2753 | return NULL; | |
2754 | return &hbq_entry->dbuf; | |
76bb24ef | 2755 | } |
57127f15 | 2756 | |
3772a991 JS |
2757 | /** |
2758 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2759 | * @phba: Pointer to HBA context object. | |
2760 | * @pring: Pointer to driver SLI ring object. | |
2761 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2762 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2763 | * @fch_type: the type for the first frame of the sequence. | |
2764 | * | |
2765 | * This function is called with no lock held. This function uses the r_ctl and | |
2766 | * type of the received sequence to find the correct callback function to call | |
2767 | * to process the sequence. | |
2768 | **/ | |
2769 | static int | |
2770 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2771 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2772 | uint32_t fch_type) | |
2773 | { | |
2774 | int i; | |
2775 | ||
f358dd0c JS |
2776 | switch (fch_type) { |
2777 | case FC_TYPE_NVME: | |
d613b6a7 | 2778 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
f358dd0c JS |
2779 | return 1; |
2780 | default: | |
2781 | break; | |
2782 | } | |
2783 | ||
3772a991 JS |
2784 | /* unSolicited Responses */ |
2785 | if (pring->prt[0].profile) { | |
2786 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2787 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2788 | saveq); | |
2789 | return 1; | |
2790 | } | |
2791 | /* We must search, based on rctl / type | |
2792 | for the right routine */ | |
2793 | for (i = 0; i < pring->num_mask; i++) { | |
2794 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2795 | (pring->prt[i].type == fch_type)) { | |
2796 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2797 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2798 | (phba, pring, saveq); | |
2799 | return 1; | |
2800 | } | |
2801 | } | |
2802 | return 0; | |
2803 | } | |
e59058c4 JS |
2804 | |
2805 | /** | |
3621a710 | 2806 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2807 | * @phba: Pointer to HBA context object. |
2808 | * @pring: Pointer to driver SLI ring object. | |
2809 | * @saveq: Pointer to the unsolicited iocb. | |
2810 | * | |
2811 | * This function is called with no lock held by the ring event handler | |
2812 | * when there is an unsolicited iocb posted to the response ring by the | |
2813 | * firmware. This function gets the buffer associated with the iocbs | |
2814 | * and calls the event handler for the ring. This function handles both | |
2815 | * qring buffers and hbq buffers. | |
2816 | * When the function returns 1 the caller can free the iocb object otherwise | |
2817 | * upper layer functions will free the iocb objects. | |
2818 | **/ | |
dea3101e JB |
2819 | static int |
2820 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2821 | struct lpfc_iocbq *saveq) | |
2822 | { | |
2823 | IOCB_t * irsp; | |
2824 | WORD5 * w5p; | |
2825 | uint32_t Rctl, Type; | |
76bb24ef | 2826 | struct lpfc_iocbq *iocbq; |
3163f725 | 2827 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2828 | |
dea3101e | 2829 | irsp = &(saveq->iocb); |
57127f15 JS |
2830 | |
2831 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2832 | if (pring->lpfc_sli_rcv_async_status) | |
2833 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2834 | else | |
2835 | lpfc_printf_log(phba, | |
2836 | KERN_WARNING, | |
2837 | LOG_SLI, | |
2838 | "0316 Ring %d handler: unexpected " | |
2839 | "ASYNC_STATUS iocb received evt_code " | |
2840 | "0x%x\n", | |
2841 | pring->ringno, | |
2842 | irsp->un.asyncstat.evt_code); | |
2843 | return 1; | |
2844 | } | |
2845 | ||
3163f725 JS |
2846 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2847 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2848 | if (irsp->ulpBdeCount > 0) { | |
2849 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2850 | irsp->un.ulpWord[3]); | |
2851 | lpfc_in_buf_free(phba, dmzbuf); | |
2852 | } | |
2853 | ||
2854 | if (irsp->ulpBdeCount > 1) { | |
2855 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2856 | irsp->unsli3.sli3Words[3]); | |
2857 | lpfc_in_buf_free(phba, dmzbuf); | |
2858 | } | |
2859 | ||
2860 | if (irsp->ulpBdeCount > 2) { | |
2861 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2862 | irsp->unsli3.sli3Words[7]); | |
2863 | lpfc_in_buf_free(phba, dmzbuf); | |
2864 | } | |
2865 | ||
2866 | return 1; | |
2867 | } | |
2868 | ||
92d7f7b0 | 2869 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2870 | if (irsp->ulpBdeCount != 0) { |
2871 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2872 | irsp->un.ulpWord[3]); | |
2873 | if (!saveq->context2) | |
2874 | lpfc_printf_log(phba, | |
2875 | KERN_ERR, | |
2876 | LOG_SLI, | |
2877 | "0341 Ring %d Cannot find buffer for " | |
2878 | "an unsolicited iocb. tag 0x%x\n", | |
2879 | pring->ringno, | |
2880 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2881 | } |
2882 | if (irsp->ulpBdeCount == 2) { | |
2883 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2884 | irsp->unsli3.sli3Words[7]); | |
2885 | if (!saveq->context3) | |
2886 | lpfc_printf_log(phba, | |
2887 | KERN_ERR, | |
2888 | LOG_SLI, | |
2889 | "0342 Ring %d Cannot find buffer for an" | |
2890 | " unsolicited iocb. tag 0x%x\n", | |
2891 | pring->ringno, | |
2892 | irsp->unsli3.sli3Words[7]); | |
2893 | } | |
2894 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2895 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2896 | if (irsp->ulpBdeCount != 0) { |
2897 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2898 | irsp->un.ulpWord[3]); | |
9c2face6 | 2899 | if (!iocbq->context2) |
76bb24ef JS |
2900 | lpfc_printf_log(phba, |
2901 | KERN_ERR, | |
2902 | LOG_SLI, | |
2903 | "0343 Ring %d Cannot find " | |
2904 | "buffer for an unsolicited iocb" | |
2905 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2906 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2907 | } |
2908 | if (irsp->ulpBdeCount == 2) { | |
2909 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2910 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2911 | if (!iocbq->context3) |
76bb24ef JS |
2912 | lpfc_printf_log(phba, |
2913 | KERN_ERR, | |
2914 | LOG_SLI, | |
2915 | "0344 Ring %d Cannot find " | |
2916 | "buffer for an unsolicited " | |
2917 | "iocb. tag 0x%x\n", | |
2918 | pring->ringno, | |
2919 | irsp->unsli3.sli3Words[7]); | |
2920 | } | |
2921 | } | |
92d7f7b0 | 2922 | } |
9c2face6 JS |
2923 | if (irsp->ulpBdeCount != 0 && |
2924 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2925 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2926 | int found = 0; | |
2927 | ||
2928 | /* search continue save q for same XRI */ | |
2929 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2930 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2931 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2932 | list_add_tail(&saveq->list, &iocbq->list); |
2933 | found = 1; | |
2934 | break; | |
2935 | } | |
2936 | } | |
2937 | if (!found) | |
2938 | list_add_tail(&saveq->clist, | |
2939 | &pring->iocb_continue_saveq); | |
2940 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2941 | list_del_init(&iocbq->clist); | |
2942 | saveq = iocbq; | |
2943 | irsp = &(saveq->iocb); | |
2944 | } else | |
2945 | return 0; | |
2946 | } | |
2947 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2948 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2949 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2950 | Rctl = FC_RCTL_ELS_REQ; |
2951 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2952 | } else { |
2953 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2954 | Rctl = w5p->hcsw.Rctl; | |
2955 | Type = w5p->hcsw.Type; | |
2956 | ||
2957 | /* Firmware Workaround */ | |
2958 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2959 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2960 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2961 | Rctl = FC_RCTL_ELS_REQ; |
2962 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2963 | w5p->hcsw.Rctl = Rctl; |
2964 | w5p->hcsw.Type = Type; | |
2965 | } | |
2966 | } | |
92d7f7b0 | 2967 | |
3772a991 | 2968 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2969 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2970 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2971 | "Type x%x received\n", |
e8b62011 | 2972 | pring->ringno, Rctl, Type); |
3772a991 | 2973 | |
92d7f7b0 | 2974 | return 1; |
dea3101e JB |
2975 | } |
2976 | ||
e59058c4 | 2977 | /** |
3621a710 | 2978 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2979 | * @phba: Pointer to HBA context object. |
2980 | * @pring: Pointer to driver SLI ring object. | |
2981 | * @prspiocb: Pointer to response iocb object. | |
2982 | * | |
2983 | * This function looks up the iocb_lookup table to get the command iocb | |
2984 | * corresponding to the given response iocb using the iotag of the | |
341b2aa8 DK |
2985 | * response iocb. This function is called with the hbalock held |
2986 | * for sli3 devices or the ring_lock for sli4 devices. | |
e59058c4 JS |
2987 | * This function returns the command iocb object if it finds the command |
2988 | * iocb else returns NULL. | |
2989 | **/ | |
dea3101e | 2990 | static struct lpfc_iocbq * |
2e0fef85 JS |
2991 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2992 | struct lpfc_sli_ring *pring, | |
2993 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2994 | { |
dea3101e JB |
2995 | struct lpfc_iocbq *cmd_iocb = NULL; |
2996 | uint16_t iotag; | |
1c2ba475 | 2997 | lockdep_assert_held(&phba->hbalock); |
dea3101e | 2998 | |
604a3e30 JB |
2999 | iotag = prspiocb->iocb.ulpIoTag; |
3000 | ||
3001 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
3002 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 | 3003 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
89533e9b JS |
3004 | /* remove from txcmpl queue list */ |
3005 | list_del_init(&cmd_iocb->list); | |
4f2e66c6 | 3006 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
89533e9b | 3007 | return cmd_iocb; |
2a9bf3d0 | 3008 | } |
dea3101e JB |
3009 | } |
3010 | ||
dea3101e | 3011 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
89533e9b | 3012 | "0317 iotag x%x is out of " |
604a3e30 | 3013 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 3014 | iotag, phba->sli.last_iotag, |
604a3e30 | 3015 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
3016 | return NULL; |
3017 | } | |
3018 | ||
3772a991 JS |
3019 | /** |
3020 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
3021 | * @phba: Pointer to HBA context object. | |
3022 | * @pring: Pointer to driver SLI ring object. | |
3023 | * @iotag: IOCB tag. | |
3024 | * | |
3025 | * This function looks up the iocb_lookup table to get the command iocb | |
3026 | * corresponding to the given iotag. This function is called with the | |
3027 | * hbalock held. | |
3028 | * This function returns the command iocb object if it finds the command | |
3029 | * iocb else returns NULL. | |
3030 | **/ | |
3031 | static struct lpfc_iocbq * | |
3032 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
3033 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
3034 | { | |
895427bd | 3035 | struct lpfc_iocbq *cmd_iocb = NULL; |
3772a991 | 3036 | |
1c2ba475 | 3037 | lockdep_assert_held(&phba->hbalock); |
3772a991 JS |
3038 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
3039 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 JS |
3040 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
3041 | /* remove from txcmpl queue list */ | |
3042 | list_del_init(&cmd_iocb->list); | |
3043 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
4f2e66c6 | 3044 | return cmd_iocb; |
2a9bf3d0 | 3045 | } |
3772a991 | 3046 | } |
89533e9b | 3047 | |
3772a991 | 3048 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
895427bd JS |
3049 | "0372 iotag x%x lookup error: max iotag (x%x) " |
3050 | "iocb_flag x%x\n", | |
3051 | iotag, phba->sli.last_iotag, | |
3052 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); | |
3772a991 JS |
3053 | return NULL; |
3054 | } | |
3055 | ||
e59058c4 | 3056 | /** |
3621a710 | 3057 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
3058 | * @phba: Pointer to HBA context object. |
3059 | * @pring: Pointer to driver SLI ring object. | |
3060 | * @saveq: Pointer to the response iocb to be processed. | |
3061 | * | |
3062 | * This function is called by the ring event handler for non-fcp | |
3063 | * rings when there is a new response iocb in the response ring. | |
3064 | * The caller is not required to hold any locks. This function | |
3065 | * gets the command iocb associated with the response iocb and | |
3066 | * calls the completion handler for the command iocb. If there | |
3067 | * is no completion handler, the function will free the resources | |
3068 | * associated with command iocb. If the response iocb is for | |
3069 | * an already aborted command iocb, the status of the completion | |
3070 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
3071 | * This function always returns 1. | |
3072 | **/ | |
dea3101e | 3073 | static int |
2e0fef85 | 3074 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
3075 | struct lpfc_iocbq *saveq) |
3076 | { | |
2e0fef85 | 3077 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
3078 | int rc = 1; |
3079 | unsigned long iflag; | |
3080 | ||
3081 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
341b2aa8 DK |
3082 | if (phba->sli_rev == LPFC_SLI_REV4) |
3083 | spin_lock_irqsave(&pring->ring_lock, iflag); | |
3084 | else | |
3085 | spin_lock_irqsave(&phba->hbalock, iflag); | |
604a3e30 | 3086 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
341b2aa8 DK |
3087 | if (phba->sli_rev == LPFC_SLI_REV4) |
3088 | spin_unlock_irqrestore(&pring->ring_lock, iflag); | |
3089 | else | |
3090 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2e0fef85 | 3091 | |
dea3101e JB |
3092 | if (cmdiocbp) { |
3093 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
3094 | /* |
3095 | * If an ELS command failed send an event to mgmt | |
3096 | * application. | |
3097 | */ | |
3098 | if (saveq->iocb.ulpStatus && | |
3099 | (pring->ringno == LPFC_ELS_RING) && | |
3100 | (cmdiocbp->iocb.ulpCommand == | |
3101 | CMD_ELS_REQUEST64_CR)) | |
3102 | lpfc_send_els_failure_event(phba, | |
3103 | cmdiocbp, saveq); | |
3104 | ||
dea3101e JB |
3105 | /* |
3106 | * Post all ELS completions to the worker thread. | |
3107 | * All other are passed to the completion callback. | |
3108 | */ | |
3109 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
3110 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
3111 | (cmdiocbp->iocb_flag & | |
3112 | LPFC_DRIVER_ABORTED)) { | |
3113 | spin_lock_irqsave(&phba->hbalock, | |
3114 | iflag); | |
07951076 JS |
3115 | cmdiocbp->iocb_flag &= |
3116 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
3117 | spin_unlock_irqrestore(&phba->hbalock, |
3118 | iflag); | |
07951076 JS |
3119 | saveq->iocb.ulpStatus = |
3120 | IOSTAT_LOCAL_REJECT; | |
3121 | saveq->iocb.un.ulpWord[4] = | |
3122 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
3123 | |
3124 | /* Firmware could still be in progress | |
3125 | * of DMAing payload, so don't free data | |
3126 | * buffer till after a hbeat. | |
3127 | */ | |
341af102 JS |
3128 | spin_lock_irqsave(&phba->hbalock, |
3129 | iflag); | |
0ff10d46 | 3130 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
3131 | spin_unlock_irqrestore(&phba->hbalock, |
3132 | iflag); | |
3133 | } | |
0f65ff68 JS |
3134 | if (phba->sli_rev == LPFC_SLI_REV4) { |
3135 | if (saveq->iocb_flag & | |
3136 | LPFC_EXCHANGE_BUSY) { | |
3137 | /* Set cmdiocb flag for the | |
3138 | * exchange busy so sgl (xri) | |
3139 | * will not be released until | |
3140 | * the abort xri is received | |
3141 | * from hba. | |
3142 | */ | |
3143 | spin_lock_irqsave( | |
3144 | &phba->hbalock, iflag); | |
3145 | cmdiocbp->iocb_flag |= | |
3146 | LPFC_EXCHANGE_BUSY; | |
3147 | spin_unlock_irqrestore( | |
3148 | &phba->hbalock, iflag); | |
3149 | } | |
3150 | if (cmdiocbp->iocb_flag & | |
3151 | LPFC_DRIVER_ABORTED) { | |
3152 | /* | |
3153 | * Clear LPFC_DRIVER_ABORTED | |
3154 | * bit in case it was driver | |
3155 | * initiated abort. | |
3156 | */ | |
3157 | spin_lock_irqsave( | |
3158 | &phba->hbalock, iflag); | |
3159 | cmdiocbp->iocb_flag &= | |
3160 | ~LPFC_DRIVER_ABORTED; | |
3161 | spin_unlock_irqrestore( | |
3162 | &phba->hbalock, iflag); | |
3163 | cmdiocbp->iocb.ulpStatus = | |
3164 | IOSTAT_LOCAL_REJECT; | |
3165 | cmdiocbp->iocb.un.ulpWord[4] = | |
3166 | IOERR_ABORT_REQUESTED; | |
3167 | /* | |
3168 | * For SLI4, irsiocb contains | |
3169 | * NO_XRI in sli_xritag, it | |
3170 | * shall not affect releasing | |
3171 | * sgl (xri) process. | |
3172 | */ | |
3173 | saveq->iocb.ulpStatus = | |
3174 | IOSTAT_LOCAL_REJECT; | |
3175 | saveq->iocb.un.ulpWord[4] = | |
3176 | IOERR_SLI_ABORTED; | |
3177 | spin_lock_irqsave( | |
3178 | &phba->hbalock, iflag); | |
3179 | saveq->iocb_flag |= | |
3180 | LPFC_DELAY_MEM_FREE; | |
3181 | spin_unlock_irqrestore( | |
3182 | &phba->hbalock, iflag); | |
3183 | } | |
07951076 | 3184 | } |
dea3101e | 3185 | } |
2e0fef85 | 3186 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
3187 | } else |
3188 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
3189 | } else { |
3190 | /* | |
3191 | * Unknown initiating command based on the response iotag. | |
3192 | * This could be the case on the ELS ring because of | |
3193 | * lpfc_els_abort(). | |
3194 | */ | |
3195 | if (pring->ringno != LPFC_ELS_RING) { | |
3196 | /* | |
3197 | * Ring <ringno> handler: unexpected completion IoTag | |
3198 | * <IoTag> | |
3199 | */ | |
a257bf90 | 3200 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
3201 | "0322 Ring %d handler: " |
3202 | "unexpected completion IoTag x%x " | |
3203 | "Data: x%x x%x x%x x%x\n", | |
3204 | pring->ringno, | |
3205 | saveq->iocb.ulpIoTag, | |
3206 | saveq->iocb.ulpStatus, | |
3207 | saveq->iocb.un.ulpWord[4], | |
3208 | saveq->iocb.ulpCommand, | |
3209 | saveq->iocb.ulpContext); | |
dea3101e JB |
3210 | } |
3211 | } | |
68876920 | 3212 | |
dea3101e JB |
3213 | return rc; |
3214 | } | |
3215 | ||
e59058c4 | 3216 | /** |
3621a710 | 3217 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
3218 | * @phba: Pointer to HBA context object. |
3219 | * @pring: Pointer to driver SLI ring object. | |
3220 | * | |
3221 | * This function is called from the iocb ring event handlers when | |
3222 | * put pointer is ahead of the get pointer for a ring. This function signal | |
3223 | * an error attention condition to the worker thread and the worker | |
3224 | * thread will transition the HBA to offline state. | |
3225 | **/ | |
2e0fef85 JS |
3226 | static void |
3227 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 3228 | { |
34b02dcd | 3229 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 3230 | /* |
025dfdaf | 3231 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
3232 | * rsp ring <portRspMax> |
3233 | */ | |
3234 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3235 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 3236 | "is bigger than rsp ring %d\n", |
e8b62011 | 3237 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
7e56aa25 | 3238 | pring->sli.sli3.numRiocb); |
875fbdfe | 3239 | |
2e0fef85 | 3240 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
3241 | |
3242 | /* | |
3243 | * All error attention handlers are posted to | |
3244 | * worker thread | |
3245 | */ | |
3246 | phba->work_ha |= HA_ERATT; | |
3247 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 3248 | |
5e9d9b82 | 3249 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
3250 | |
3251 | return; | |
3252 | } | |
3253 | ||
9399627f | 3254 | /** |
3621a710 | 3255 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
3256 | * @ptr: Pointer to address of HBA context object. |
3257 | * | |
3258 | * This function is invoked by the Error Attention polling timer when the | |
3259 | * timer times out. It will check the SLI Error Attention register for | |
3260 | * possible attention events. If so, it will post an Error Attention event | |
3261 | * and wake up worker thread to process it. Otherwise, it will set up the | |
3262 | * Error Attention polling timer for the next poll. | |
3263 | **/ | |
f22eb4d3 | 3264 | void lpfc_poll_eratt(struct timer_list *t) |
9399627f JS |
3265 | { |
3266 | struct lpfc_hba *phba; | |
eb016566 | 3267 | uint32_t eratt = 0; |
aa6fbb75 | 3268 | uint64_t sli_intr, cnt; |
9399627f | 3269 | |
f22eb4d3 | 3270 | phba = from_timer(phba, t, eratt_poll); |
9399627f | 3271 | |
aa6fbb75 JS |
3272 | /* Here we will also keep track of interrupts per sec of the hba */ |
3273 | sli_intr = phba->sli.slistat.sli_intr; | |
3274 | ||
3275 | if (phba->sli.slistat.sli_prev_intr > sli_intr) | |
3276 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + | |
3277 | sli_intr); | |
3278 | else | |
3279 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); | |
3280 | ||
65791f1f JS |
3281 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
3282 | do_div(cnt, phba->eratt_poll_interval); | |
aa6fbb75 JS |
3283 | phba->sli.slistat.sli_ips = cnt; |
3284 | ||
3285 | phba->sli.slistat.sli_prev_intr = sli_intr; | |
3286 | ||
9399627f JS |
3287 | /* Check chip HA register for error event */ |
3288 | eratt = lpfc_sli_check_eratt(phba); | |
3289 | ||
3290 | if (eratt) | |
3291 | /* Tell the worker thread there is work to do */ | |
3292 | lpfc_worker_wake_up(phba); | |
3293 | else | |
3294 | /* Restart the timer for next eratt poll */ | |
256ec0d0 JS |
3295 | mod_timer(&phba->eratt_poll, |
3296 | jiffies + | |
65791f1f | 3297 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
9399627f JS |
3298 | return; |
3299 | } | |
3300 | ||
875fbdfe | 3301 | |
e59058c4 | 3302 | /** |
3621a710 | 3303 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
3304 | * @phba: Pointer to HBA context object. |
3305 | * @pring: Pointer to driver SLI ring object. | |
3306 | * @mask: Host attention register mask for this ring. | |
3307 | * | |
3308 | * This function is called from the interrupt context when there is a ring | |
3309 | * event for the fcp ring. The caller does not hold any lock. | |
3310 | * The function processes each response iocb in the response ring until it | |
25985edc | 3311 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
3312 | * LE bit set. The function will call the completion handler of the command iocb |
3313 | * if the response iocb indicates a completion for a command iocb or it is | |
3314 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
3315 | * function if this is an unsolicited iocb. | |
dea3101e | 3316 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
3317 | * to check it explicitly. |
3318 | */ | |
3319 | int | |
2e0fef85 JS |
3320 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
3321 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3322 | { |
34b02dcd | 3323 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 3324 | IOCB_t *irsp = NULL; |
87f6eaff | 3325 | IOCB_t *entry = NULL; |
dea3101e JB |
3326 | struct lpfc_iocbq *cmdiocbq = NULL; |
3327 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
3328 | uint32_t status; |
3329 | uint32_t portRspPut, portRspMax; | |
3330 | int rc = 1; | |
3331 | lpfc_iocb_type type; | |
3332 | unsigned long iflag; | |
3333 | uint32_t rsp_cmpl = 0; | |
dea3101e | 3334 | |
2e0fef85 | 3335 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3336 | pring->stats.iocb_event++; |
3337 | ||
dea3101e JB |
3338 | /* |
3339 | * The next available response entry should never exceed the maximum | |
3340 | * entries. If it does, treat it as an adapter hardware error. | |
3341 | */ | |
7e56aa25 | 3342 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
3343 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3344 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 3345 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 3346 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3347 | return 1; |
3348 | } | |
45ed1190 JS |
3349 | if (phba->fcp_ring_in_use) { |
3350 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3351 | return 1; | |
3352 | } else | |
3353 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
3354 | |
3355 | rmb(); | |
7e56aa25 | 3356 | while (pring->sli.sli3.rspidx != portRspPut) { |
87f6eaff JSEC |
3357 | /* |
3358 | * Fetch an entry off the ring and copy it into a local data | |
3359 | * structure. The copy involves a byte-swap since the | |
3360 | * network byte order and pci byte orders are different. | |
3361 | */ | |
ed957684 | 3362 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 3363 | phba->last_completion_time = jiffies; |
875fbdfe | 3364 | |
7e56aa25 JS |
3365 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3366 | pring->sli.sli3.rspidx = 0; | |
875fbdfe | 3367 | |
87f6eaff JSEC |
3368 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
3369 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 3370 | phba->iocb_rsp_size); |
a4bc3379 | 3371 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
3372 | irsp = &rspiocbq.iocb; |
3373 | ||
dea3101e JB |
3374 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
3375 | pring->stats.iocb_rsp++; | |
3376 | rsp_cmpl++; | |
3377 | ||
3378 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
3379 | /* |
3380 | * If resource errors reported from HBA, reduce | |
3381 | * queuedepths of the SCSI device. | |
3382 | */ | |
3383 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
3384 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
3385 | IOERR_NO_RESOURCES)) { | |
92d7f7b0 | 3386 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3387 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
3388 | spin_lock_irqsave(&phba->hbalock, iflag); |
3389 | } | |
3390 | ||
dea3101e JB |
3391 | /* Rsp ring <ringno> error: IOCB */ |
3392 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 3393 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 3394 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 3395 | pring->ringno, |
92d7f7b0 JS |
3396 | irsp->un.ulpWord[0], |
3397 | irsp->un.ulpWord[1], | |
3398 | irsp->un.ulpWord[2], | |
3399 | irsp->un.ulpWord[3], | |
3400 | irsp->un.ulpWord[4], | |
3401 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
3402 | *(uint32_t *)&irsp->un1, |
3403 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
3404 | } |
3405 | ||
3406 | switch (type) { | |
3407 | case LPFC_ABORT_IOCB: | |
3408 | case LPFC_SOL_IOCB: | |
3409 | /* | |
3410 | * Idle exchange closed via ABTS from port. No iocb | |
3411 | * resources need to be recovered. | |
3412 | */ | |
3413 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 3414 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 3415 | "0333 IOCB cmd 0x%x" |
dca9479b | 3416 | " processed. Skipping" |
92d7f7b0 | 3417 | " completion\n", |
dca9479b | 3418 | irsp->ulpCommand); |
dea3101e JB |
3419 | break; |
3420 | } | |
3421 | ||
604a3e30 JB |
3422 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
3423 | &rspiocbq); | |
0f65ff68 JS |
3424 | if (unlikely(!cmdiocbq)) |
3425 | break; | |
3426 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
3427 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
3428 | if (cmdiocbq->iocb_cmpl) { | |
3429 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3430 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
3431 | &rspiocbq); | |
3432 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3433 | } | |
dea3101e | 3434 | break; |
a4bc3379 | 3435 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 3436 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 3437 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 3438 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 3439 | break; |
dea3101e JB |
3440 | default: |
3441 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3442 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3443 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3444 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
3445 | MAX_MSG_DATA); | |
898eb71c JP |
3446 | dev_warn(&((phba->pcidev)->dev), |
3447 | "lpfc%d: %s\n", | |
dea3101e JB |
3448 | phba->brd_no, adaptermsg); |
3449 | } else { | |
3450 | /* Unknown IOCB command */ | |
3451 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3452 | "0334 Unknown IOCB command " |
92d7f7b0 | 3453 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 3454 | type, irsp->ulpCommand, |
92d7f7b0 JS |
3455 | irsp->ulpStatus, |
3456 | irsp->ulpIoTag, | |
3457 | irsp->ulpContext); | |
dea3101e JB |
3458 | } |
3459 | break; | |
3460 | } | |
3461 | ||
3462 | /* | |
3463 | * The response IOCB has been processed. Update the ring | |
3464 | * pointer in SLIM. If the port response put pointer has not | |
3465 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
3466 | * response put pointer. | |
3467 | */ | |
7e56aa25 JS |
3468 | writel(pring->sli.sli3.rspidx, |
3469 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3470 | |
7e56aa25 | 3471 | if (pring->sli.sli3.rspidx == portRspPut) |
dea3101e JB |
3472 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3473 | } | |
3474 | ||
3475 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3476 | pring->stats.iocb_rsp_full++; | |
3477 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3478 | writel(status, phba->CAregaddr); | |
3479 | readl(phba->CAregaddr); | |
3480 | } | |
3481 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3482 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3483 | pring->stats.iocb_cmd_empty++; | |
3484 | ||
3485 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3486 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3487 | lpfc_sli_resume_iocb(phba, pring); |
3488 | ||
3489 | if ((pring->lpfc_sli_cmd_available)) | |
3490 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3491 | ||
3492 | } | |
3493 | ||
45ed1190 | 3494 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3495 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3496 | return rc; |
3497 | } | |
3498 | ||
e59058c4 | 3499 | /** |
3772a991 JS |
3500 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3501 | * @phba: Pointer to HBA context object. | |
3502 | * @pring: Pointer to driver SLI ring object. | |
3503 | * @rspiocbp: Pointer to driver response IOCB object. | |
3504 | * | |
3505 | * This function is called from the worker thread when there is a slow-path | |
3506 | * response IOCB to process. This function chains all the response iocbs until | |
3507 | * seeing the iocb with the LE bit set. The function will call | |
3508 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3509 | * completion of a command iocb. The function will call the | |
3510 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3511 | * The function frees the resources or calls the completion handler if this | |
3512 | * iocb is an abort completion. The function returns NULL when the response | |
3513 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3514 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3515 | * response iocb passed in. | |
3516 | **/ | |
3517 | static struct lpfc_iocbq * | |
3518 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3519 | struct lpfc_iocbq *rspiocbp) | |
3520 | { | |
3521 | struct lpfc_iocbq *saveq; | |
3522 | struct lpfc_iocbq *cmdiocbp; | |
3523 | struct lpfc_iocbq *next_iocb; | |
3524 | IOCB_t *irsp = NULL; | |
3525 | uint32_t free_saveq; | |
3526 | uint8_t iocb_cmd_type; | |
3527 | lpfc_iocb_type type; | |
3528 | unsigned long iflag; | |
3529 | int rc; | |
3530 | ||
3531 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3532 | /* First add the response iocb to the countinueq list */ | |
3533 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3534 | pring->iocb_continueq_cnt++; | |
3535 | ||
70f23fd6 | 3536 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3537 | irsp = &rspiocbp->iocb; |
3538 | if (irsp->ulpLe) { | |
3539 | /* | |
3540 | * By default, the driver expects to free all resources | |
3541 | * associated with this iocb completion. | |
3542 | */ | |
3543 | free_saveq = 1; | |
3544 | saveq = list_get_first(&pring->iocb_continueq, | |
3545 | struct lpfc_iocbq, list); | |
3546 | irsp = &(saveq->iocb); | |
3547 | list_del_init(&pring->iocb_continueq); | |
3548 | pring->iocb_continueq_cnt = 0; | |
3549 | ||
3550 | pring->stats.iocb_rsp++; | |
3551 | ||
3552 | /* | |
3553 | * If resource errors reported from HBA, reduce | |
3554 | * queuedepths of the SCSI device. | |
3555 | */ | |
3556 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
3557 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
3558 | IOERR_NO_RESOURCES)) { | |
3772a991 JS |
3559 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3560 | phba->lpfc_rampdown_queue_depth(phba); | |
3561 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3562 | } | |
3563 | ||
3564 | if (irsp->ulpStatus) { | |
3565 | /* Rsp ring <ringno> error: IOCB */ | |
3566 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3567 | "0328 Rsp Ring %d error: " | |
3568 | "IOCB Data: " | |
3569 | "x%x x%x x%x x%x " | |
3570 | "x%x x%x x%x x%x " | |
3571 | "x%x x%x x%x x%x " | |
3572 | "x%x x%x x%x x%x\n", | |
3573 | pring->ringno, | |
3574 | irsp->un.ulpWord[0], | |
3575 | irsp->un.ulpWord[1], | |
3576 | irsp->un.ulpWord[2], | |
3577 | irsp->un.ulpWord[3], | |
3578 | irsp->un.ulpWord[4], | |
3579 | irsp->un.ulpWord[5], | |
3580 | *(((uint32_t *) irsp) + 6), | |
3581 | *(((uint32_t *) irsp) + 7), | |
3582 | *(((uint32_t *) irsp) + 8), | |
3583 | *(((uint32_t *) irsp) + 9), | |
3584 | *(((uint32_t *) irsp) + 10), | |
3585 | *(((uint32_t *) irsp) + 11), | |
3586 | *(((uint32_t *) irsp) + 12), | |
3587 | *(((uint32_t *) irsp) + 13), | |
3588 | *(((uint32_t *) irsp) + 14), | |
3589 | *(((uint32_t *) irsp) + 15)); | |
3590 | } | |
3591 | ||
3592 | /* | |
3593 | * Fetch the IOCB command type and call the correct completion | |
3594 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3595 | * get freed back to the lpfc_iocb_list by the discovery | |
3596 | * kernel thread. | |
3597 | */ | |
3598 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3599 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3600 | switch (type) { | |
3601 | case LPFC_SOL_IOCB: | |
3602 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3603 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3604 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3605 | break; | |
3606 | ||
3607 | case LPFC_UNSOL_IOCB: | |
3608 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3609 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3610 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3611 | if (!rc) | |
3612 | free_saveq = 0; | |
3613 | break; | |
3614 | ||
3615 | case LPFC_ABORT_IOCB: | |
3616 | cmdiocbp = NULL; | |
3617 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3618 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3619 | saveq); | |
3620 | if (cmdiocbp) { | |
3621 | /* Call the specified completion routine */ | |
3622 | if (cmdiocbp->iocb_cmpl) { | |
3623 | spin_unlock_irqrestore(&phba->hbalock, | |
3624 | iflag); | |
3625 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3626 | saveq); | |
3627 | spin_lock_irqsave(&phba->hbalock, | |
3628 | iflag); | |
3629 | } else | |
3630 | __lpfc_sli_release_iocbq(phba, | |
3631 | cmdiocbp); | |
3632 | } | |
3633 | break; | |
3634 | ||
3635 | case LPFC_UNKNOWN_IOCB: | |
3636 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3637 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3638 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3639 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3640 | MAX_MSG_DATA); | |
3641 | dev_warn(&((phba->pcidev)->dev), | |
3642 | "lpfc%d: %s\n", | |
3643 | phba->brd_no, adaptermsg); | |
3644 | } else { | |
3645 | /* Unknown IOCB command */ | |
3646 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3647 | "0335 Unknown IOCB " | |
3648 | "command Data: x%x " | |
3649 | "x%x x%x x%x\n", | |
3650 | irsp->ulpCommand, | |
3651 | irsp->ulpStatus, | |
3652 | irsp->ulpIoTag, | |
3653 | irsp->ulpContext); | |
3654 | } | |
3655 | break; | |
3656 | } | |
3657 | ||
3658 | if (free_saveq) { | |
3659 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3660 | &saveq->list, list) { | |
61f35bff | 3661 | list_del_init(&rspiocbp->list); |
3772a991 JS |
3662 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
3663 | } | |
3664 | __lpfc_sli_release_iocbq(phba, saveq); | |
3665 | } | |
3666 | rspiocbp = NULL; | |
3667 | } | |
3668 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3669 | return rspiocbp; | |
3670 | } | |
3671 | ||
3672 | /** | |
3673 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3674 | * @phba: Pointer to HBA context object. |
3675 | * @pring: Pointer to driver SLI ring object. | |
3676 | * @mask: Host attention register mask for this ring. | |
3677 | * | |
3772a991 JS |
3678 | * This routine wraps the actual slow_ring event process routine from the |
3679 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3680 | **/ |
3772a991 | 3681 | void |
2e0fef85 JS |
3682 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3683 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3684 | { |
3685 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3686 | } | |
3687 | ||
3688 | /** | |
3689 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3690 | * @phba: Pointer to HBA context object. | |
3691 | * @pring: Pointer to driver SLI ring object. | |
3692 | * @mask: Host attention register mask for this ring. | |
3693 | * | |
3694 | * This function is called from the worker thread when there is a ring event | |
3695 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3696 | * remove each response iocb in the response ring and calls the handle | |
3697 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3698 | **/ | |
3699 | static void | |
3700 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3701 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3702 | { |
34b02dcd | 3703 | struct lpfc_pgp *pgp; |
dea3101e JB |
3704 | IOCB_t *entry; |
3705 | IOCB_t *irsp = NULL; | |
3706 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3707 | uint32_t portRspPut, portRspMax; |
dea3101e | 3708 | unsigned long iflag; |
3772a991 | 3709 | uint32_t status; |
dea3101e | 3710 | |
34b02dcd | 3711 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3712 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3713 | pring->stats.iocb_event++; |
3714 | ||
dea3101e JB |
3715 | /* |
3716 | * The next available response entry should never exceed the maximum | |
3717 | * entries. If it does, treat it as an adapter hardware error. | |
3718 | */ | |
7e56aa25 | 3719 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
3720 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3721 | if (portRspPut >= portRspMax) { | |
3722 | /* | |
025dfdaf | 3723 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3724 | * rsp ring <portRspMax> |
3725 | */ | |
ed957684 | 3726 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3727 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3728 | "is bigger than rsp ring %d\n", |
e8b62011 | 3729 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3730 | |
2e0fef85 JS |
3731 | phba->link_state = LPFC_HBA_ERROR; |
3732 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3733 | |
3734 | phba->work_hs = HS_FFER3; | |
3735 | lpfc_handle_eratt(phba); | |
3736 | ||
3772a991 | 3737 | return; |
dea3101e JB |
3738 | } |
3739 | ||
3740 | rmb(); | |
7e56aa25 | 3741 | while (pring->sli.sli3.rspidx != portRspPut) { |
dea3101e JB |
3742 | /* |
3743 | * Build a completion list and call the appropriate handler. | |
3744 | * The process is to get the next available response iocb, get | |
3745 | * a free iocb from the list, copy the response data into the | |
3746 | * free iocb, insert to the continuation list, and update the | |
3747 | * next response index to slim. This process makes response | |
3748 | * iocb's in the ring available to DMA as fast as possible but | |
3749 | * pays a penalty for a copy operation. Since the iocb is | |
3750 | * only 32 bytes, this penalty is considered small relative to | |
3751 | * the PCI reads for register values and a slim write. When | |
3752 | * the ulpLe field is set, the entire Command has been | |
3753 | * received. | |
3754 | */ | |
ed957684 JS |
3755 | entry = lpfc_resp_iocb(phba, pring); |
3756 | ||
858c9f6c | 3757 | phba->last_completion_time = jiffies; |
2e0fef85 | 3758 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3759 | if (rspiocbp == NULL) { |
3760 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3761 | "completion.\n", __func__); |
dea3101e JB |
3762 | break; |
3763 | } | |
3764 | ||
ed957684 JS |
3765 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3766 | phba->iocb_rsp_size); | |
dea3101e JB |
3767 | irsp = &rspiocbp->iocb; |
3768 | ||
7e56aa25 JS |
3769 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3770 | pring->sli.sli3.rspidx = 0; | |
dea3101e | 3771 | |
a58cbd52 JS |
3772 | if (pring->ringno == LPFC_ELS_RING) { |
3773 | lpfc_debugfs_slow_ring_trc(phba, | |
3774 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3775 | *(((uint32_t *) irsp) + 4), | |
3776 | *(((uint32_t *) irsp) + 6), | |
3777 | *(((uint32_t *) irsp) + 7)); | |
3778 | } | |
3779 | ||
7e56aa25 JS |
3780 | writel(pring->sli.sli3.rspidx, |
3781 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3782 | |
3772a991 JS |
3783 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3784 | /* Handle the response IOCB */ | |
3785 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3786 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3787 | |
3788 | /* | |
3789 | * If the port response put pointer has not been updated, sync | |
3790 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3791 | * response put pointer. | |
3792 | */ | |
7e56aa25 | 3793 | if (pring->sli.sli3.rspidx == portRspPut) { |
dea3101e JB |
3794 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3795 | } | |
7e56aa25 | 3796 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
dea3101e | 3797 | |
92d7f7b0 | 3798 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3799 | /* At least one response entry has been freed */ |
3800 | pring->stats.iocb_rsp_full++; | |
3801 | /* SET RxRE_RSP in Chip Att register */ | |
3802 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3803 | writel(status, phba->CAregaddr); | |
3804 | readl(phba->CAregaddr); /* flush */ | |
3805 | } | |
3806 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3807 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3808 | pring->stats.iocb_cmd_empty++; | |
3809 | ||
3810 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3811 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3812 | lpfc_sli_resume_iocb(phba, pring); |
3813 | ||
3814 | if ((pring->lpfc_sli_cmd_available)) | |
3815 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3816 | ||
3817 | } | |
3818 | ||
2e0fef85 | 3819 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3820 | return; |
dea3101e JB |
3821 | } |
3822 | ||
4f774513 JS |
3823 | /** |
3824 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3825 | * @phba: Pointer to HBA context object. | |
3826 | * @pring: Pointer to driver SLI ring object. | |
3827 | * @mask: Host attention register mask for this ring. | |
3828 | * | |
3829 | * This function is called from the worker thread when there is a pending | |
3830 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3831 | * queue. The caller does not hold any lock. The function will remove each | |
3832 | * response iocb from the response worker queue and calls the handle | |
3833 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3834 | **/ | |
3835 | static void | |
3836 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3837 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3838 | { | |
3839 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3840 | struct hbq_dmabuf *dmabuf; |
3841 | struct lpfc_cq_event *cq_event; | |
4f774513 | 3842 | unsigned long iflag; |
0ef01a2d | 3843 | int count = 0; |
4f774513 | 3844 | |
45ed1190 JS |
3845 | spin_lock_irqsave(&phba->hbalock, iflag); |
3846 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3847 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3848 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3849 | /* Get the response iocb from the head of work queue */ |
3850 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3851 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3852 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3853 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3854 | |
3855 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3856 | case CQE_CODE_COMPL_WQE: | |
3857 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3858 | cq_event); | |
45ed1190 JS |
3859 | /* Translate ELS WCQE to response IOCBQ */ |
3860 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3861 | irspiocbq); | |
3862 | if (irspiocbq) | |
3863 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3864 | irspiocbq); | |
0ef01a2d | 3865 | count++; |
4d9ab994 JS |
3866 | break; |
3867 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3868 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3869 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3870 | cq_event); | |
3871 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
0ef01a2d | 3872 | count++; |
4d9ab994 JS |
3873 | break; |
3874 | default: | |
3875 | break; | |
3876 | } | |
0ef01a2d JS |
3877 | |
3878 | /* Limit the number of events to 64 to avoid soft lockups */ | |
3879 | if (count == 64) | |
3880 | break; | |
4f774513 JS |
3881 | } |
3882 | } | |
3883 | ||
e59058c4 | 3884 | /** |
3621a710 | 3885 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3886 | * @phba: Pointer to HBA context object. |
3887 | * @pring: Pointer to driver SLI ring object. | |
3888 | * | |
3889 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3890 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3891 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3892 | * the return of this function. The caller is not required to hold any locks. | |
3893 | **/ | |
2e0fef85 | 3894 | void |
dea3101e JB |
3895 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3896 | { | |
2534ba75 | 3897 | LIST_HEAD(completions); |
dea3101e | 3898 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3899 | |
92d7f7b0 JS |
3900 | if (pring->ringno == LPFC_ELS_RING) { |
3901 | lpfc_fabric_abort_hba(phba); | |
3902 | } | |
3903 | ||
dea3101e JB |
3904 | /* Error everything on txq and txcmplq |
3905 | * First do the txq. | |
3906 | */ | |
db55fba8 JS |
3907 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
3908 | spin_lock_irq(&pring->ring_lock); | |
3909 | list_splice_init(&pring->txq, &completions); | |
3910 | pring->txq_cnt = 0; | |
3911 | spin_unlock_irq(&pring->ring_lock); | |
dea3101e | 3912 | |
db55fba8 JS |
3913 | spin_lock_irq(&phba->hbalock); |
3914 | /* Next issue ABTS for everything on the txcmplq */ | |
3915 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3916 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3917 | spin_unlock_irq(&phba->hbalock); | |
3918 | } else { | |
3919 | spin_lock_irq(&phba->hbalock); | |
3920 | list_splice_init(&pring->txq, &completions); | |
3921 | pring->txq_cnt = 0; | |
dea3101e | 3922 | |
db55fba8 JS |
3923 | /* Next issue ABTS for everything on the txcmplq */ |
3924 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3925 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
3926 | spin_unlock_irq(&phba->hbalock); | |
3927 | } | |
dea3101e | 3928 | |
a257bf90 JS |
3929 | /* Cancel all the IOCBs from the completions list */ |
3930 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3931 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3932 | } |
3933 | ||
895427bd JS |
3934 | /** |
3935 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring | |
3936 | * @phba: Pointer to HBA context object. | |
3937 | * @pring: Pointer to driver SLI ring object. | |
3938 | * | |
3939 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3940 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3941 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3942 | * the return of this function. The caller is not required to hold any locks. | |
3943 | **/ | |
3944 | void | |
3945 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
3946 | { | |
3947 | LIST_HEAD(completions); | |
3948 | struct lpfc_iocbq *iocb, *next_iocb; | |
3949 | ||
3950 | if (pring->ringno == LPFC_ELS_RING) | |
3951 | lpfc_fabric_abort_hba(phba); | |
3952 | ||
3953 | spin_lock_irq(&phba->hbalock); | |
3954 | /* Next issue ABTS for everything on the txcmplq */ | |
3955 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
3956 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); | |
3957 | spin_unlock_irq(&phba->hbalock); | |
3958 | } | |
3959 | ||
3960 | ||
db55fba8 JS |
3961 | /** |
3962 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings | |
3963 | * @phba: Pointer to HBA context object. | |
3964 | * @pring: Pointer to driver SLI ring object. | |
3965 | * | |
3966 | * This function aborts all iocbs in FCP rings and frees all the iocb | |
3967 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3968 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3969 | * the return of this function. The caller is not required to hold any locks. | |
3970 | **/ | |
3971 | void | |
3972 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) | |
3973 | { | |
3974 | struct lpfc_sli *psli = &phba->sli; | |
3975 | struct lpfc_sli_ring *pring; | |
3976 | uint32_t i; | |
3977 | ||
3978 | /* Look on all the FCP Rings for the iotag */ | |
3979 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
3980 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
895427bd | 3981 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
db55fba8 JS |
3982 | lpfc_sli_abort_iocb_ring(phba, pring); |
3983 | } | |
3984 | } else { | |
895427bd | 3985 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
db55fba8 JS |
3986 | lpfc_sli_abort_iocb_ring(phba, pring); |
3987 | } | |
3988 | } | |
3989 | ||
895427bd JS |
3990 | /** |
3991 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings | |
3992 | * @phba: Pointer to HBA context object. | |
3993 | * | |
3994 | * This function aborts all wqes in NVME rings. This function issues an | |
3995 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in | |
3996 | * the txcmplq is not guaranteed to complete before the return of this | |
3997 | * function. The caller is not required to hold any locks. | |
3998 | **/ | |
3999 | void | |
4000 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) | |
4001 | { | |
4002 | struct lpfc_sli_ring *pring; | |
4003 | uint32_t i; | |
4004 | ||
4005 | if (phba->sli_rev < LPFC_SLI_REV4) | |
4006 | return; | |
4007 | ||
4008 | /* Abort all IO on each NVME ring. */ | |
4009 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { | |
4010 | pring = phba->sli4_hba.nvme_wq[i]->pring; | |
4011 | lpfc_sli_abort_wqe_ring(phba, pring); | |
4012 | } | |
4013 | } | |
4014 | ||
db55fba8 | 4015 | |
a8e497d5 | 4016 | /** |
3621a710 | 4017 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
4018 | * @phba: Pointer to HBA context object. |
4019 | * | |
4020 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
4021 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
4022 | * for all the iocb commands in txcmplq, they will just be returned with | |
4023 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
4024 | * slot has been permanently disabled. | |
4025 | **/ | |
4026 | void | |
4027 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
4028 | { | |
4029 | LIST_HEAD(txq); | |
4030 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
4031 | struct lpfc_sli *psli = &phba->sli; |
4032 | struct lpfc_sli_ring *pring; | |
db55fba8 | 4033 | uint32_t i; |
c1dd9111 | 4034 | struct lpfc_iocbq *piocb, *next_iocb; |
a8e497d5 JS |
4035 | |
4036 | spin_lock_irq(&phba->hbalock); | |
4f2e66c6 JS |
4037 | /* Indicate the I/O queues are flushed */ |
4038 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; | |
a8e497d5 JS |
4039 | spin_unlock_irq(&phba->hbalock); |
4040 | ||
db55fba8 JS |
4041 | /* Look on all the FCP Rings for the iotag */ |
4042 | if (phba->sli_rev >= LPFC_SLI_REV4) { | |
4043 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { | |
895427bd | 4044 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
db55fba8 JS |
4045 | |
4046 | spin_lock_irq(&pring->ring_lock); | |
4047 | /* Retrieve everything on txq */ | |
4048 | list_splice_init(&pring->txq, &txq); | |
c1dd9111 JS |
4049 | list_for_each_entry_safe(piocb, next_iocb, |
4050 | &pring->txcmplq, list) | |
4051 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
db55fba8 JS |
4052 | /* Retrieve everything on the txcmplq */ |
4053 | list_splice_init(&pring->txcmplq, &txcmplq); | |
4054 | pring->txq_cnt = 0; | |
4055 | pring->txcmplq_cnt = 0; | |
4056 | spin_unlock_irq(&pring->ring_lock); | |
4057 | ||
4058 | /* Flush the txq */ | |
4059 | lpfc_sli_cancel_iocbs(phba, &txq, | |
4060 | IOSTAT_LOCAL_REJECT, | |
4061 | IOERR_SLI_DOWN); | |
4062 | /* Flush the txcmpq */ | |
4063 | lpfc_sli_cancel_iocbs(phba, &txcmplq, | |
4064 | IOSTAT_LOCAL_REJECT, | |
4065 | IOERR_SLI_DOWN); | |
4066 | } | |
4067 | } else { | |
895427bd | 4068 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
a8e497d5 | 4069 | |
db55fba8 JS |
4070 | spin_lock_irq(&phba->hbalock); |
4071 | /* Retrieve everything on txq */ | |
4072 | list_splice_init(&pring->txq, &txq); | |
c1dd9111 JS |
4073 | list_for_each_entry_safe(piocb, next_iocb, |
4074 | &pring->txcmplq, list) | |
4075 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
db55fba8 JS |
4076 | /* Retrieve everything on the txcmplq */ |
4077 | list_splice_init(&pring->txcmplq, &txcmplq); | |
4078 | pring->txq_cnt = 0; | |
4079 | pring->txcmplq_cnt = 0; | |
4080 | spin_unlock_irq(&phba->hbalock); | |
4081 | ||
4082 | /* Flush the txq */ | |
4083 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, | |
4084 | IOERR_SLI_DOWN); | |
4085 | /* Flush the txcmpq */ | |
4086 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, | |
4087 | IOERR_SLI_DOWN); | |
4088 | } | |
a8e497d5 JS |
4089 | } |
4090 | ||
895427bd JS |
4091 | /** |
4092 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings | |
4093 | * @phba: Pointer to HBA context object. | |
4094 | * | |
4095 | * This function flushes all wqes in the nvme rings and frees all resources | |
4096 | * in the txcmplq. This function does not issue abort wqes for the IO | |
4097 | * commands in txcmplq, they will just be returned with | |
4098 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
4099 | * slot has been permanently disabled. | |
4100 | **/ | |
4101 | void | |
4102 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) | |
4103 | { | |
4104 | LIST_HEAD(txcmplq); | |
4105 | struct lpfc_sli_ring *pring; | |
4106 | uint32_t i; | |
c1dd9111 | 4107 | struct lpfc_iocbq *piocb, *next_iocb; |
895427bd JS |
4108 | |
4109 | if (phba->sli_rev < LPFC_SLI_REV4) | |
4110 | return; | |
4111 | ||
4112 | /* Hint to other driver operations that a flush is in progress. */ | |
4113 | spin_lock_irq(&phba->hbalock); | |
4114 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; | |
4115 | spin_unlock_irq(&phba->hbalock); | |
4116 | ||
4117 | /* Cycle through all NVME rings and complete each IO with | |
4118 | * a local driver reason code. This is a flush so no | |
4119 | * abort exchange to FW. | |
4120 | */ | |
4121 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { | |
4122 | pring = phba->sli4_hba.nvme_wq[i]->pring; | |
4123 | ||
895427bd | 4124 | spin_lock_irq(&pring->ring_lock); |
c1dd9111 JS |
4125 | list_for_each_entry_safe(piocb, next_iocb, |
4126 | &pring->txcmplq, list) | |
4127 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
4128 | /* Retrieve everything on the txcmplq */ | |
895427bd JS |
4129 | list_splice_init(&pring->txcmplq, &txcmplq); |
4130 | pring->txcmplq_cnt = 0; | |
4131 | spin_unlock_irq(&pring->ring_lock); | |
4132 | ||
4133 | /* Flush the txcmpq &&&PAE */ | |
4134 | lpfc_sli_cancel_iocbs(phba, &txcmplq, | |
4135 | IOSTAT_LOCAL_REJECT, | |
4136 | IOERR_SLI_DOWN); | |
4137 | } | |
4138 | } | |
4139 | ||
e59058c4 | 4140 | /** |
3772a991 | 4141 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
4142 | * @phba: Pointer to HBA context object. |
4143 | * @mask: Bit mask to be checked. | |
4144 | * | |
4145 | * This function reads the host status register and compares | |
4146 | * with the provided bit mask to check if HBA completed | |
4147 | * the restart. This function will wait in a loop for the | |
4148 | * HBA to complete restart. If the HBA does not restart within | |
4149 | * 15 iterations, the function will reset the HBA again. The | |
4150 | * function returns 1 when HBA fail to restart otherwise returns | |
4151 | * zero. | |
4152 | **/ | |
3772a991 JS |
4153 | static int |
4154 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 4155 | { |
41415862 JW |
4156 | uint32_t status; |
4157 | int i = 0; | |
4158 | int retval = 0; | |
dea3101e | 4159 | |
41415862 | 4160 | /* Read the HBA Host Status Register */ |
9940b97b JS |
4161 | if (lpfc_readl(phba->HSregaddr, &status)) |
4162 | return 1; | |
dea3101e | 4163 | |
41415862 JW |
4164 | /* |
4165 | * Check status register every 100ms for 5 retries, then every | |
4166 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
4167 | * every 2.5 sec for 4. | |
4168 | * Break our of the loop if errors occurred during init. | |
4169 | */ | |
4170 | while (((status & mask) != mask) && | |
4171 | !(status & HS_FFERM) && | |
4172 | i++ < 20) { | |
dea3101e | 4173 | |
41415862 JW |
4174 | if (i <= 5) |
4175 | msleep(10); | |
4176 | else if (i <= 10) | |
4177 | msleep(500); | |
4178 | else | |
4179 | msleep(2500); | |
dea3101e | 4180 | |
41415862 | 4181 | if (i == 15) { |
2e0fef85 | 4182 | /* Do post */ |
92d7f7b0 | 4183 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
4184 | lpfc_sli_brdrestart(phba); |
4185 | } | |
4186 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4187 | if (lpfc_readl(phba->HSregaddr, &status)) { |
4188 | retval = 1; | |
4189 | break; | |
4190 | } | |
41415862 | 4191 | } |
dea3101e | 4192 | |
41415862 JW |
4193 | /* Check to see if any errors occurred during init */ |
4194 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
4195 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4196 | "2751 Adapter failed to restart, " | |
4197 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
4198 | status, | |
4199 | readl(phba->MBslimaddr + 0xa8), | |
4200 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4201 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 4202 | retval = 1; |
dea3101e | 4203 | } |
dea3101e | 4204 | |
41415862 JW |
4205 | return retval; |
4206 | } | |
dea3101e | 4207 | |
da0436e9 JS |
4208 | /** |
4209 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
4210 | * @phba: Pointer to HBA context object. | |
4211 | * @mask: Bit mask to be checked. | |
4212 | * | |
4213 | * This function checks the host status register to check if HBA is | |
4214 | * ready. This function will wait in a loop for the HBA to be ready | |
4215 | * If the HBA is not ready , the function will will reset the HBA PCI | |
4216 | * function again. The function returns 1 when HBA fail to be ready | |
4217 | * otherwise returns zero. | |
4218 | **/ | |
4219 | static int | |
4220 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
4221 | { | |
4222 | uint32_t status; | |
4223 | int retval = 0; | |
4224 | ||
4225 | /* Read the HBA Host Status Register */ | |
4226 | status = lpfc_sli4_post_status_check(phba); | |
4227 | ||
4228 | if (status) { | |
4229 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
4230 | lpfc_sli_brdrestart(phba); | |
4231 | status = lpfc_sli4_post_status_check(phba); | |
4232 | } | |
4233 | ||
4234 | /* Check to see if any errors occurred during init */ | |
4235 | if (status) { | |
4236 | phba->link_state = LPFC_HBA_ERROR; | |
4237 | retval = 1; | |
4238 | } else | |
4239 | phba->sli4_hba.intr_enable = 0; | |
4240 | ||
4241 | return retval; | |
4242 | } | |
4243 | ||
4244 | /** | |
4245 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
4246 | * @phba: Pointer to HBA context object. | |
4247 | * @mask: Bit mask to be checked. | |
4248 | * | |
4249 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
4250 | * from the API jump table function pointer from the lpfc_hba struct. | |
4251 | **/ | |
4252 | int | |
4253 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
4254 | { | |
4255 | return phba->lpfc_sli_brdready(phba, mask); | |
4256 | } | |
4257 | ||
9290831f JS |
4258 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
4259 | ||
e59058c4 | 4260 | /** |
3621a710 | 4261 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
4262 | * @phba: Pointer to HBA context object. |
4263 | * | |
1b51197d JS |
4264 | * This function is called before resetting an HBA. This function is called |
4265 | * with hbalock held and requests HBA to quiesce DMAs before a reset. | |
e59058c4 | 4266 | **/ |
2e0fef85 | 4267 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 4268 | { |
65a29c16 JS |
4269 | uint32_t __iomem *resp_buf; |
4270 | uint32_t __iomem *mbox_buf; | |
9290831f | 4271 | volatile uint32_t mbox; |
9940b97b | 4272 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
4273 | int i; |
4274 | uint8_t hdrtype; | |
4275 | ||
1c2ba475 JT |
4276 | lockdep_assert_held(&phba->hbalock); |
4277 | ||
9290831f JS |
4278 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
4279 | if (hdrtype != 0x80 || | |
4280 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
4281 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
4282 | return; | |
4283 | ||
4284 | /* | |
4285 | * Tell the other part of the chip to suspend temporarily all | |
4286 | * its DMA activity. | |
4287 | */ | |
65a29c16 | 4288 | resp_buf = phba->MBslimaddr; |
9290831f JS |
4289 | |
4290 | /* Disable the error attention */ | |
9940b97b JS |
4291 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
4292 | return; | |
9290831f JS |
4293 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
4294 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 4295 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 4296 | |
9940b97b JS |
4297 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
4298 | return; | |
4299 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
4300 | /* Clear Chip error bit */ |
4301 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 4302 | phba->pport->stopped = 1; |
9290831f JS |
4303 | } |
4304 | ||
4305 | mbox = 0; | |
4306 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
4307 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
4308 | ||
4309 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 4310 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
4311 | writel(mbox, mbox_buf); |
4312 | ||
9940b97b JS |
4313 | for (i = 0; i < 50; i++) { |
4314 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
4315 | return; | |
4316 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
4317 | mdelay(1); | |
4318 | else | |
4319 | break; | |
4320 | } | |
4321 | resp_data = 0; | |
4322 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
4323 | return; | |
4324 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 4325 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 4326 | phba->pport->stopped) |
9290831f JS |
4327 | goto restore_hc; |
4328 | else | |
4329 | goto clear_errat; | |
4330 | } | |
4331 | ||
4332 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
4333 | resp_data = 0; |
4334 | for (i = 0; i < 500; i++) { | |
4335 | if (lpfc_readl(resp_buf, &resp_data)) | |
4336 | return; | |
4337 | if (resp_data != mbox) | |
4338 | mdelay(1); | |
4339 | else | |
4340 | break; | |
4341 | } | |
9290831f JS |
4342 | |
4343 | clear_errat: | |
4344 | ||
9940b97b JS |
4345 | while (++i < 500) { |
4346 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
4347 | return; | |
4348 | if (!(ha_copy & HA_ERATT)) | |
4349 | mdelay(1); | |
4350 | else | |
4351 | break; | |
4352 | } | |
9290831f JS |
4353 | |
4354 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
4355 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 4356 | phba->pport->stopped = 1; |
9290831f JS |
4357 | } |
4358 | ||
4359 | restore_hc: | |
2e0fef85 | 4360 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
4361 | writel(hc_copy, phba->HCregaddr); |
4362 | readl(phba->HCregaddr); /* flush */ | |
4363 | } | |
4364 | ||
e59058c4 | 4365 | /** |
3621a710 | 4366 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
4367 | * @phba: Pointer to HBA context object. |
4368 | * | |
4369 | * This function issues a kill_board mailbox command and waits for | |
4370 | * the error attention interrupt. This function is called for stopping | |
4371 | * the firmware processing. The caller is not required to hold any | |
4372 | * locks. This function calls lpfc_hba_down_post function to free | |
4373 | * any pending commands after the kill. The function will return 1 when it | |
4374 | * fails to kill the board else will return 0. | |
4375 | **/ | |
41415862 | 4376 | int |
2e0fef85 | 4377 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
4378 | { |
4379 | struct lpfc_sli *psli; | |
4380 | LPFC_MBOXQ_t *pmb; | |
4381 | uint32_t status; | |
4382 | uint32_t ha_copy; | |
4383 | int retval; | |
4384 | int i = 0; | |
dea3101e | 4385 | |
41415862 | 4386 | psli = &phba->sli; |
dea3101e | 4387 | |
41415862 | 4388 | /* Kill HBA */ |
ed957684 | 4389 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
4390 | "0329 Kill HBA Data: x%x x%x\n", |
4391 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 4392 | |
98c9ea5c JS |
4393 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4394 | if (!pmb) | |
41415862 | 4395 | return 1; |
41415862 JW |
4396 | |
4397 | /* Disable the error attention */ | |
2e0fef85 | 4398 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
4399 | if (lpfc_readl(phba->HCregaddr, &status)) { |
4400 | spin_unlock_irq(&phba->hbalock); | |
4401 | mempool_free(pmb, phba->mbox_mem_pool); | |
4402 | return 1; | |
4403 | } | |
41415862 JW |
4404 | status &= ~HC_ERINT_ENA; |
4405 | writel(status, phba->HCregaddr); | |
4406 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
4407 | phba->link_flag |= LS_IGNORE_ERATT; |
4408 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
4409 | |
4410 | lpfc_kill_board(phba, pmb); | |
4411 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
4412 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
4413 | ||
4414 | if (retval != MBX_SUCCESS) { | |
4415 | if (retval != MBX_BUSY) | |
4416 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
4417 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
4418 | "2752 KILL_BOARD command failed retval %d\n", | |
4419 | retval); | |
2e0fef85 JS |
4420 | spin_lock_irq(&phba->hbalock); |
4421 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
4422 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
4423 | return 1; |
4424 | } | |
4425 | ||
f4b4c68f JS |
4426 | spin_lock_irq(&phba->hbalock); |
4427 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
4428 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 4429 | |
41415862 JW |
4430 | mempool_free(pmb, phba->mbox_mem_pool); |
4431 | ||
4432 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
4433 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
4434 | * 3 seconds we still set HBA_ERROR state because the status of the | |
4435 | * board is now undefined. | |
4436 | */ | |
9940b97b JS |
4437 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
4438 | return 1; | |
41415862 JW |
4439 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
4440 | mdelay(100); | |
9940b97b JS |
4441 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
4442 | return 1; | |
41415862 JW |
4443 | } |
4444 | ||
4445 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
4446 | if (ha_copy & HA_ERATT) { |
4447 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 4448 | phba->pport->stopped = 1; |
9290831f | 4449 | } |
2e0fef85 | 4450 | spin_lock_irq(&phba->hbalock); |
41415862 | 4451 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 4452 | psli->mbox_active = NULL; |
2e0fef85 JS |
4453 | phba->link_flag &= ~LS_IGNORE_ERATT; |
4454 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 4455 | |
41415862 | 4456 | lpfc_hba_down_post(phba); |
2e0fef85 | 4457 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 4458 | |
2e0fef85 | 4459 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
4460 | } |
4461 | ||
e59058c4 | 4462 | /** |
3772a991 | 4463 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
4464 | * @phba: Pointer to HBA context object. |
4465 | * | |
4466 | * This function resets the HBA by writing HC_INITFF to the control | |
4467 | * register. After the HBA resets, this function resets all the iocb ring | |
4468 | * indices. This function disables PCI layer parity checking during | |
4469 | * the reset. | |
4470 | * This function returns 0 always. | |
4471 | * The caller is not required to hold any locks. | |
4472 | **/ | |
41415862 | 4473 | int |
2e0fef85 | 4474 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 4475 | { |
41415862 | 4476 | struct lpfc_sli *psli; |
dea3101e | 4477 | struct lpfc_sli_ring *pring; |
41415862 | 4478 | uint16_t cfg_value; |
dea3101e | 4479 | int i; |
dea3101e | 4480 | |
41415862 | 4481 | psli = &phba->sli; |
dea3101e | 4482 | |
41415862 JW |
4483 | /* Reset HBA */ |
4484 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4485 | "0325 Reset HBA Data: x%x x%x\n", |
4492b739 JS |
4486 | (phba->pport) ? phba->pport->port_state : 0, |
4487 | psli->sli_flag); | |
dea3101e JB |
4488 | |
4489 | /* perform board reset */ | |
4490 | phba->fc_eventTag = 0; | |
4d9ab994 | 4491 | phba->link_events = 0; |
4492b739 JS |
4492 | if (phba->pport) { |
4493 | phba->pport->fc_myDID = 0; | |
4494 | phba->pport->fc_prevDID = 0; | |
4495 | } | |
dea3101e | 4496 | |
41415862 JW |
4497 | /* Turn off parity checking and serr during the physical reset */ |
4498 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
4499 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
4500 | (cfg_value & | |
4501 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
4502 | ||
3772a991 JS |
4503 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
4504 | ||
41415862 JW |
4505 | /* Now toggle INITFF bit in the Host Control Register */ |
4506 | writel(HC_INITFF, phba->HCregaddr); | |
4507 | mdelay(1); | |
4508 | readl(phba->HCregaddr); /* flush */ | |
4509 | writel(0, phba->HCregaddr); | |
4510 | readl(phba->HCregaddr); /* flush */ | |
4511 | ||
4512 | /* Restore PCI cmd register */ | |
4513 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
4514 | |
4515 | /* Initialize relevant SLI info */ | |
41415862 | 4516 | for (i = 0; i < psli->num_rings; i++) { |
895427bd | 4517 | pring = &psli->sli3_ring[i]; |
dea3101e | 4518 | pring->flag = 0; |
7e56aa25 JS |
4519 | pring->sli.sli3.rspidx = 0; |
4520 | pring->sli.sli3.next_cmdidx = 0; | |
4521 | pring->sli.sli3.local_getidx = 0; | |
4522 | pring->sli.sli3.cmdidx = 0; | |
dea3101e JB |
4523 | pring->missbufcnt = 0; |
4524 | } | |
dea3101e | 4525 | |
2e0fef85 | 4526 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
4527 | return 0; |
4528 | } | |
4529 | ||
e59058c4 | 4530 | /** |
da0436e9 JS |
4531 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
4532 | * @phba: Pointer to HBA context object. | |
4533 | * | |
4534 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
4535 | * checking during resets the device. The caller is not required to hold | |
4536 | * any locks. | |
4537 | * | |
4538 | * This function returns 0 always. | |
4539 | **/ | |
4540 | int | |
4541 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
4542 | { | |
4543 | struct lpfc_sli *psli = &phba->sli; | |
4544 | uint16_t cfg_value; | |
0293635e | 4545 | int rc = 0; |
da0436e9 JS |
4546 | |
4547 | /* Reset HBA */ | |
4548 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
0293635e JS |
4549 | "0295 Reset HBA Data: x%x x%x x%x\n", |
4550 | phba->pport->port_state, psli->sli_flag, | |
4551 | phba->hba_flag); | |
da0436e9 JS |
4552 | |
4553 | /* perform board reset */ | |
4554 | phba->fc_eventTag = 0; | |
4d9ab994 | 4555 | phba->link_events = 0; |
da0436e9 JS |
4556 | phba->pport->fc_myDID = 0; |
4557 | phba->pport->fc_prevDID = 0; | |
4558 | ||
da0436e9 JS |
4559 | spin_lock_irq(&phba->hbalock); |
4560 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
4561 | phba->fcf.fcf_flag = 0; | |
da0436e9 JS |
4562 | spin_unlock_irq(&phba->hbalock); |
4563 | ||
0293635e JS |
4564 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
4565 | if (phba->hba_flag & HBA_FW_DUMP_OP) { | |
4566 | phba->hba_flag &= ~HBA_FW_DUMP_OP; | |
4567 | return rc; | |
4568 | } | |
4569 | ||
da0436e9 JS |
4570 | /* Now physically reset the device */ |
4571 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4572 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
4573 | |
4574 | /* Turn off parity checking and serr during the physical reset */ | |
4575 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
4576 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
4577 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
4578 | ||
88318816 | 4579 | /* Perform FCoE PCI function reset before freeing queue memory */ |
27b01b82 | 4580 | rc = lpfc_pci_function_reset(phba); |
da0436e9 | 4581 | |
be858b65 JS |
4582 | /* Restore PCI cmd register */ |
4583 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
4584 | ||
27b01b82 | 4585 | return rc; |
da0436e9 JS |
4586 | } |
4587 | ||
4588 | /** | |
4589 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
4590 | * @phba: Pointer to HBA context object. |
4591 | * | |
4592 | * This function is called in the SLI initialization code path to | |
4593 | * restart the HBA. The caller is not required to hold any lock. | |
4594 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
4595 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
4596 | * function to free any pending commands. The function enables | |
4597 | * POST only during the first initialization. The function returns zero. | |
4598 | * The function does not guarantee completion of MBX_RESTART mailbox | |
4599 | * command before the return of this function. | |
4600 | **/ | |
da0436e9 JS |
4601 | static int |
4602 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
4603 | { |
4604 | MAILBOX_t *mb; | |
4605 | struct lpfc_sli *psli; | |
41415862 JW |
4606 | volatile uint32_t word0; |
4607 | void __iomem *to_slim; | |
0d878419 | 4608 | uint32_t hba_aer_enabled; |
41415862 | 4609 | |
2e0fef85 | 4610 | spin_lock_irq(&phba->hbalock); |
41415862 | 4611 | |
0d878419 JS |
4612 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4613 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4614 | ||
41415862 JW |
4615 | psli = &phba->sli; |
4616 | ||
4617 | /* Restart HBA */ | |
4618 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4619 | "0337 Restart HBA Data: x%x x%x\n", |
4492b739 JS |
4620 | (phba->pport) ? phba->pport->port_state : 0, |
4621 | psli->sli_flag); | |
41415862 JW |
4622 | |
4623 | word0 = 0; | |
4624 | mb = (MAILBOX_t *) &word0; | |
4625 | mb->mbxCommand = MBX_RESTART; | |
4626 | mb->mbxHc = 1; | |
4627 | ||
9290831f JS |
4628 | lpfc_reset_barrier(phba); |
4629 | ||
41415862 JW |
4630 | to_slim = phba->MBslimaddr; |
4631 | writel(*(uint32_t *) mb, to_slim); | |
4632 | readl(to_slim); /* flush */ | |
4633 | ||
4634 | /* Only skip post after fc_ffinit is completed */ | |
4492b739 | 4635 | if (phba->pport && phba->pport->port_state) |
41415862 | 4636 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 4637 | else |
41415862 | 4638 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 4639 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
4640 | writel(*(uint32_t *) mb, to_slim); |
4641 | readl(to_slim); /* flush */ | |
dea3101e | 4642 | |
41415862 | 4643 | lpfc_sli_brdreset(phba); |
4492b739 JS |
4644 | if (phba->pport) |
4645 | phba->pport->stopped = 0; | |
2e0fef85 | 4646 | phba->link_state = LPFC_INIT_START; |
da0436e9 | 4647 | phba->hba_flag = 0; |
2e0fef85 | 4648 | spin_unlock_irq(&phba->hbalock); |
41415862 | 4649 | |
64ba8818 | 4650 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
c4d6204d | 4651 | psli->stats_start = ktime_get_seconds(); |
64ba8818 | 4652 | |
eaf15d5b JS |
4653 | /* Give the INITFF and Post time to settle. */ |
4654 | mdelay(100); | |
41415862 | 4655 | |
0d878419 JS |
4656 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4657 | if (hba_aer_enabled) | |
4658 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4659 | ||
41415862 | 4660 | lpfc_hba_down_post(phba); |
dea3101e JB |
4661 | |
4662 | return 0; | |
4663 | } | |
4664 | ||
da0436e9 JS |
4665 | /** |
4666 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
4667 | * @phba: Pointer to HBA context object. | |
4668 | * | |
4669 | * This function is called in the SLI initialization code path to restart | |
4670 | * a SLI4 HBA. The caller is not required to hold any lock. | |
4671 | * At the end of the function, it calls lpfc_hba_down_post function to | |
4672 | * free any pending commands. | |
4673 | **/ | |
4674 | static int | |
4675 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
4676 | { | |
4677 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 4678 | uint32_t hba_aer_enabled; |
27b01b82 | 4679 | int rc; |
da0436e9 JS |
4680 | |
4681 | /* Restart HBA */ | |
4682 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4683 | "0296 Restart HBA Data: x%x x%x\n", | |
4684 | phba->pport->port_state, psli->sli_flag); | |
4685 | ||
75baf696 JS |
4686 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4687 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4688 | ||
27b01b82 | 4689 | rc = lpfc_sli4_brdreset(phba); |
5a9eeff5 JS |
4690 | if (rc) |
4691 | return rc; | |
da0436e9 JS |
4692 | |
4693 | spin_lock_irq(&phba->hbalock); | |
4694 | phba->pport->stopped = 0; | |
4695 | phba->link_state = LPFC_INIT_START; | |
4696 | phba->hba_flag = 0; | |
4697 | spin_unlock_irq(&phba->hbalock); | |
4698 | ||
4699 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
c4d6204d | 4700 | psli->stats_start = ktime_get_seconds(); |
da0436e9 | 4701 | |
75baf696 JS |
4702 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4703 | if (hba_aer_enabled) | |
4704 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4705 | ||
da0436e9 | 4706 | lpfc_hba_down_post(phba); |
569dbe84 | 4707 | lpfc_sli4_queue_destroy(phba); |
da0436e9 | 4708 | |
27b01b82 | 4709 | return rc; |
da0436e9 JS |
4710 | } |
4711 | ||
4712 | /** | |
4713 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4714 | * @phba: Pointer to HBA context object. | |
4715 | * | |
4716 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4717 | * API jump table function pointer from the lpfc_hba struct. | |
4718 | **/ | |
4719 | int | |
4720 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4721 | { | |
4722 | return phba->lpfc_sli_brdrestart(phba); | |
4723 | } | |
4724 | ||
e59058c4 | 4725 | /** |
3621a710 | 4726 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4727 | * @phba: Pointer to HBA context object. |
4728 | * | |
4729 | * This function is called after a HBA restart to wait for successful | |
4730 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4731 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4732 | * iteration, the function will restart the HBA again. The function returns | |
4733 | * zero if HBA successfully restarted else returns negative error code. | |
4734 | **/ | |
4492b739 | 4735 | int |
dea3101e JB |
4736 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
4737 | { | |
4738 | uint32_t status, i = 0; | |
4739 | ||
4740 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4741 | if (lpfc_readl(phba->HSregaddr, &status)) |
4742 | return -EIO; | |
dea3101e JB |
4743 | |
4744 | /* Check status register to see what current state is */ | |
4745 | i = 0; | |
4746 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4747 | ||
dcf2a4e0 JS |
4748 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4749 | * retries, then every 1 sec for 50 retires for a total of | |
4750 | * ~60 seconds before reset the board again and check every | |
4751 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4752 | * board ready is required by the Falcon FIPS zeroization | |
4753 | * complete, and any reset the board in between shall cause | |
4754 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4755 | */ |
dcf2a4e0 | 4756 | if (i++ >= 200) { |
dea3101e JB |
4757 | /* Adapter failed to init, timeout, status reg |
4758 | <status> */ | |
ed957684 | 4759 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4760 | "0436 Adapter failed to init, " |
09372820 JS |
4761 | "timeout, status reg x%x, " |
4762 | "FW Data: A8 x%x AC x%x\n", status, | |
4763 | readl(phba->MBslimaddr + 0xa8), | |
4764 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4765 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4766 | return -ETIMEDOUT; |
4767 | } | |
4768 | ||
4769 | /* Check to see if any errors occurred during init */ | |
4770 | if (status & HS_FFERM) { | |
4771 | /* ERROR: During chipset initialization */ | |
4772 | /* Adapter failed to init, chipset, status reg | |
4773 | <status> */ | |
ed957684 | 4774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4775 | "0437 Adapter failed to init, " |
09372820 JS |
4776 | "chipset, status reg x%x, " |
4777 | "FW Data: A8 x%x AC x%x\n", status, | |
4778 | readl(phba->MBslimaddr + 0xa8), | |
4779 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4780 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4781 | return -EIO; |
4782 | } | |
4783 | ||
dcf2a4e0 | 4784 | if (i <= 10) |
dea3101e | 4785 | msleep(10); |
dcf2a4e0 JS |
4786 | else if (i <= 100) |
4787 | msleep(100); | |
4788 | else | |
4789 | msleep(1000); | |
dea3101e | 4790 | |
dcf2a4e0 JS |
4791 | if (i == 150) { |
4792 | /* Do post */ | |
92d7f7b0 | 4793 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4794 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4795 | } |
4796 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4797 | if (lpfc_readl(phba->HSregaddr, &status)) |
4798 | return -EIO; | |
dea3101e JB |
4799 | } |
4800 | ||
4801 | /* Check to see if any errors occurred during init */ | |
4802 | if (status & HS_FFERM) { | |
4803 | /* ERROR: During chipset initialization */ | |
4804 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4806 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4807 | "status reg x%x, " |
4808 | "FW Data: A8 x%x AC x%x\n", status, | |
4809 | readl(phba->MBslimaddr + 0xa8), | |
4810 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4811 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4812 | return -EIO; |
4813 | } | |
4814 | ||
4815 | /* Clear all interrupt enable conditions */ | |
4816 | writel(0, phba->HCregaddr); | |
4817 | readl(phba->HCregaddr); /* flush */ | |
4818 | ||
4819 | /* setup host attn register */ | |
4820 | writel(0xffffffff, phba->HAregaddr); | |
4821 | readl(phba->HAregaddr); /* flush */ | |
4822 | return 0; | |
4823 | } | |
4824 | ||
e59058c4 | 4825 | /** |
3621a710 | 4826 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4827 | * |
4828 | * This function calculates and returns the number of HBQs required to be | |
4829 | * configured. | |
4830 | **/ | |
78b2d852 | 4831 | int |
ed957684 JS |
4832 | lpfc_sli_hbq_count(void) |
4833 | { | |
92d7f7b0 | 4834 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4835 | } |
4836 | ||
e59058c4 | 4837 | /** |
3621a710 | 4838 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4839 | * |
4840 | * This function adds the number of hbq entries in every HBQ to get | |
4841 | * the total number of hbq entries required for the HBA and returns | |
4842 | * the total count. | |
4843 | **/ | |
ed957684 JS |
4844 | static int |
4845 | lpfc_sli_hbq_entry_count(void) | |
4846 | { | |
4847 | int hbq_count = lpfc_sli_hbq_count(); | |
4848 | int count = 0; | |
4849 | int i; | |
4850 | ||
4851 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4852 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4853 | return count; |
4854 | } | |
4855 | ||
e59058c4 | 4856 | /** |
3621a710 | 4857 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4858 | * |
4859 | * This function calculates amount of memory required for all hbq entries | |
4860 | * to be configured and returns the total memory required. | |
4861 | **/ | |
dea3101e | 4862 | int |
ed957684 JS |
4863 | lpfc_sli_hbq_size(void) |
4864 | { | |
4865 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4866 | } | |
4867 | ||
e59058c4 | 4868 | /** |
3621a710 | 4869 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4870 | * @phba: Pointer to HBA context object. |
4871 | * | |
4872 | * This function is called during the SLI initialization to configure | |
4873 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4874 | * required to hold any locks. This function will return zero if successful | |
4875 | * else it will return negative error code. | |
4876 | **/ | |
ed957684 JS |
4877 | static int |
4878 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4879 | { | |
4880 | int hbq_count = lpfc_sli_hbq_count(); | |
4881 | LPFC_MBOXQ_t *pmb; | |
4882 | MAILBOX_t *pmbox; | |
4883 | uint32_t hbqno; | |
4884 | uint32_t hbq_entry_index; | |
ed957684 | 4885 | |
92d7f7b0 JS |
4886 | /* Get a Mailbox buffer to setup mailbox |
4887 | * commands for HBA initialization | |
4888 | */ | |
ed957684 JS |
4889 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4890 | ||
4891 | if (!pmb) | |
4892 | return -ENOMEM; | |
4893 | ||
04c68496 | 4894 | pmbox = &pmb->u.mb; |
ed957684 JS |
4895 | |
4896 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4897 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4898 | phba->hbq_in_use = 1; |
ed957684 JS |
4899 | |
4900 | hbq_entry_index = 0; | |
4901 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4902 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4903 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4904 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4905 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4906 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4907 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4908 | hbq_entry_index, pmb); | |
ed957684 JS |
4909 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4910 | ||
4911 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4912 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4913 | mbxStatus <status>, ring <num> */ | |
4914 | ||
4915 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4916 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4917 | "1805 Adapter failed to init. " |
ed957684 | 4918 | "Data: x%x x%x x%x\n", |
e8b62011 | 4919 | pmbox->mbxCommand, |
ed957684 JS |
4920 | pmbox->mbxStatus, hbqno); |
4921 | ||
4922 | phba->link_state = LPFC_HBA_ERROR; | |
4923 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4924 | return -ENXIO; |
ed957684 JS |
4925 | } |
4926 | } | |
4927 | phba->hbq_count = hbq_count; | |
4928 | ||
ed957684 JS |
4929 | mempool_free(pmb, phba->mbox_mem_pool); |
4930 | ||
92d7f7b0 | 4931 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4932 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4933 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4934 | return 0; |
4935 | } | |
4936 | ||
4f774513 JS |
4937 | /** |
4938 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4939 | * @phba: Pointer to HBA context object. | |
4940 | * | |
4941 | * This function is called during the SLI initialization to configure | |
4942 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4943 | * required to hold any locks. This function will return zero if successful | |
4944 | * else it will return negative error code. | |
4945 | **/ | |
4946 | static int | |
4947 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4948 | { | |
4949 | phba->hbq_in_use = 1; | |
895427bd JS |
4950 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
4951 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; | |
4f774513 | 4952 | phba->hbq_count = 1; |
895427bd | 4953 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
4f774513 | 4954 | /* Initially populate or replenish the HBQs */ |
4f774513 JS |
4955 | return 0; |
4956 | } | |
4957 | ||
e59058c4 | 4958 | /** |
3621a710 | 4959 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4960 | * @phba: Pointer to HBA context object. |
4961 | * @sli_mode: sli mode - 2/3 | |
4962 | * | |
183b8021 | 4963 | * This function is called by the sli initialization code path |
e59058c4 JS |
4964 | * to issue config_port mailbox command. This function restarts the |
4965 | * HBA firmware and issues a config_port mailbox command to configure | |
4966 | * the SLI interface in the sli mode specified by sli_mode | |
4967 | * variable. The caller is not required to hold any locks. | |
4968 | * The function returns 0 if successful, else returns negative error | |
4969 | * code. | |
4970 | **/ | |
9399627f JS |
4971 | int |
4972 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4973 | { |
4974 | LPFC_MBOXQ_t *pmb; | |
4975 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4976 | ||
4977 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4978 | if (!pmb) { | |
2e0fef85 | 4979 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4980 | return -ENOMEM; |
4981 | } | |
4982 | ||
ed957684 | 4983 | phba->sli_rev = sli_mode; |
dea3101e | 4984 | while (resetcount < 2 && !done) { |
2e0fef85 | 4985 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4986 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4987 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4988 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4989 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4990 | rc = lpfc_sli_chipset_init(phba); |
4991 | if (rc) | |
4992 | break; | |
4993 | ||
2e0fef85 | 4994 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4995 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4996 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4997 | resetcount++; |
4998 | ||
ed957684 JS |
4999 | /* Call pre CONFIG_PORT mailbox command initialization. A |
5000 | * value of 0 means the call was successful. Any other | |
5001 | * nonzero value is a failure, but if ERESTART is returned, | |
5002 | * the driver may reset the HBA and try again. | |
5003 | */ | |
dea3101e JB |
5004 | rc = lpfc_config_port_prep(phba); |
5005 | if (rc == -ERESTART) { | |
ed957684 | 5006 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 5007 | continue; |
34b02dcd | 5008 | } else if (rc) |
dea3101e | 5009 | break; |
6d368e53 | 5010 | |
2e0fef85 | 5011 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
5012 | lpfc_config_port(phba, pmb); |
5013 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
5014 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
5015 | LPFC_SLI3_HBQ_ENABLED | | |
5016 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
5017 | LPFC_SLI3_BG_ENABLED | |
5018 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 5019 | if (rc != MBX_SUCCESS) { |
dea3101e | 5020 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 5021 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 5022 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 5023 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 5024 | spin_lock_irq(&phba->hbalock); |
04c68496 | 5025 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
5026 | spin_unlock_irq(&phba->hbalock); |
5027 | rc = -ENXIO; | |
04c68496 JS |
5028 | } else { |
5029 | /* Allow asynchronous mailbox command to go through */ | |
5030 | spin_lock_irq(&phba->hbalock); | |
5031 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5032 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 5033 | done = 1; |
cb69f7de JS |
5034 | |
5035 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
5036 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
5037 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5038 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 5039 | } |
dea3101e | 5040 | } |
ed957684 JS |
5041 | if (!done) { |
5042 | rc = -EINVAL; | |
5043 | goto do_prep_failed; | |
5044 | } | |
04c68496 JS |
5045 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
5046 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
5047 | rc = -ENXIO; |
5048 | goto do_prep_failed; | |
5049 | } | |
04c68496 | 5050 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 5051 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
5052 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
5053 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
5054 | phba->max_vpi : phba->max_vports; | |
5055 | ||
34b02dcd JS |
5056 | } else |
5057 | phba->max_vpi = 0; | |
bc73905a JS |
5058 | phba->fips_level = 0; |
5059 | phba->fips_spec_rev = 0; | |
5060 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 5061 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
5062 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
5063 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
5064 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5065 | "2850 Security Crypto Active. FIPS x%d " | |
5066 | "(Spec Rev: x%d)", | |
5067 | phba->fips_level, phba->fips_spec_rev); | |
5068 | } | |
5069 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
5070 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5071 | "2856 Config Port Security Crypto " | |
5072 | "Error: x%x ", | |
5073 | pmb->u.mb.un.varCfgPort.sec_err); | |
5074 | } | |
04c68496 | 5075 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 5076 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 5077 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 5078 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
5079 | |
5080 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
5081 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 | 5082 | |
f44ac12f JS |
5083 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
5084 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { | |
5085 | phba->cfg_enable_bg = 0; | |
5086 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; | |
e2a0a9d6 JS |
5087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
5088 | "0443 Adapter did not grant " | |
5089 | "BlockGuard\n"); | |
f44ac12f | 5090 | } |
e2a0a9d6 | 5091 | } |
34b02dcd | 5092 | } else { |
8f34f4ce | 5093 | phba->hbq_get = NULL; |
34b02dcd | 5094 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 5095 | phba->max_vpi = 0; |
ed957684 | 5096 | } |
92d7f7b0 | 5097 | do_prep_failed: |
ed957684 JS |
5098 | mempool_free(pmb, phba->mbox_mem_pool); |
5099 | return rc; | |
5100 | } | |
5101 | ||
e59058c4 JS |
5102 | |
5103 | /** | |
183b8021 | 5104 | * lpfc_sli_hba_setup - SLI initialization function |
e59058c4 JS |
5105 | * @phba: Pointer to HBA context object. |
5106 | * | |
183b8021 MY |
5107 | * This function is the main SLI initialization function. This function |
5108 | * is called by the HBA initialization code, HBA reset code and HBA | |
e59058c4 JS |
5109 | * error attention handler code. Caller is not required to hold any |
5110 | * locks. This function issues config_port mailbox command to configure | |
5111 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
5112 | * calls the config_port_post function to issue init_link mailbox | |
5113 | * command and to start the discovery. The function will return zero | |
5114 | * if successful, else it will return negative error code. | |
5115 | **/ | |
ed957684 JS |
5116 | int |
5117 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
5118 | { | |
5119 | uint32_t rc; | |
6d368e53 JS |
5120 | int mode = 3, i; |
5121 | int longs; | |
ed957684 | 5122 | |
12247e81 | 5123 | switch (phba->cfg_sli_mode) { |
ed957684 | 5124 | case 2: |
78b2d852 | 5125 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 5126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
12247e81 | 5127 | "1824 NPIV enabled: Override sli_mode " |
92d7f7b0 | 5128 | "parameter (%d) to auto (0).\n", |
12247e81 | 5129 | phba->cfg_sli_mode); |
92d7f7b0 JS |
5130 | break; |
5131 | } | |
ed957684 JS |
5132 | mode = 2; |
5133 | break; | |
5134 | case 0: | |
5135 | case 3: | |
5136 | break; | |
5137 | default: | |
92d7f7b0 | 5138 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
12247e81 JS |
5139 | "1819 Unrecognized sli_mode parameter: %d.\n", |
5140 | phba->cfg_sli_mode); | |
ed957684 JS |
5141 | |
5142 | break; | |
5143 | } | |
b5c53958 | 5144 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
ed957684 | 5145 | |
9399627f JS |
5146 | rc = lpfc_sli_config_port(phba, mode); |
5147 | ||
12247e81 | 5148 | if (rc && phba->cfg_sli_mode == 3) |
92d7f7b0 | 5149 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
5150 | "1820 Unable to select SLI-3. " |
5151 | "Not supported by adapter.\n"); | |
ed957684 | 5152 | if (rc && mode != 2) |
9399627f | 5153 | rc = lpfc_sli_config_port(phba, 2); |
4597663f JS |
5154 | else if (rc && mode == 2) |
5155 | rc = lpfc_sli_config_port(phba, 3); | |
ed957684 | 5156 | if (rc) |
dea3101e JB |
5157 | goto lpfc_sli_hba_setup_error; |
5158 | ||
0d878419 JS |
5159 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
5160 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
5161 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
5162 | if (!rc) { | |
5163 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5164 | "2709 This device supports " | |
5165 | "Advanced Error Reporting (AER)\n"); | |
5166 | spin_lock_irq(&phba->hbalock); | |
5167 | phba->hba_flag |= HBA_AER_ENABLED; | |
5168 | spin_unlock_irq(&phba->hbalock); | |
5169 | } else { | |
5170 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5171 | "2708 This device does not support " | |
b069d7eb JS |
5172 | "Advanced Error Reporting (AER): %d\n", |
5173 | rc); | |
0d878419 JS |
5174 | phba->cfg_aer_support = 0; |
5175 | } | |
5176 | } | |
5177 | ||
ed957684 JS |
5178 | if (phba->sli_rev == 3) { |
5179 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
5180 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
5181 | } else { |
5182 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
5183 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 5184 | phba->sli3_options = 0; |
ed957684 JS |
5185 | } |
5186 | ||
5187 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
5188 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
5189 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 5190 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
5191 | |
5192 | if (rc) | |
5193 | goto lpfc_sli_hba_setup_error; | |
5194 | ||
6d368e53 JS |
5195 | /* Initialize VPIs. */ |
5196 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
5197 | /* | |
5198 | * The VPI bitmask and physical ID array are allocated | |
5199 | * and initialized once only - at driver load. A port | |
5200 | * reset doesn't need to reinitialize this memory. | |
5201 | */ | |
5202 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
5203 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
6396bb22 KC |
5204 | phba->vpi_bmask = kcalloc(longs, |
5205 | sizeof(unsigned long), | |
6d368e53 JS |
5206 | GFP_KERNEL); |
5207 | if (!phba->vpi_bmask) { | |
5208 | rc = -ENOMEM; | |
5209 | goto lpfc_sli_hba_setup_error; | |
5210 | } | |
5211 | ||
6396bb22 KC |
5212 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
5213 | sizeof(uint16_t), | |
5214 | GFP_KERNEL); | |
6d368e53 JS |
5215 | if (!phba->vpi_ids) { |
5216 | kfree(phba->vpi_bmask); | |
5217 | rc = -ENOMEM; | |
5218 | goto lpfc_sli_hba_setup_error; | |
5219 | } | |
5220 | for (i = 0; i < phba->max_vpi; i++) | |
5221 | phba->vpi_ids[i] = i; | |
5222 | } | |
5223 | } | |
5224 | ||
9399627f | 5225 | /* Init HBQs */ |
ed957684 JS |
5226 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
5227 | rc = lpfc_sli_hbq_setup(phba); | |
5228 | if (rc) | |
5229 | goto lpfc_sli_hba_setup_error; | |
5230 | } | |
04c68496 | 5231 | spin_lock_irq(&phba->hbalock); |
dea3101e | 5232 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 5233 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5234 | |
5235 | rc = lpfc_config_port_post(phba); | |
5236 | if (rc) | |
5237 | goto lpfc_sli_hba_setup_error; | |
5238 | ||
ed957684 JS |
5239 | return rc; |
5240 | ||
92d7f7b0 | 5241 | lpfc_sli_hba_setup_error: |
2e0fef85 | 5242 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 5243 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 5244 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
5245 | return rc; |
5246 | } | |
5247 | ||
e59058c4 | 5248 | /** |
da0436e9 JS |
5249 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
5250 | * @phba: Pointer to HBA context object. | |
5251 | * @mboxq: mailbox pointer. | |
5252 | * This function issue a dump mailbox command to read config region | |
5253 | * 23 and parse the records in the region and populate driver | |
5254 | * data structure. | |
e59058c4 | 5255 | **/ |
da0436e9 | 5256 | static int |
ff78d8f9 | 5257 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 5258 | { |
ff78d8f9 | 5259 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
5260 | struct lpfc_dmabuf *mp; |
5261 | struct lpfc_mqe *mqe; | |
5262 | uint32_t data_length; | |
5263 | int rc; | |
dea3101e | 5264 | |
da0436e9 JS |
5265 | /* Program the default value of vlan_id and fc_map */ |
5266 | phba->valid_vlan = 0; | |
5267 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
5268 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
5269 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 5270 | |
ff78d8f9 JS |
5271 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5272 | if (!mboxq) | |
da0436e9 JS |
5273 | return -ENOMEM; |
5274 | ||
ff78d8f9 JS |
5275 | mqe = &mboxq->u.mqe; |
5276 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
5277 | rc = -ENOMEM; | |
5278 | goto out_free_mboxq; | |
5279 | } | |
5280 | ||
3e1f0718 | 5281 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
da0436e9 JS |
5282 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
5283 | ||
5284 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5285 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
5286 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
5287 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
5288 | "CQ: x%x x%x x%x x%x\n", | |
5289 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5290 | bf_get(lpfc_mqe_command, mqe), | |
5291 | bf_get(lpfc_mqe_status, mqe), | |
5292 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
5293 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
5294 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
5295 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
5296 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
5297 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
5298 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
5299 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
5300 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
5301 | mboxq->mcqe.word0, | |
5302 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
5303 | mboxq->mcqe.trailer); | |
5304 | ||
5305 | if (rc) { | |
5306 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
5307 | kfree(mp); | |
ff78d8f9 JS |
5308 | rc = -EIO; |
5309 | goto out_free_mboxq; | |
da0436e9 JS |
5310 | } |
5311 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 5312 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
5313 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
5314 | kfree(mp); | |
ff78d8f9 JS |
5315 | rc = -EIO; |
5316 | goto out_free_mboxq; | |
d11e31dd | 5317 | } |
dea3101e | 5318 | |
da0436e9 JS |
5319 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
5320 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
5321 | kfree(mp); | |
ff78d8f9 JS |
5322 | rc = 0; |
5323 | ||
5324 | out_free_mboxq: | |
5325 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5326 | return rc; | |
da0436e9 | 5327 | } |
e59058c4 JS |
5328 | |
5329 | /** | |
da0436e9 JS |
5330 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
5331 | * @phba: pointer to lpfc hba data structure. | |
5332 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
5333 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
5334 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
5335 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 5336 | * |
da0436e9 JS |
5337 | * This routine executes a READ_REV SLI4 mailbox command. In |
5338 | * addition, this routine gets the port vpd data. | |
5339 | * | |
5340 | * Return codes | |
af901ca1 | 5341 | * 0 - successful |
d439d286 | 5342 | * -ENOMEM - could not allocated memory. |
e59058c4 | 5343 | **/ |
da0436e9 JS |
5344 | static int |
5345 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
5346 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 5347 | { |
da0436e9 JS |
5348 | int rc = 0; |
5349 | uint32_t dma_size; | |
5350 | struct lpfc_dmabuf *dmabuf; | |
5351 | struct lpfc_mqe *mqe; | |
dea3101e | 5352 | |
da0436e9 JS |
5353 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
5354 | if (!dmabuf) | |
5355 | return -ENOMEM; | |
5356 | ||
5357 | /* | |
5358 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
5359 | * mailbox command. | |
a257bf90 | 5360 | */ |
da0436e9 | 5361 | dma_size = *vpd_size; |
1aee383d JP |
5362 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
5363 | &dmabuf->phys, GFP_KERNEL); | |
da0436e9 JS |
5364 | if (!dmabuf->virt) { |
5365 | kfree(dmabuf); | |
5366 | return -ENOMEM; | |
a257bf90 JS |
5367 | } |
5368 | ||
da0436e9 JS |
5369 | /* |
5370 | * The SLI4 implementation of READ_REV conflicts at word1, | |
5371 | * bits 31:16 and SLI4 adds vpd functionality not present | |
5372 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 5373 | */ |
da0436e9 JS |
5374 | lpfc_read_rev(phba, mboxq); |
5375 | mqe = &mboxq->u.mqe; | |
5376 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
5377 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
5378 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
5379 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
5380 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
5381 | ||
5382 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5383 | if (rc) { | |
5384 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
5385 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 5386 | kfree(dmabuf); |
da0436e9 JS |
5387 | return -EIO; |
5388 | } | |
1dcb58e5 | 5389 | |
da0436e9 JS |
5390 | /* |
5391 | * The available vpd length cannot be bigger than the | |
5392 | * DMA buffer passed to the port. Catch the less than | |
5393 | * case and update the caller's size. | |
5394 | */ | |
5395 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
5396 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 5397 | |
d7c47992 JS |
5398 | memcpy(vpd, dmabuf->virt, *vpd_size); |
5399 | ||
da0436e9 JS |
5400 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
5401 | dmabuf->virt, dmabuf->phys); | |
5402 | kfree(dmabuf); | |
5403 | return 0; | |
dea3101e JB |
5404 | } |
5405 | ||
cd1c8301 JS |
5406 | /** |
5407 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
5408 | * @phba: pointer to lpfc hba data structure. | |
5409 | * | |
5410 | * This routine retrieves SLI4 device physical port name this PCI function | |
5411 | * is attached to. | |
5412 | * | |
5413 | * Return codes | |
4907cb7b | 5414 | * 0 - successful |
cd1c8301 JS |
5415 | * otherwise - failed to retrieve physical port name |
5416 | **/ | |
5417 | static int | |
5418 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
5419 | { | |
5420 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
5421 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
5422 | struct lpfc_controller_attribute *cntl_attr; | |
5423 | struct lpfc_mbx_get_port_name *get_port_name; | |
5424 | void *virtaddr = NULL; | |
5425 | uint32_t alloclen, reqlen; | |
5426 | uint32_t shdr_status, shdr_add_status; | |
5427 | union lpfc_sli4_cfg_shdr *shdr; | |
5428 | char cport_name = 0; | |
5429 | int rc; | |
5430 | ||
5431 | /* We assume nothing at this point */ | |
5432 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
5433 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
5434 | ||
5435 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5436 | if (!mboxq) | |
5437 | return -ENOMEM; | |
cd1c8301 | 5438 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
5439 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
5440 | lpfc_sli4_read_config(phba); | |
5441 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
5442 | goto retrieve_ppname; | |
cd1c8301 JS |
5443 | |
5444 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
5445 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
5446 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5447 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
5448 | LPFC_SLI4_MBX_NEMBED); | |
5449 | if (alloclen < reqlen) { | |
5450 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5451 | "3084 Allocated DMA memory size (%d) is " | |
5452 | "less than the requested DMA memory size " | |
5453 | "(%d)\n", alloclen, reqlen); | |
5454 | rc = -ENOMEM; | |
5455 | goto out_free_mboxq; | |
5456 | } | |
5457 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5458 | virtaddr = mboxq->sge_array->addr[0]; | |
5459 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
5460 | shdr = &mbx_cntl_attr->cfg_shdr; | |
5461 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5462 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5463 | if (shdr_status || shdr_add_status || rc) { | |
5464 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
5465 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
5466 | "rc:x%x, status:x%x, add_status:x%x\n", | |
5467 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5468 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
5469 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
5470 | rc, shdr_status, shdr_add_status); | |
5471 | rc = -ENXIO; | |
5472 | goto out_free_mboxq; | |
5473 | } | |
5474 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
5475 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
5476 | phba->sli4_hba.lnk_info.lnk_tp = | |
5477 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
5478 | phba->sli4_hba.lnk_info.lnk_no = | |
5479 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
5480 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5481 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
5482 | phba->sli4_hba.lnk_info.lnk_tp, | |
5483 | phba->sli4_hba.lnk_info.lnk_no); | |
5484 | ||
5485 | retrieve_ppname: | |
5486 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5487 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
5488 | sizeof(struct lpfc_mbx_get_port_name) - | |
5489 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
5490 | LPFC_SLI4_MBX_EMBED); | |
5491 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
5492 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
5493 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
5494 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
5495 | phba->sli4_hba.lnk_info.lnk_tp); | |
5496 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5497 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
5498 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
5499 | if (shdr_status || shdr_add_status || rc) { | |
5500 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
5501 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
5502 | "rc:x%x, status:x%x, add_status:x%x\n", | |
5503 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5504 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
5505 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
5506 | rc, shdr_status, shdr_add_status); | |
5507 | rc = -ENXIO; | |
5508 | goto out_free_mboxq; | |
5509 | } | |
5510 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
5511 | case LPFC_LINK_NUMBER_0: | |
5512 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
5513 | &get_port_name->u.response); | |
5514 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5515 | break; | |
5516 | case LPFC_LINK_NUMBER_1: | |
5517 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
5518 | &get_port_name->u.response); | |
5519 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5520 | break; | |
5521 | case LPFC_LINK_NUMBER_2: | |
5522 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
5523 | &get_port_name->u.response); | |
5524 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5525 | break; | |
5526 | case LPFC_LINK_NUMBER_3: | |
5527 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
5528 | &get_port_name->u.response); | |
5529 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
5530 | break; | |
5531 | default: | |
5532 | break; | |
5533 | } | |
5534 | ||
5535 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
5536 | phba->Port[0] = cport_name; | |
5537 | phba->Port[1] = '\0'; | |
5538 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5539 | "3091 SLI get port name: %s\n", phba->Port); | |
5540 | } | |
5541 | ||
5542 | out_free_mboxq: | |
5543 | if (rc != MBX_TIMEOUT) { | |
5544 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
5545 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
5546 | else | |
5547 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5548 | } | |
5549 | return rc; | |
5550 | } | |
5551 | ||
e59058c4 | 5552 | /** |
da0436e9 JS |
5553 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
5554 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 5555 | * |
da0436e9 JS |
5556 | * This routine is called to explicitly arm the SLI4 device's completion and |
5557 | * event queues | |
5558 | **/ | |
5559 | static void | |
5560 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
5561 | { | |
895427bd | 5562 | int qidx; |
b71413dd | 5563 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
da0436e9 | 5564 | |
b71413dd JS |
5565 | sli4_hba->sli4_cq_release(sli4_hba->mbx_cq, LPFC_QUEUE_REARM); |
5566 | sli4_hba->sli4_cq_release(sli4_hba->els_cq, LPFC_QUEUE_REARM); | |
5567 | if (sli4_hba->nvmels_cq) | |
5568 | sli4_hba->sli4_cq_release(sli4_hba->nvmels_cq, | |
895427bd JS |
5569 | LPFC_QUEUE_REARM); |
5570 | ||
b71413dd | 5571 | if (sli4_hba->fcp_cq) |
895427bd | 5572 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
b71413dd | 5573 | sli4_hba->sli4_cq_release(sli4_hba->fcp_cq[qidx], |
895427bd JS |
5574 | LPFC_QUEUE_REARM); |
5575 | ||
b71413dd | 5576 | if (sli4_hba->nvme_cq) |
895427bd | 5577 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
b71413dd | 5578 | sli4_hba->sli4_cq_release(sli4_hba->nvme_cq[qidx], |
895427bd | 5579 | LPFC_QUEUE_REARM); |
1ba981fd | 5580 | |
f38fa0bb | 5581 | if (phba->cfg_fof) |
b71413dd | 5582 | sli4_hba->sli4_cq_release(sli4_hba->oas_cq, LPFC_QUEUE_REARM); |
1ba981fd | 5583 | |
b71413dd | 5584 | if (sli4_hba->hba_eq) |
895427bd | 5585 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
b71413dd JS |
5586 | sli4_hba->sli4_eq_release(sli4_hba->hba_eq[qidx], |
5587 | LPFC_QUEUE_REARM); | |
1ba981fd | 5588 | |
2d7dbc4c JS |
5589 | if (phba->nvmet_support) { |
5590 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { | |
b71413dd JS |
5591 | sli4_hba->sli4_cq_release( |
5592 | sli4_hba->nvmet_cqset[qidx], | |
2d7dbc4c JS |
5593 | LPFC_QUEUE_REARM); |
5594 | } | |
2e90f4b5 | 5595 | } |
1ba981fd JS |
5596 | |
5597 | if (phba->cfg_fof) | |
b71413dd | 5598 | sli4_hba->sli4_eq_release(sli4_hba->fof_eq, LPFC_QUEUE_REARM); |
da0436e9 JS |
5599 | } |
5600 | ||
6d368e53 JS |
5601 | /** |
5602 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
5603 | * @phba: Pointer to HBA context object. | |
5604 | * @type: The resource extent type. | |
b76f2dc9 JS |
5605 | * @extnt_count: buffer to hold port available extent count. |
5606 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 5607 | * |
b76f2dc9 JS |
5608 | * This function calls the port and retrievs the number of available |
5609 | * extents and their size for a particular extent type. | |
5610 | * | |
5611 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 5612 | **/ |
b76f2dc9 | 5613 | int |
6d368e53 JS |
5614 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
5615 | uint16_t *extnt_count, uint16_t *extnt_size) | |
5616 | { | |
5617 | int rc = 0; | |
5618 | uint32_t length; | |
5619 | uint32_t mbox_tmo; | |
5620 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
5621 | LPFC_MBOXQ_t *mbox; | |
5622 | ||
5623 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5624 | if (!mbox) | |
5625 | return -ENOMEM; | |
5626 | ||
5627 | /* Find out how many extents are available for this resource type */ | |
5628 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
5629 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5630 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5631 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
5632 | length, LPFC_SLI4_MBX_EMBED); | |
5633 | ||
5634 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
5635 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5636 | LPFC_SLI4_MBX_EMBED); | |
5637 | if (unlikely(rc)) { | |
5638 | rc = -EIO; | |
5639 | goto err_exit; | |
5640 | } | |
5641 | ||
5642 | if (!phba->sli4_hba.intr_enable) | |
5643 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5644 | else { | |
a183a15f | 5645 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5646 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5647 | } | |
5648 | if (unlikely(rc)) { | |
5649 | rc = -EIO; | |
5650 | goto err_exit; | |
5651 | } | |
5652 | ||
5653 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
5654 | if (bf_get(lpfc_mbox_hdr_status, | |
5655 | &rsrc_info->header.cfg_shdr.response)) { | |
5656 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5657 | "2930 Failed to get resource extents " | |
5658 | "Status 0x%x Add'l Status 0x%x\n", | |
5659 | bf_get(lpfc_mbox_hdr_status, | |
5660 | &rsrc_info->header.cfg_shdr.response), | |
5661 | bf_get(lpfc_mbox_hdr_add_status, | |
5662 | &rsrc_info->header.cfg_shdr.response)); | |
5663 | rc = -EIO; | |
5664 | goto err_exit; | |
5665 | } | |
5666 | ||
5667 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
5668 | &rsrc_info->u.rsp); | |
5669 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
5670 | &rsrc_info->u.rsp); | |
8a9d2e80 JS |
5671 | |
5672 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5673 | "3162 Retrieved extents type-%d from port: count:%d, " | |
5674 | "size:%d\n", type, *extnt_count, *extnt_size); | |
5675 | ||
5676 | err_exit: | |
6d368e53 JS |
5677 | mempool_free(mbox, phba->mbox_mem_pool); |
5678 | return rc; | |
5679 | } | |
5680 | ||
5681 | /** | |
5682 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
5683 | * @phba: Pointer to HBA context object. | |
5684 | * @type: The extent type to check. | |
5685 | * | |
5686 | * This function reads the current available extents from the port and checks | |
5687 | * if the extent count or extent size has changed since the last access. | |
5688 | * Callers use this routine post port reset to understand if there is a | |
5689 | * extent reprovisioning requirement. | |
5690 | * | |
5691 | * Returns: | |
5692 | * -Error: error indicates problem. | |
5693 | * 1: Extent count or size has changed. | |
5694 | * 0: No changes. | |
5695 | **/ | |
5696 | static int | |
5697 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
5698 | { | |
5699 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
5700 | uint16_t size_diff, rsrc_ext_size; | |
5701 | int rc = 0; | |
5702 | struct lpfc_rsrc_blks *rsrc_entry; | |
5703 | struct list_head *rsrc_blk_list = NULL; | |
5704 | ||
5705 | size_diff = 0; | |
5706 | curr_ext_cnt = 0; | |
5707 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5708 | &rsrc_ext_cnt, | |
5709 | &rsrc_ext_size); | |
5710 | if (unlikely(rc)) | |
5711 | return -EIO; | |
5712 | ||
5713 | switch (type) { | |
5714 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5715 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5716 | break; | |
5717 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5718 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
5719 | break; | |
5720 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5721 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5722 | break; | |
5723 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5724 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5725 | break; | |
5726 | default: | |
5727 | break; | |
5728 | } | |
5729 | ||
5730 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5731 | curr_ext_cnt++; | |
5732 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5733 | size_diff++; | |
5734 | } | |
5735 | ||
5736 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5737 | rc = 1; | |
5738 | ||
5739 | return rc; | |
5740 | } | |
5741 | ||
5742 | /** | |
5743 | * lpfc_sli4_cfg_post_extnts - | |
5744 | * @phba: Pointer to HBA context object. | |
5745 | * @extnt_cnt - number of available extents. | |
5746 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5747 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5748 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5749 | * | |
5750 | * This function executes the extents allocation request. It also | |
5751 | * takes care of the amount of memory needed to allocate or get the | |
5752 | * allocated extents. It is the caller's responsibility to evaluate | |
5753 | * the response. | |
5754 | * | |
5755 | * Returns: | |
5756 | * -Error: Error value describes the condition found. | |
5757 | * 0: if successful | |
5758 | **/ | |
5759 | static int | |
8a9d2e80 | 5760 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
6d368e53 JS |
5761 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
5762 | { | |
5763 | int rc = 0; | |
5764 | uint32_t req_len; | |
5765 | uint32_t emb_len; | |
5766 | uint32_t alloc_len, mbox_tmo; | |
5767 | ||
5768 | /* Calculate the total requested length of the dma memory */ | |
8a9d2e80 | 5769 | req_len = extnt_cnt * sizeof(uint16_t); |
6d368e53 JS |
5770 | |
5771 | /* | |
5772 | * Calculate the size of an embedded mailbox. The uint32_t | |
5773 | * accounts for extents-specific word. | |
5774 | */ | |
5775 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5776 | sizeof(uint32_t); | |
5777 | ||
5778 | /* | |
5779 | * Presume the allocation and response will fit into an embedded | |
5780 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5781 | */ | |
5782 | *emb = LPFC_SLI4_MBX_EMBED; | |
5783 | if (req_len > emb_len) { | |
8a9d2e80 | 5784 | req_len = extnt_cnt * sizeof(uint16_t) + |
6d368e53 JS |
5785 | sizeof(union lpfc_sli4_cfg_shdr) + |
5786 | sizeof(uint32_t); | |
5787 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5788 | } | |
5789 | ||
5790 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5791 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5792 | req_len, *emb); | |
5793 | if (alloc_len < req_len) { | |
5794 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5795 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5796 | "less than the requested DMA memory " |
5797 | "size (x%x)\n", alloc_len, req_len); | |
5798 | return -ENOMEM; | |
5799 | } | |
8a9d2e80 | 5800 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
6d368e53 JS |
5801 | if (unlikely(rc)) |
5802 | return -EIO; | |
5803 | ||
5804 | if (!phba->sli4_hba.intr_enable) | |
5805 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5806 | else { | |
a183a15f | 5807 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5808 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5809 | } | |
5810 | ||
5811 | if (unlikely(rc)) | |
5812 | rc = -EIO; | |
5813 | return rc; | |
5814 | } | |
5815 | ||
5816 | /** | |
5817 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5818 | * @phba: Pointer to HBA context object. | |
5819 | * @type: The resource extent type to allocate. | |
5820 | * | |
5821 | * This function allocates the number of elements for the specified | |
5822 | * resource type. | |
5823 | **/ | |
5824 | static int | |
5825 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5826 | { | |
5827 | bool emb = false; | |
5828 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5829 | uint16_t rsrc_id, rsrc_start, j, k; | |
5830 | uint16_t *ids; | |
5831 | int i, rc; | |
5832 | unsigned long longs; | |
5833 | unsigned long *bmask; | |
5834 | struct lpfc_rsrc_blks *rsrc_blks; | |
5835 | LPFC_MBOXQ_t *mbox; | |
5836 | uint32_t length; | |
5837 | struct lpfc_id_range *id_array = NULL; | |
5838 | void *virtaddr = NULL; | |
5839 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5840 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5841 | struct list_head *ext_blk_list; | |
5842 | ||
5843 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5844 | &rsrc_cnt, | |
5845 | &rsrc_size); | |
5846 | if (unlikely(rc)) | |
5847 | return -EIO; | |
5848 | ||
5849 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5850 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5851 | "3009 No available Resource Extents " | |
5852 | "for resource type 0x%x: Count: 0x%x, " | |
5853 | "Size 0x%x\n", type, rsrc_cnt, | |
5854 | rsrc_size); | |
5855 | return -ENOMEM; | |
5856 | } | |
5857 | ||
8a9d2e80 JS |
5858 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
5859 | "2903 Post resource extents type-0x%x: " | |
5860 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); | |
6d368e53 JS |
5861 | |
5862 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5863 | if (!mbox) | |
5864 | return -ENOMEM; | |
5865 | ||
8a9d2e80 | 5866 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
6d368e53 JS |
5867 | if (unlikely(rc)) { |
5868 | rc = -EIO; | |
5869 | goto err_exit; | |
5870 | } | |
5871 | ||
5872 | /* | |
5873 | * Figure out where the response is located. Then get local pointers | |
5874 | * to the response data. The port does not guarantee to respond to | |
5875 | * all extents counts request so update the local variable with the | |
5876 | * allocated count from the port. | |
5877 | */ | |
5878 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5879 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5880 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5881 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5882 | } else { | |
5883 | virtaddr = mbox->sge_array->addr[0]; | |
5884 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5885 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5886 | id_array = &n_rsrc->id; | |
5887 | } | |
5888 | ||
5889 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5890 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5891 | ||
5892 | /* | |
5893 | * Based on the resource size and count, correct the base and max | |
5894 | * resource values. | |
5895 | */ | |
5896 | length = sizeof(struct lpfc_rsrc_blks); | |
5897 | switch (type) { | |
5898 | case LPFC_RSC_TYPE_FCOE_RPI: | |
6396bb22 | 5899 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
6d368e53 JS |
5900 | sizeof(unsigned long), |
5901 | GFP_KERNEL); | |
5902 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5903 | rc = -ENOMEM; | |
5904 | goto err_exit; | |
5905 | } | |
6396bb22 | 5906 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
6d368e53 JS |
5907 | sizeof(uint16_t), |
5908 | GFP_KERNEL); | |
5909 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5910 | kfree(phba->sli4_hba.rpi_bmask); | |
5911 | rc = -ENOMEM; | |
5912 | goto err_exit; | |
5913 | } | |
5914 | ||
5915 | /* | |
5916 | * The next_rpi was initialized with the maximum available | |
5917 | * count but the port may allocate a smaller number. Catch | |
5918 | * that case and update the next_rpi. | |
5919 | */ | |
5920 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5921 | ||
5922 | /* Initialize local ptrs for common extent processing later. */ | |
5923 | bmask = phba->sli4_hba.rpi_bmask; | |
5924 | ids = phba->sli4_hba.rpi_ids; | |
5925 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5926 | break; | |
5927 | case LPFC_RSC_TYPE_FCOE_VPI: | |
6396bb22 | 5928 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
6d368e53 JS |
5929 | GFP_KERNEL); |
5930 | if (unlikely(!phba->vpi_bmask)) { | |
5931 | rc = -ENOMEM; | |
5932 | goto err_exit; | |
5933 | } | |
6396bb22 | 5934 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
6d368e53 JS |
5935 | GFP_KERNEL); |
5936 | if (unlikely(!phba->vpi_ids)) { | |
5937 | kfree(phba->vpi_bmask); | |
5938 | rc = -ENOMEM; | |
5939 | goto err_exit; | |
5940 | } | |
5941 | ||
5942 | /* Initialize local ptrs for common extent processing later. */ | |
5943 | bmask = phba->vpi_bmask; | |
5944 | ids = phba->vpi_ids; | |
5945 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5946 | break; | |
5947 | case LPFC_RSC_TYPE_FCOE_XRI: | |
6396bb22 | 5948 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
6d368e53 JS |
5949 | sizeof(unsigned long), |
5950 | GFP_KERNEL); | |
5951 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5952 | rc = -ENOMEM; | |
5953 | goto err_exit; | |
5954 | } | |
8a9d2e80 | 5955 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6396bb22 | 5956 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
6d368e53 JS |
5957 | sizeof(uint16_t), |
5958 | GFP_KERNEL); | |
5959 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5960 | kfree(phba->sli4_hba.xri_bmask); | |
5961 | rc = -ENOMEM; | |
5962 | goto err_exit; | |
5963 | } | |
5964 | ||
5965 | /* Initialize local ptrs for common extent processing later. */ | |
5966 | bmask = phba->sli4_hba.xri_bmask; | |
5967 | ids = phba->sli4_hba.xri_ids; | |
5968 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5969 | break; | |
5970 | case LPFC_RSC_TYPE_FCOE_VFI: | |
6396bb22 | 5971 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
6d368e53 JS |
5972 | sizeof(unsigned long), |
5973 | GFP_KERNEL); | |
5974 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5975 | rc = -ENOMEM; | |
5976 | goto err_exit; | |
5977 | } | |
6396bb22 | 5978 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
6d368e53 JS |
5979 | sizeof(uint16_t), |
5980 | GFP_KERNEL); | |
5981 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5982 | kfree(phba->sli4_hba.vfi_bmask); | |
5983 | rc = -ENOMEM; | |
5984 | goto err_exit; | |
5985 | } | |
5986 | ||
5987 | /* Initialize local ptrs for common extent processing later. */ | |
5988 | bmask = phba->sli4_hba.vfi_bmask; | |
5989 | ids = phba->sli4_hba.vfi_ids; | |
5990 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5991 | break; | |
5992 | default: | |
5993 | /* Unsupported Opcode. Fail call. */ | |
5994 | id_array = NULL; | |
5995 | bmask = NULL; | |
5996 | ids = NULL; | |
5997 | ext_blk_list = NULL; | |
5998 | goto err_exit; | |
5999 | } | |
6000 | ||
6001 | /* | |
6002 | * Complete initializing the extent configuration with the | |
6003 | * allocated ids assigned to this function. The bitmask serves | |
6004 | * as an index into the array and manages the available ids. The | |
6005 | * array just stores the ids communicated to the port via the wqes. | |
6006 | */ | |
6007 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
6008 | if ((i % 2) == 0) | |
6009 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
6010 | &id_array[k]); | |
6011 | else | |
6012 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
6013 | &id_array[k]); | |
6014 | ||
6015 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
6016 | if (unlikely(!rsrc_blks)) { | |
6017 | rc = -ENOMEM; | |
6018 | kfree(bmask); | |
6019 | kfree(ids); | |
6020 | goto err_exit; | |
6021 | } | |
6022 | rsrc_blks->rsrc_start = rsrc_id; | |
6023 | rsrc_blks->rsrc_size = rsrc_size; | |
6024 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
6025 | rsrc_start = rsrc_id; | |
895427bd | 6026 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
6d368e53 | 6027 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
895427bd JS |
6028 | lpfc_sli4_get_iocb_cnt(phba); |
6029 | phba->sli4_hba.nvme_xri_start = | |
6030 | phba->sli4_hba.scsi_xri_start + | |
6031 | phba->sli4_hba.scsi_xri_max; | |
6032 | } | |
6d368e53 JS |
6033 | |
6034 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
6035 | ids[j] = rsrc_id; | |
6036 | rsrc_id++; | |
6037 | j++; | |
6038 | } | |
6039 | /* Entire word processed. Get next word.*/ | |
6040 | if ((i % 2) == 1) | |
6041 | k++; | |
6042 | } | |
6043 | err_exit: | |
6044 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
6045 | return rc; | |
6046 | } | |
6047 | ||
895427bd JS |
6048 | |
6049 | ||
6d368e53 JS |
6050 | /** |
6051 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
6052 | * @phba: Pointer to HBA context object. | |
6053 | * @type: the extent's type. | |
6054 | * | |
6055 | * This function deallocates all extents of a particular resource type. | |
6056 | * SLI4 does not allow for deallocating a particular extent range. It | |
6057 | * is the caller's responsibility to release all kernel memory resources. | |
6058 | **/ | |
6059 | static int | |
6060 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
6061 | { | |
6062 | int rc; | |
6063 | uint32_t length, mbox_tmo = 0; | |
6064 | LPFC_MBOXQ_t *mbox; | |
6065 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
6066 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
6067 | ||
6068 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6069 | if (!mbox) | |
6070 | return -ENOMEM; | |
6071 | ||
6072 | /* | |
6073 | * This function sends an embedded mailbox because it only sends the | |
6074 | * the resource type. All extents of this type are released by the | |
6075 | * port. | |
6076 | */ | |
6077 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
6078 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6079 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6080 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
6081 | length, LPFC_SLI4_MBX_EMBED); | |
6082 | ||
6083 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
6084 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
6085 | LPFC_SLI4_MBX_EMBED); | |
6086 | if (unlikely(rc)) { | |
6087 | rc = -EIO; | |
6088 | goto out_free_mbox; | |
6089 | } | |
6090 | if (!phba->sli4_hba.intr_enable) | |
6091 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6092 | else { | |
a183a15f | 6093 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
6094 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
6095 | } | |
6096 | if (unlikely(rc)) { | |
6097 | rc = -EIO; | |
6098 | goto out_free_mbox; | |
6099 | } | |
6100 | ||
6101 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
6102 | if (bf_get(lpfc_mbox_hdr_status, | |
6103 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
6104 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
6105 | "2919 Failed to release resource extents " | |
6106 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
6107 | "Resource memory not released.\n", | |
6108 | type, | |
6109 | bf_get(lpfc_mbox_hdr_status, | |
6110 | &dealloc_rsrc->header.cfg_shdr.response), | |
6111 | bf_get(lpfc_mbox_hdr_add_status, | |
6112 | &dealloc_rsrc->header.cfg_shdr.response)); | |
6113 | rc = -EIO; | |
6114 | goto out_free_mbox; | |
6115 | } | |
6116 | ||
6117 | /* Release kernel memory resources for the specific type. */ | |
6118 | switch (type) { | |
6119 | case LPFC_RSC_TYPE_FCOE_VPI: | |
6120 | kfree(phba->vpi_bmask); | |
6121 | kfree(phba->vpi_ids); | |
6122 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6123 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
6124 | &phba->lpfc_vpi_blk_list, list) { | |
6125 | list_del_init(&rsrc_blk->list); | |
6126 | kfree(rsrc_blk); | |
6127 | } | |
16a3a208 | 6128 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
6129 | break; |
6130 | case LPFC_RSC_TYPE_FCOE_XRI: | |
6131 | kfree(phba->sli4_hba.xri_bmask); | |
6132 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
6133 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
6134 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
6135 | list_del_init(&rsrc_blk->list); | |
6136 | kfree(rsrc_blk); | |
6137 | } | |
6138 | break; | |
6139 | case LPFC_RSC_TYPE_FCOE_VFI: | |
6140 | kfree(phba->sli4_hba.vfi_bmask); | |
6141 | kfree(phba->sli4_hba.vfi_ids); | |
6142 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6143 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
6144 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
6145 | list_del_init(&rsrc_blk->list); | |
6146 | kfree(rsrc_blk); | |
6147 | } | |
6148 | break; | |
6149 | case LPFC_RSC_TYPE_FCOE_RPI: | |
6150 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
6151 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
6152 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
6153 | list_del_init(&rsrc_blk->list); | |
6154 | kfree(rsrc_blk); | |
6155 | } | |
6156 | break; | |
6157 | default: | |
6158 | break; | |
6159 | } | |
6160 | ||
6161 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6162 | ||
6163 | out_free_mbox: | |
6164 | mempool_free(mbox, phba->mbox_mem_pool); | |
6165 | return rc; | |
6166 | } | |
6167 | ||
bd4b3e5c | 6168 | static void |
7bdedb34 JS |
6169 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
6170 | uint32_t feature) | |
65791f1f | 6171 | { |
65791f1f | 6172 | uint32_t len; |
65791f1f | 6173 | |
65791f1f JS |
6174 | len = sizeof(struct lpfc_mbx_set_feature) - |
6175 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
6176 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6177 | LPFC_MBOX_OPCODE_SET_FEATURES, len, | |
6178 | LPFC_SLI4_MBX_EMBED); | |
7bdedb34 JS |
6179 | |
6180 | switch (feature) { | |
6181 | case LPFC_SET_UE_RECOVERY: | |
6182 | bf_set(lpfc_mbx_set_feature_UER, | |
6183 | &mbox->u.mqe.un.set_feature, 1); | |
6184 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; | |
6185 | mbox->u.mqe.un.set_feature.param_len = 8; | |
6186 | break; | |
6187 | case LPFC_SET_MDS_DIAGS: | |
6188 | bf_set(lpfc_mbx_set_feature_mds, | |
6189 | &mbox->u.mqe.un.set_feature, 1); | |
6190 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, | |
ae9e28f3 | 6191 | &mbox->u.mqe.un.set_feature, 1); |
7bdedb34 JS |
6192 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
6193 | mbox->u.mqe.un.set_feature.param_len = 8; | |
6194 | break; | |
65791f1f | 6195 | } |
7bdedb34 JS |
6196 | |
6197 | return; | |
65791f1f JS |
6198 | } |
6199 | ||
d2cc9bcd JS |
6200 | /** |
6201 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. | |
6202 | * @phba: Pointer to HBA context object. | |
6203 | * | |
6204 | * This function is called to free memory allocated for RAS FW logging | |
6205 | * support in the driver. | |
6206 | **/ | |
6207 | void | |
6208 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) | |
6209 | { | |
6210 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; | |
6211 | struct lpfc_dmabuf *dmabuf, *next; | |
6212 | ||
6213 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { | |
6214 | list_for_each_entry_safe(dmabuf, next, | |
6215 | &ras_fwlog->fwlog_buff_list, | |
6216 | list) { | |
6217 | list_del(&dmabuf->list); | |
6218 | dma_free_coherent(&phba->pcidev->dev, | |
6219 | LPFC_RAS_MAX_ENTRY_SIZE, | |
6220 | dmabuf->virt, dmabuf->phys); | |
6221 | kfree(dmabuf); | |
6222 | } | |
6223 | } | |
6224 | ||
6225 | if (ras_fwlog->lwpd.virt) { | |
6226 | dma_free_coherent(&phba->pcidev->dev, | |
6227 | sizeof(uint32_t) * 2, | |
6228 | ras_fwlog->lwpd.virt, | |
6229 | ras_fwlog->lwpd.phys); | |
6230 | ras_fwlog->lwpd.virt = NULL; | |
6231 | } | |
6232 | ||
6233 | ras_fwlog->ras_active = false; | |
6234 | } | |
6235 | ||
6236 | /** | |
6237 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support | |
6238 | * @phba: Pointer to HBA context object. | |
6239 | * @fwlog_buff_count: Count of buffers to be created. | |
6240 | * | |
6241 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer | |
6242 | * to update FW log is posted to the adapter. | |
6243 | * Buffer count is calculated based on module param ras_fwlog_buffsize | |
6244 | * Size of each buffer posted to FW is 64K. | |
6245 | **/ | |
6246 | ||
6247 | static int | |
6248 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, | |
6249 | uint32_t fwlog_buff_count) | |
6250 | { | |
6251 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; | |
6252 | struct lpfc_dmabuf *dmabuf; | |
6253 | int rc = 0, i = 0; | |
6254 | ||
6255 | /* Initialize List */ | |
6256 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); | |
6257 | ||
6258 | /* Allocate memory for the LWPD */ | |
6259 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, | |
6260 | sizeof(uint32_t) * 2, | |
6261 | &ras_fwlog->lwpd.phys, | |
6262 | GFP_KERNEL); | |
6263 | if (!ras_fwlog->lwpd.virt) { | |
cb34990b | 6264 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
d2cc9bcd JS |
6265 | "6185 LWPD Memory Alloc Failed\n"); |
6266 | ||
6267 | return -ENOMEM; | |
6268 | } | |
6269 | ||
6270 | ras_fwlog->fw_buffcount = fwlog_buff_count; | |
6271 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { | |
6272 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
6273 | GFP_KERNEL); | |
6274 | if (!dmabuf) { | |
6275 | rc = -ENOMEM; | |
6276 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6277 | "6186 Memory Alloc failed FW logging"); | |
6278 | goto free_mem; | |
6279 | } | |
6280 | ||
359d0ac1 | 6281 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
d2cc9bcd JS |
6282 | LPFC_RAS_MAX_ENTRY_SIZE, |
6283 | &dmabuf->phys, | |
6284 | GFP_KERNEL); | |
6285 | if (!dmabuf->virt) { | |
6286 | kfree(dmabuf); | |
6287 | rc = -ENOMEM; | |
6288 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6289 | "6187 DMA Alloc Failed FW logging"); | |
6290 | goto free_mem; | |
6291 | } | |
d2cc9bcd JS |
6292 | dmabuf->buffer_tag = i; |
6293 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); | |
6294 | } | |
6295 | ||
6296 | free_mem: | |
6297 | if (rc) | |
6298 | lpfc_sli4_ras_dma_free(phba); | |
6299 | ||
6300 | return rc; | |
6301 | } | |
6302 | ||
6303 | /** | |
6304 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command | |
6305 | * @phba: pointer to lpfc hba data structure. | |
6306 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
6307 | * | |
6308 | * Completion handler for driver's RAS MBX command to the device. | |
6309 | **/ | |
6310 | static void | |
6311 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
6312 | { | |
6313 | MAILBOX_t *mb; | |
6314 | union lpfc_sli4_cfg_shdr *shdr; | |
6315 | uint32_t shdr_status, shdr_add_status; | |
6316 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; | |
6317 | ||
6318 | mb = &pmb->u.mb; | |
6319 | ||
6320 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6321 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; | |
6322 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6323 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6324 | ||
6325 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { | |
cb34990b | 6326 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
d2cc9bcd JS |
6327 | "6188 FW LOG mailbox " |
6328 | "completed with status x%x add_status x%x," | |
6329 | " mbx status x%x\n", | |
6330 | shdr_status, shdr_add_status, mb->mbxStatus); | |
cb34990b JS |
6331 | |
6332 | ras_fwlog->ras_hwsupport = false; | |
d2cc9bcd JS |
6333 | goto disable_ras; |
6334 | } | |
6335 | ||
6336 | ras_fwlog->ras_active = true; | |
6337 | mempool_free(pmb, phba->mbox_mem_pool); | |
6338 | ||
6339 | return; | |
6340 | ||
6341 | disable_ras: | |
6342 | /* Free RAS DMA memory */ | |
6343 | lpfc_sli4_ras_dma_free(phba); | |
6344 | mempool_free(pmb, phba->mbox_mem_pool); | |
6345 | } | |
6346 | ||
6347 | /** | |
6348 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command | |
6349 | * @phba: pointer to lpfc hba data structure. | |
6350 | * @fwlog_level: Logging verbosity level. | |
6351 | * @fwlog_enable: Enable/Disable logging. | |
6352 | * | |
6353 | * Initialize memory and post mailbox command to enable FW logging in host | |
6354 | * memory. | |
6355 | **/ | |
6356 | int | |
6357 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, | |
6358 | uint32_t fwlog_level, | |
6359 | uint32_t fwlog_enable) | |
6360 | { | |
6361 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; | |
6362 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; | |
6363 | struct lpfc_dmabuf *dmabuf; | |
6364 | LPFC_MBOXQ_t *mbox; | |
6365 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; | |
6366 | int rc = 0; | |
6367 | ||
6368 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * | |
6369 | phba->cfg_ras_fwlog_buffsize); | |
6370 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); | |
6371 | ||
6372 | /* | |
6373 | * If re-enabling FW logging support use earlier allocated | |
6374 | * DMA buffers while posting MBX command. | |
6375 | **/ | |
6376 | if (!ras_fwlog->lwpd.virt) { | |
6377 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); | |
6378 | if (rc) { | |
6379 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
cb34990b | 6380 | "6189 FW Log Memory Allocation Failed"); |
d2cc9bcd JS |
6381 | return rc; |
6382 | } | |
6383 | } | |
6384 | ||
6385 | /* Setup Mailbox command */ | |
6386 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6387 | if (!mbox) { | |
cb34990b | 6388 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
d2cc9bcd JS |
6389 | "6190 RAS MBX Alloc Failed"); |
6390 | rc = -ENOMEM; | |
6391 | goto mem_free; | |
6392 | } | |
6393 | ||
6394 | ras_fwlog->fw_loglevel = fwlog_level; | |
6395 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - | |
6396 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6397 | ||
6398 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, | |
6399 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, | |
6400 | len, LPFC_SLI4_MBX_EMBED); | |
6401 | ||
6402 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; | |
6403 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, | |
6404 | fwlog_enable); | |
6405 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, | |
6406 | ras_fwlog->fw_loglevel); | |
6407 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, | |
6408 | ras_fwlog->fw_buffcount); | |
6409 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, | |
6410 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); | |
6411 | ||
6412 | /* Update DMA buffer address */ | |
6413 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { | |
6414 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); | |
6415 | ||
6416 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = | |
6417 | putPaddrLow(dmabuf->phys); | |
6418 | ||
6419 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = | |
6420 | putPaddrHigh(dmabuf->phys); | |
6421 | } | |
6422 | ||
6423 | /* Update LPWD address */ | |
6424 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); | |
6425 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); | |
6426 | ||
6427 | mbox->vport = phba->pport; | |
6428 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; | |
6429 | ||
6430 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
6431 | ||
6432 | if (rc == MBX_NOT_FINISHED) { | |
cb34990b JS |
6433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6434 | "6191 FW-Log Mailbox failed. " | |
d2cc9bcd JS |
6435 | "status %d mbxStatus : x%x", rc, |
6436 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); | |
6437 | mempool_free(mbox, phba->mbox_mem_pool); | |
6438 | rc = -EIO; | |
6439 | goto mem_free; | |
6440 | } else | |
6441 | rc = 0; | |
6442 | mem_free: | |
6443 | if (rc) | |
6444 | lpfc_sli4_ras_dma_free(phba); | |
6445 | ||
6446 | return rc; | |
6447 | } | |
6448 | ||
6449 | /** | |
6450 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter | |
6451 | * @phba: Pointer to HBA context object. | |
6452 | * | |
6453 | * Check if RAS is supported on the adapter and initialize it. | |
6454 | **/ | |
6455 | void | |
6456 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) | |
6457 | { | |
6458 | /* Check RAS FW Log needs to be enabled or not */ | |
6459 | if (lpfc_check_fwlog_support(phba)) | |
6460 | return; | |
6461 | ||
6462 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, | |
6463 | LPFC_RAS_ENABLE_LOGGING); | |
6464 | } | |
6465 | ||
6d368e53 JS |
6466 | /** |
6467 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
6468 | * @phba: Pointer to HBA context object. | |
6469 | * | |
6470 | * This function allocates all SLI4 resource identifiers. | |
6471 | **/ | |
6472 | int | |
6473 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
6474 | { | |
6475 | int i, rc, error = 0; | |
6476 | uint16_t count, base; | |
6477 | unsigned long longs; | |
6478 | ||
ff78d8f9 JS |
6479 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6480 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
6481 | if (phba->sli4_hba.extents_in_use) { |
6482 | /* | |
6483 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
6484 | * resource extent count must be read and allocated before | |
6485 | * provisioning the resource id arrays. | |
6486 | */ | |
6487 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
6488 | LPFC_IDX_RSRC_RDY) { | |
6489 | /* | |
6490 | * Extent-based resources are set - the driver could | |
6491 | * be in a port reset. Figure out if any corrective | |
6492 | * actions need to be taken. | |
6493 | */ | |
6494 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
6495 | LPFC_RSC_TYPE_FCOE_VFI); | |
6496 | if (rc != 0) | |
6497 | error++; | |
6498 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
6499 | LPFC_RSC_TYPE_FCOE_VPI); | |
6500 | if (rc != 0) | |
6501 | error++; | |
6502 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
6503 | LPFC_RSC_TYPE_FCOE_XRI); | |
6504 | if (rc != 0) | |
6505 | error++; | |
6506 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
6507 | LPFC_RSC_TYPE_FCOE_RPI); | |
6508 | if (rc != 0) | |
6509 | error++; | |
6510 | ||
6511 | /* | |
6512 | * It's possible that the number of resources | |
6513 | * provided to this port instance changed between | |
6514 | * resets. Detect this condition and reallocate | |
6515 | * resources. Otherwise, there is no action. | |
6516 | */ | |
6517 | if (error) { | |
6518 | lpfc_printf_log(phba, KERN_INFO, | |
6519 | LOG_MBOX | LOG_INIT, | |
6520 | "2931 Detected extent resource " | |
6521 | "change. Reallocating all " | |
6522 | "extents.\n"); | |
6523 | rc = lpfc_sli4_dealloc_extent(phba, | |
6524 | LPFC_RSC_TYPE_FCOE_VFI); | |
6525 | rc = lpfc_sli4_dealloc_extent(phba, | |
6526 | LPFC_RSC_TYPE_FCOE_VPI); | |
6527 | rc = lpfc_sli4_dealloc_extent(phba, | |
6528 | LPFC_RSC_TYPE_FCOE_XRI); | |
6529 | rc = lpfc_sli4_dealloc_extent(phba, | |
6530 | LPFC_RSC_TYPE_FCOE_RPI); | |
6531 | } else | |
6532 | return 0; | |
6533 | } | |
6534 | ||
6535 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
6536 | if (unlikely(rc)) | |
6537 | goto err_exit; | |
6538 | ||
6539 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
6540 | if (unlikely(rc)) | |
6541 | goto err_exit; | |
6542 | ||
6543 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
6544 | if (unlikely(rc)) | |
6545 | goto err_exit; | |
6546 | ||
6547 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
6548 | if (unlikely(rc)) | |
6549 | goto err_exit; | |
6550 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
6551 | LPFC_IDX_RSRC_RDY); | |
6552 | return rc; | |
6553 | } else { | |
6554 | /* | |
6555 | * The port does not support resource extents. The XRI, VPI, | |
6556 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
6557 | * Just allocate the bitmasks and provision the resource id | |
6558 | * arrays. If a port reset is active, the resources don't | |
6559 | * need any action - just exit. | |
6560 | */ | |
6561 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
6562 | LPFC_IDX_RSRC_RDY) { |
6563 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
6564 | lpfc_sli4_remove_rpis(phba); | |
6565 | } | |
6d368e53 JS |
6566 | /* RPIs. */ |
6567 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
0a630c27 JS |
6568 | if (count <= 0) { |
6569 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6570 | "3279 Invalid provisioning of " | |
6571 | "rpi:%d\n", count); | |
6572 | rc = -EINVAL; | |
6573 | goto err_exit; | |
6574 | } | |
6d368e53 JS |
6575 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
6576 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
6396bb22 | 6577 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
6d368e53 JS |
6578 | sizeof(unsigned long), |
6579 | GFP_KERNEL); | |
6580 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
6581 | rc = -ENOMEM; | |
6582 | goto err_exit; | |
6583 | } | |
6396bb22 | 6584 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
6d368e53 JS |
6585 | GFP_KERNEL); |
6586 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
6587 | rc = -ENOMEM; | |
6588 | goto free_rpi_bmask; | |
6589 | } | |
6590 | ||
6591 | for (i = 0; i < count; i++) | |
6592 | phba->sli4_hba.rpi_ids[i] = base + i; | |
6593 | ||
6594 | /* VPIs. */ | |
6595 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
0a630c27 JS |
6596 | if (count <= 0) { |
6597 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6598 | "3280 Invalid provisioning of " | |
6599 | "vpi:%d\n", count); | |
6600 | rc = -EINVAL; | |
6601 | goto free_rpi_ids; | |
6602 | } | |
6d368e53 JS |
6603 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
6604 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
6396bb22 | 6605 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
6d368e53 JS |
6606 | GFP_KERNEL); |
6607 | if (unlikely(!phba->vpi_bmask)) { | |
6608 | rc = -ENOMEM; | |
6609 | goto free_rpi_ids; | |
6610 | } | |
6396bb22 | 6611 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
6d368e53 JS |
6612 | GFP_KERNEL); |
6613 | if (unlikely(!phba->vpi_ids)) { | |
6614 | rc = -ENOMEM; | |
6615 | goto free_vpi_bmask; | |
6616 | } | |
6617 | ||
6618 | for (i = 0; i < count; i++) | |
6619 | phba->vpi_ids[i] = base + i; | |
6620 | ||
6621 | /* XRIs. */ | |
6622 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
0a630c27 JS |
6623 | if (count <= 0) { |
6624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6625 | "3281 Invalid provisioning of " | |
6626 | "xri:%d\n", count); | |
6627 | rc = -EINVAL; | |
6628 | goto free_vpi_ids; | |
6629 | } | |
6d368e53 JS |
6630 | base = phba->sli4_hba.max_cfg_param.xri_base; |
6631 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
6396bb22 | 6632 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
6d368e53 JS |
6633 | sizeof(unsigned long), |
6634 | GFP_KERNEL); | |
6635 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
6636 | rc = -ENOMEM; | |
6637 | goto free_vpi_ids; | |
6638 | } | |
41899be7 | 6639 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6396bb22 | 6640 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
6d368e53 JS |
6641 | GFP_KERNEL); |
6642 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
6643 | rc = -ENOMEM; | |
6644 | goto free_xri_bmask; | |
6645 | } | |
6646 | ||
6647 | for (i = 0; i < count; i++) | |
6648 | phba->sli4_hba.xri_ids[i] = base + i; | |
6649 | ||
6650 | /* VFIs. */ | |
6651 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
0a630c27 JS |
6652 | if (count <= 0) { |
6653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6654 | "3282 Invalid provisioning of " | |
6655 | "vfi:%d\n", count); | |
6656 | rc = -EINVAL; | |
6657 | goto free_xri_ids; | |
6658 | } | |
6d368e53 JS |
6659 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
6660 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
6396bb22 | 6661 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
6d368e53 JS |
6662 | sizeof(unsigned long), |
6663 | GFP_KERNEL); | |
6664 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
6665 | rc = -ENOMEM; | |
6666 | goto free_xri_ids; | |
6667 | } | |
6396bb22 | 6668 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
6d368e53 JS |
6669 | GFP_KERNEL); |
6670 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
6671 | rc = -ENOMEM; | |
6672 | goto free_vfi_bmask; | |
6673 | } | |
6674 | ||
6675 | for (i = 0; i < count; i++) | |
6676 | phba->sli4_hba.vfi_ids[i] = base + i; | |
6677 | ||
6678 | /* | |
6679 | * Mark all resources ready. An HBA reset doesn't need | |
6680 | * to reset the initialization. | |
6681 | */ | |
6682 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
6683 | LPFC_IDX_RSRC_RDY); | |
6684 | return 0; | |
6685 | } | |
6686 | ||
6687 | free_vfi_bmask: | |
6688 | kfree(phba->sli4_hba.vfi_bmask); | |
cd60be49 | 6689 | phba->sli4_hba.vfi_bmask = NULL; |
6d368e53 JS |
6690 | free_xri_ids: |
6691 | kfree(phba->sli4_hba.xri_ids); | |
cd60be49 | 6692 | phba->sli4_hba.xri_ids = NULL; |
6d368e53 JS |
6693 | free_xri_bmask: |
6694 | kfree(phba->sli4_hba.xri_bmask); | |
cd60be49 | 6695 | phba->sli4_hba.xri_bmask = NULL; |
6d368e53 JS |
6696 | free_vpi_ids: |
6697 | kfree(phba->vpi_ids); | |
cd60be49 | 6698 | phba->vpi_ids = NULL; |
6d368e53 JS |
6699 | free_vpi_bmask: |
6700 | kfree(phba->vpi_bmask); | |
cd60be49 | 6701 | phba->vpi_bmask = NULL; |
6d368e53 JS |
6702 | free_rpi_ids: |
6703 | kfree(phba->sli4_hba.rpi_ids); | |
cd60be49 | 6704 | phba->sli4_hba.rpi_ids = NULL; |
6d368e53 JS |
6705 | free_rpi_bmask: |
6706 | kfree(phba->sli4_hba.rpi_bmask); | |
cd60be49 | 6707 | phba->sli4_hba.rpi_bmask = NULL; |
6d368e53 JS |
6708 | err_exit: |
6709 | return rc; | |
6710 | } | |
6711 | ||
6712 | /** | |
6713 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
6714 | * @phba: Pointer to HBA context object. | |
6715 | * | |
6716 | * This function allocates the number of elements for the specified | |
6717 | * resource type. | |
6718 | **/ | |
6719 | int | |
6720 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
6721 | { | |
6722 | if (phba->sli4_hba.extents_in_use) { | |
6723 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
6724 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
6725 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
6726 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
6727 | } else { | |
6728 | kfree(phba->vpi_bmask); | |
16a3a208 | 6729 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
6d368e53 JS |
6730 | kfree(phba->vpi_ids); |
6731 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6732 | kfree(phba->sli4_hba.xri_bmask); | |
6733 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
6734 | kfree(phba->sli4_hba.vfi_bmask); |
6735 | kfree(phba->sli4_hba.vfi_ids); | |
6736 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6737 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6738 | } | |
6739 | ||
6740 | return 0; | |
6741 | } | |
6742 | ||
b76f2dc9 JS |
6743 | /** |
6744 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
6745 | * @phba: Pointer to HBA context object. | |
6746 | * @type: The resource extent type. | |
6747 | * @extnt_count: buffer to hold port extent count response | |
6748 | * @extnt_size: buffer to hold port extent size response. | |
6749 | * | |
6750 | * This function calls the port to read the host allocated extents | |
6751 | * for a particular type. | |
6752 | **/ | |
6753 | int | |
6754 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
6755 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
6756 | { | |
6757 | bool emb; | |
6758 | int rc = 0; | |
6759 | uint16_t curr_blks = 0; | |
6760 | uint32_t req_len, emb_len; | |
6761 | uint32_t alloc_len, mbox_tmo; | |
6762 | struct list_head *blk_list_head; | |
6763 | struct lpfc_rsrc_blks *rsrc_blk; | |
6764 | LPFC_MBOXQ_t *mbox; | |
6765 | void *virtaddr = NULL; | |
6766 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
6767 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
6768 | union lpfc_sli4_cfg_shdr *shdr; | |
6769 | ||
6770 | switch (type) { | |
6771 | case LPFC_RSC_TYPE_FCOE_VPI: | |
6772 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
6773 | break; | |
6774 | case LPFC_RSC_TYPE_FCOE_XRI: | |
6775 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
6776 | break; | |
6777 | case LPFC_RSC_TYPE_FCOE_VFI: | |
6778 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
6779 | break; | |
6780 | case LPFC_RSC_TYPE_FCOE_RPI: | |
6781 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
6782 | break; | |
6783 | default: | |
6784 | return -EIO; | |
6785 | } | |
6786 | ||
6787 | /* Count the number of extents currently allocatd for this type. */ | |
6788 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
6789 | if (curr_blks == 0) { | |
6790 | /* | |
6791 | * The GET_ALLOCATED mailbox does not return the size, | |
6792 | * just the count. The size should be just the size | |
6793 | * stored in the current allocated block and all sizes | |
6794 | * for an extent type are the same so set the return | |
6795 | * value now. | |
6796 | */ | |
6797 | *extnt_size = rsrc_blk->rsrc_size; | |
6798 | } | |
6799 | curr_blks++; | |
6800 | } | |
6801 | ||
b76f2dc9 JS |
6802 | /* |
6803 | * Calculate the size of an embedded mailbox. The uint32_t | |
6804 | * accounts for extents-specific word. | |
6805 | */ | |
6806 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
6807 | sizeof(uint32_t); | |
6808 | ||
6809 | /* | |
6810 | * Presume the allocation and response will fit into an embedded | |
6811 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
6812 | */ | |
6813 | emb = LPFC_SLI4_MBX_EMBED; | |
6814 | req_len = emb_len; | |
6815 | if (req_len > emb_len) { | |
6816 | req_len = curr_blks * sizeof(uint16_t) + | |
6817 | sizeof(union lpfc_sli4_cfg_shdr) + | |
6818 | sizeof(uint32_t); | |
6819 | emb = LPFC_SLI4_MBX_NEMBED; | |
6820 | } | |
6821 | ||
6822 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6823 | if (!mbox) | |
6824 | return -ENOMEM; | |
6825 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
6826 | ||
6827 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6828 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
6829 | req_len, emb); | |
6830 | if (alloc_len < req_len) { | |
6831 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6832 | "2983 Allocated DMA memory size (x%x) is " | |
6833 | "less than the requested DMA memory " | |
6834 | "size (x%x)\n", alloc_len, req_len); | |
6835 | rc = -ENOMEM; | |
6836 | goto err_exit; | |
6837 | } | |
6838 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
6839 | if (unlikely(rc)) { | |
6840 | rc = -EIO; | |
6841 | goto err_exit; | |
6842 | } | |
6843 | ||
6844 | if (!phba->sli4_hba.intr_enable) | |
6845 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6846 | else { | |
a183a15f | 6847 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
6848 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
6849 | } | |
6850 | ||
6851 | if (unlikely(rc)) { | |
6852 | rc = -EIO; | |
6853 | goto err_exit; | |
6854 | } | |
6855 | ||
6856 | /* | |
6857 | * Figure out where the response is located. Then get local pointers | |
6858 | * to the response data. The port does not guarantee to respond to | |
6859 | * all extents counts request so update the local variable with the | |
6860 | * allocated count from the port. | |
6861 | */ | |
6862 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
6863 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
6864 | shdr = &rsrc_ext->header.cfg_shdr; | |
6865 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
6866 | } else { | |
6867 | virtaddr = mbox->sge_array->addr[0]; | |
6868 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
6869 | shdr = &n_rsrc->cfg_shdr; | |
6870 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
6871 | } | |
6872 | ||
6873 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
6874 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
6875 | "2984 Failed to read allocated resources " | |
6876 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
6877 | type, | |
6878 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
6879 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
6880 | rc = -EIO; | |
6881 | goto err_exit; | |
6882 | } | |
6883 | err_exit: | |
6884 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
6885 | return rc; | |
6886 | } | |
6887 | ||
8a9d2e80 | 6888 | /** |
0ef69968 | 6889 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
8a9d2e80 | 6890 | * @phba: pointer to lpfc hba data structure. |
895427bd JS |
6891 | * @pring: Pointer to driver SLI ring object. |
6892 | * @sgl_list: linked link of sgl buffers to post | |
6893 | * @cnt: number of linked list buffers | |
8a9d2e80 | 6894 | * |
895427bd | 6895 | * This routine walks the list of buffers that have been allocated and |
8a9d2e80 JS |
6896 | * repost them to the port by using SGL block post. This is needed after a |
6897 | * pci_function_reset/warm_start or start. It attempts to construct blocks | |
895427bd JS |
6898 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
6899 | * SGL block post mailbox commands to post them to the port. For single | |
8a9d2e80 JS |
6900 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
6901 | * mailbox command for posting. | |
6902 | * | |
6903 | * Returns: 0 = success, non-zero failure. | |
6904 | **/ | |
6905 | static int | |
895427bd JS |
6906 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
6907 | struct list_head *sgl_list, int cnt) | |
8a9d2e80 JS |
6908 | { |
6909 | struct lpfc_sglq *sglq_entry = NULL; | |
6910 | struct lpfc_sglq *sglq_entry_next = NULL; | |
6911 | struct lpfc_sglq *sglq_entry_first = NULL; | |
895427bd JS |
6912 | int status, total_cnt; |
6913 | int post_cnt = 0, num_posted = 0, block_cnt = 0; | |
8a9d2e80 JS |
6914 | int last_xritag = NO_XRI; |
6915 | LIST_HEAD(prep_sgl_list); | |
6916 | LIST_HEAD(blck_sgl_list); | |
6917 | LIST_HEAD(allc_sgl_list); | |
6918 | LIST_HEAD(post_sgl_list); | |
6919 | LIST_HEAD(free_sgl_list); | |
6920 | ||
38c20673 | 6921 | spin_lock_irq(&phba->hbalock); |
895427bd JS |
6922 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
6923 | list_splice_init(sgl_list, &allc_sgl_list); | |
6924 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
38c20673 | 6925 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 | 6926 | |
895427bd | 6927 | total_cnt = cnt; |
8a9d2e80 JS |
6928 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
6929 | &allc_sgl_list, list) { | |
6930 | list_del_init(&sglq_entry->list); | |
6931 | block_cnt++; | |
6932 | if ((last_xritag != NO_XRI) && | |
6933 | (sglq_entry->sli4_xritag != last_xritag + 1)) { | |
6934 | /* a hole in xri block, form a sgl posting block */ | |
6935 | list_splice_init(&prep_sgl_list, &blck_sgl_list); | |
6936 | post_cnt = block_cnt - 1; | |
6937 | /* prepare list for next posting block */ | |
6938 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6939 | block_cnt = 1; | |
6940 | } else { | |
6941 | /* prepare list for next posting block */ | |
6942 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
6943 | /* enough sgls for non-embed sgl mbox command */ | |
6944 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
6945 | list_splice_init(&prep_sgl_list, | |
6946 | &blck_sgl_list); | |
6947 | post_cnt = block_cnt; | |
6948 | block_cnt = 0; | |
6949 | } | |
6950 | } | |
6951 | num_posted++; | |
6952 | ||
6953 | /* keep track of last sgl's xritag */ | |
6954 | last_xritag = sglq_entry->sli4_xritag; | |
6955 | ||
895427bd JS |
6956 | /* end of repost sgl list condition for buffers */ |
6957 | if (num_posted == total_cnt) { | |
8a9d2e80 JS |
6958 | if (post_cnt == 0) { |
6959 | list_splice_init(&prep_sgl_list, | |
6960 | &blck_sgl_list); | |
6961 | post_cnt = block_cnt; | |
6962 | } else if (block_cnt == 1) { | |
6963 | status = lpfc_sli4_post_sgl(phba, | |
6964 | sglq_entry->phys, 0, | |
6965 | sglq_entry->sli4_xritag); | |
6966 | if (!status) { | |
6967 | /* successful, put sgl to posted list */ | |
6968 | list_add_tail(&sglq_entry->list, | |
6969 | &post_sgl_list); | |
6970 | } else { | |
6971 | /* Failure, put sgl to free list */ | |
6972 | lpfc_printf_log(phba, KERN_WARNING, | |
6973 | LOG_SLI, | |
895427bd | 6974 | "3159 Failed to post " |
8a9d2e80 JS |
6975 | "sgl, xritag:x%x\n", |
6976 | sglq_entry->sli4_xritag); | |
6977 | list_add_tail(&sglq_entry->list, | |
6978 | &free_sgl_list); | |
711ea882 | 6979 | total_cnt--; |
8a9d2e80 JS |
6980 | } |
6981 | } | |
6982 | } | |
6983 | ||
6984 | /* continue until a nembed page worth of sgls */ | |
6985 | if (post_cnt == 0) | |
6986 | continue; | |
6987 | ||
895427bd JS |
6988 | /* post the buffer list sgls as a block */ |
6989 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, | |
6990 | post_cnt); | |
8a9d2e80 JS |
6991 | |
6992 | if (!status) { | |
6993 | /* success, put sgl list to posted sgl list */ | |
6994 | list_splice_init(&blck_sgl_list, &post_sgl_list); | |
6995 | } else { | |
6996 | /* Failure, put sgl list to free sgl list */ | |
6997 | sglq_entry_first = list_first_entry(&blck_sgl_list, | |
6998 | struct lpfc_sglq, | |
6999 | list); | |
7000 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
895427bd | 7001 | "3160 Failed to post sgl-list, " |
8a9d2e80 JS |
7002 | "xritag:x%x-x%x\n", |
7003 | sglq_entry_first->sli4_xritag, | |
7004 | (sglq_entry_first->sli4_xritag + | |
7005 | post_cnt - 1)); | |
7006 | list_splice_init(&blck_sgl_list, &free_sgl_list); | |
711ea882 | 7007 | total_cnt -= post_cnt; |
8a9d2e80 JS |
7008 | } |
7009 | ||
7010 | /* don't reset xirtag due to hole in xri block */ | |
7011 | if (block_cnt == 0) | |
7012 | last_xritag = NO_XRI; | |
7013 | ||
895427bd | 7014 | /* reset sgl post count for next round of posting */ |
8a9d2e80 JS |
7015 | post_cnt = 0; |
7016 | } | |
7017 | ||
895427bd | 7018 | /* free the sgls failed to post */ |
8a9d2e80 JS |
7019 | lpfc_free_sgl_list(phba, &free_sgl_list); |
7020 | ||
895427bd | 7021 | /* push sgls posted to the available list */ |
8a9d2e80 | 7022 | if (!list_empty(&post_sgl_list)) { |
38c20673 | 7023 | spin_lock_irq(&phba->hbalock); |
895427bd JS |
7024 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
7025 | list_splice_init(&post_sgl_list, sgl_list); | |
7026 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
38c20673 | 7027 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
7028 | } else { |
7029 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
895427bd | 7030 | "3161 Failure to post sgl to port.\n"); |
8a9d2e80 JS |
7031 | return -EIO; |
7032 | } | |
895427bd JS |
7033 | |
7034 | /* return the number of XRIs actually posted */ | |
7035 | return total_cnt; | |
8a9d2e80 JS |
7036 | } |
7037 | ||
61bda8f7 JS |
7038 | void |
7039 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
7040 | { | |
7041 | uint32_t len; | |
7042 | ||
7043 | len = sizeof(struct lpfc_mbx_set_host_data) - | |
7044 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
7045 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7046 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, | |
7047 | LPFC_SLI4_MBX_EMBED); | |
7048 | ||
7049 | mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION; | |
b2fd103b JS |
7050 | mbox->u.mqe.un.set_host_data.param_len = |
7051 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; | |
61bda8f7 JS |
7052 | snprintf(mbox->u.mqe.un.set_host_data.data, |
7053 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, | |
7054 | "Linux %s v"LPFC_DRIVER_VERSION, | |
7055 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); | |
7056 | } | |
7057 | ||
a8cf5dfe | 7058 | int |
6c621a22 | 7059 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
a8cf5dfe | 7060 | struct lpfc_queue *drq, int count, int idx) |
6c621a22 JS |
7061 | { |
7062 | int rc, i; | |
7063 | struct lpfc_rqe hrqe; | |
7064 | struct lpfc_rqe drqe; | |
7065 | struct lpfc_rqb *rqbp; | |
411de511 | 7066 | unsigned long flags; |
6c621a22 JS |
7067 | struct rqb_dmabuf *rqb_buffer; |
7068 | LIST_HEAD(rqb_buf_list); | |
7069 | ||
411de511 | 7070 | spin_lock_irqsave(&phba->hbalock, flags); |
6c621a22 JS |
7071 | rqbp = hrq->rqbp; |
7072 | for (i = 0; i < count; i++) { | |
7073 | /* IF RQ is already full, don't bother */ | |
7074 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) | |
7075 | break; | |
7076 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); | |
7077 | if (!rqb_buffer) | |
7078 | break; | |
7079 | rqb_buffer->hrq = hrq; | |
7080 | rqb_buffer->drq = drq; | |
a8cf5dfe | 7081 | rqb_buffer->idx = idx; |
6c621a22 JS |
7082 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
7083 | } | |
7084 | while (!list_empty(&rqb_buf_list)) { | |
7085 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, | |
7086 | hbuf.list); | |
7087 | ||
7088 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); | |
7089 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); | |
7090 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); | |
7091 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); | |
7092 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); | |
7093 | if (rc < 0) { | |
411de511 JS |
7094 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7095 | "6421 Cannot post to HRQ %d: %x %x %x " | |
7096 | "DRQ %x %x\n", | |
7097 | hrq->queue_id, | |
7098 | hrq->host_index, | |
7099 | hrq->hba_index, | |
7100 | hrq->entry_count, | |
7101 | drq->host_index, | |
7102 | drq->hba_index); | |
6c621a22 JS |
7103 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
7104 | } else { | |
7105 | list_add_tail(&rqb_buffer->hbuf.list, | |
7106 | &rqbp->rqb_buffer_list); | |
7107 | rqbp->buffer_count++; | |
7108 | } | |
7109 | } | |
411de511 | 7110 | spin_unlock_irqrestore(&phba->hbalock, flags); |
6c621a22 JS |
7111 | return 1; |
7112 | } | |
7113 | ||
da0436e9 | 7114 | /** |
183b8021 | 7115 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
da0436e9 JS |
7116 | * @phba: Pointer to HBA context object. |
7117 | * | |
183b8021 MY |
7118 | * This function is the main SLI4 device initialization PCI function. This |
7119 | * function is called by the HBA initialization code, HBA reset code and | |
da0436e9 JS |
7120 | * HBA error attention handler code. Caller is not required to hold any |
7121 | * locks. | |
7122 | **/ | |
7123 | int | |
7124 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
7125 | { | |
6c621a22 | 7126 | int rc, i, cnt; |
da0436e9 JS |
7127 | LPFC_MBOXQ_t *mboxq; |
7128 | struct lpfc_mqe *mqe; | |
7129 | uint8_t *vpd; | |
7130 | uint32_t vpd_size; | |
7131 | uint32_t ftr_rsp = 0; | |
7132 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
7133 | struct lpfc_vport *vport = phba->pport; | |
7134 | struct lpfc_dmabuf *mp; | |
2d7dbc4c | 7135 | struct lpfc_rqb *rqbp; |
da0436e9 JS |
7136 | |
7137 | /* Perform a PCI function reset to start from clean */ | |
7138 | rc = lpfc_pci_function_reset(phba); | |
7139 | if (unlikely(rc)) | |
7140 | return -ENODEV; | |
7141 | ||
7142 | /* Check the HBA Host Status Register for readyness */ | |
7143 | rc = lpfc_sli4_post_status_check(phba); | |
7144 | if (unlikely(rc)) | |
7145 | return -ENODEV; | |
7146 | else { | |
7147 | spin_lock_irq(&phba->hbalock); | |
7148 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
7149 | spin_unlock_irq(&phba->hbalock); | |
7150 | } | |
7151 | ||
7152 | /* | |
7153 | * Allocate a single mailbox container for initializing the | |
7154 | * port. | |
7155 | */ | |
7156 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7157 | if (!mboxq) | |
7158 | return -ENOMEM; | |
7159 | ||
da0436e9 | 7160 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 7161 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
7162 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
7163 | if (!vpd) { | |
7164 | rc = -ENOMEM; | |
7165 | goto out_free_mbox; | |
7166 | } | |
7167 | ||
7168 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
7169 | if (unlikely(rc)) { |
7170 | kfree(vpd); | |
7171 | goto out_free_mbox; | |
7172 | } | |
572709e2 | 7173 | |
da0436e9 | 7174 | mqe = &mboxq->u.mqe; |
f1126688 | 7175 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
b5c53958 | 7176 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
76a95d75 | 7177 | phba->hba_flag |= HBA_FCOE_MODE; |
b5c53958 JS |
7178 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
7179 | } else { | |
76a95d75 | 7180 | phba->hba_flag &= ~HBA_FCOE_MODE; |
b5c53958 | 7181 | } |
45ed1190 JS |
7182 | |
7183 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
7184 | LPFC_DCBX_CEE_MODE) | |
7185 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
7186 | else | |
7187 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
7188 | ||
4f2e66c6 JS |
7189 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
7190 | ||
c31098ce | 7191 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
7192 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7193 | "0376 READ_REV Error. SLI Level %d " | |
7194 | "FCoE enabled %d\n", | |
76a95d75 | 7195 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 7196 | rc = -EIO; |
76a95d75 JS |
7197 | kfree(vpd); |
7198 | goto out_free_mbox; | |
da0436e9 | 7199 | } |
cd1c8301 | 7200 | |
ff78d8f9 JS |
7201 | /* |
7202 | * Continue initialization with default values even if driver failed | |
7203 | * to read FCoE param config regions, only read parameters if the | |
7204 | * board is FCoE | |
7205 | */ | |
7206 | if (phba->hba_flag & HBA_FCOE_MODE && | |
7207 | lpfc_sli4_read_fcoe_params(phba)) | |
7208 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
7209 | "2570 Failed to read FCoE parameters\n"); | |
7210 | ||
cd1c8301 JS |
7211 | /* |
7212 | * Retrieve sli4 device physical port name, failure of doing it | |
7213 | * is considered as non-fatal. | |
7214 | */ | |
7215 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
7216 | if (!rc) | |
7217 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7218 | "3080 Successful retrieving SLI4 device " | |
7219 | "physical port name: %s.\n", phba->Port); | |
7220 | ||
da0436e9 JS |
7221 | /* |
7222 | * Evaluate the read rev and vpd data. Populate the driver | |
7223 | * state with the results. If this routine fails, the failure | |
7224 | * is not fatal as the driver will use generic values. | |
7225 | */ | |
7226 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
7227 | if (unlikely(!rc)) { | |
7228 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7229 | "0377 Error %d parsing vpd. " | |
7230 | "Using defaults.\n", rc); | |
7231 | rc = 0; | |
7232 | } | |
76a95d75 | 7233 | kfree(vpd); |
da0436e9 | 7234 | |
f1126688 JS |
7235 | /* Save information as VPD data */ |
7236 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
7237 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
4e565cf0 JS |
7238 | |
7239 | /* | |
7240 | * This is because first G7 ASIC doesn't support the standard | |
7241 | * 0x5a NVME cmd descriptor type/subtype | |
7242 | */ | |
7243 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
7244 | LPFC_SLI_INTF_IF_TYPE_6) && | |
7245 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && | |
7246 | (phba->vpd.rev.smRev == 0) && | |
7247 | (phba->cfg_nvme_embed_cmd == 1)) | |
7248 | phba->cfg_nvme_embed_cmd = 0; | |
7249 | ||
f1126688 JS |
7250 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
7251 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
7252 | &mqe->un.read_rev); | |
7253 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
7254 | &mqe->un.read_rev); | |
7255 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
7256 | &mqe->un.read_rev); | |
7257 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
7258 | &mqe->un.read_rev); | |
7259 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
7260 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
7261 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
7262 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
7263 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
7264 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
7265 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7266 | "(%d):0380 READ_REV Status x%x " | |
7267 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
7268 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7269 | bf_get(lpfc_mqe_status, mqe), | |
7270 | phba->vpd.rev.opFwName, | |
7271 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
7272 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 | 7273 | |
572709e2 JS |
7274 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
7275 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); | |
7276 | if (phba->pport->cfg_lun_queue_depth > rc) { | |
7277 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7278 | "3362 LUN queue depth changed from %d to %d\n", | |
7279 | phba->pport->cfg_lun_queue_depth, rc); | |
7280 | phba->pport->cfg_lun_queue_depth = rc; | |
7281 | } | |
7282 | ||
65791f1f | 7283 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
7bdedb34 JS |
7284 | LPFC_SLI_INTF_IF_TYPE_0) { |
7285 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); | |
7286 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7287 | if (rc == MBX_SUCCESS) { | |
7288 | phba->hba_flag |= HBA_RECOVERABLE_UE; | |
7289 | /* Set 1Sec interval to detect UE */ | |
7290 | phba->eratt_poll_interval = 1; | |
7291 | phba->sli4_hba.ue_to_sr = bf_get( | |
7292 | lpfc_mbx_set_feature_UESR, | |
7293 | &mboxq->u.mqe.un.set_feature); | |
7294 | phba->sli4_hba.ue_to_rp = bf_get( | |
7295 | lpfc_mbx_set_feature_UERP, | |
7296 | &mboxq->u.mqe.un.set_feature); | |
7297 | } | |
7298 | } | |
7299 | ||
7300 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { | |
7301 | /* Enable MDS Diagnostics only if the SLI Port supports it */ | |
7302 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); | |
7303 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7304 | if (rc != MBX_SUCCESS) | |
7305 | phba->mds_diags_support = 0; | |
7306 | } | |
572709e2 | 7307 | |
da0436e9 JS |
7308 | /* |
7309 | * Discover the port's supported feature set and match it against the | |
7310 | * hosts requests. | |
7311 | */ | |
7312 | lpfc_request_features(phba, mboxq); | |
7313 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7314 | if (unlikely(rc)) { | |
7315 | rc = -EIO; | |
76a95d75 | 7316 | goto out_free_mbox; |
da0436e9 JS |
7317 | } |
7318 | ||
7319 | /* | |
7320 | * The port must support FCP initiator mode as this is the | |
7321 | * only mode running in the host. | |
7322 | */ | |
7323 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
7324 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
7325 | "0378 No support for fcpi mode.\n"); | |
7326 | ftr_rsp++; | |
7327 | } | |
0bc2b7c5 JS |
7328 | |
7329 | /* Performance Hints are ONLY for FCoE */ | |
7330 | if (phba->hba_flag & HBA_FCOE_MODE) { | |
7331 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) | |
7332 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
7333 | else | |
7334 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
7335 | } | |
7336 | ||
da0436e9 JS |
7337 | /* |
7338 | * If the port cannot support the host's requested features | |
7339 | * then turn off the global config parameters to disable the | |
7340 | * feature in the driver. This is not a fatal error. | |
7341 | */ | |
f44ac12f JS |
7342 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
7343 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { | |
7344 | phba->cfg_enable_bg = 0; | |
7345 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; | |
bf08611b | 7346 | ftr_rsp++; |
f44ac12f | 7347 | } |
bf08611b | 7348 | } |
da0436e9 JS |
7349 | |
7350 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
7351 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
7352 | ftr_rsp++; | |
7353 | ||
7354 | if (ftr_rsp) { | |
7355 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
7356 | "0379 Feature Mismatch Data: x%08x %08x " | |
7357 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
7358 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
7359 | phba->cfg_enable_npiv, phba->max_vpi); | |
7360 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
7361 | phba->cfg_enable_bg = 0; | |
7362 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
7363 | phba->cfg_enable_npiv = 0; | |
7364 | } | |
7365 | ||
7366 | /* These SLI3 features are assumed in SLI4 */ | |
7367 | spin_lock_irq(&phba->hbalock); | |
7368 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
7369 | spin_unlock_irq(&phba->hbalock); | |
7370 | ||
6d368e53 JS |
7371 | /* |
7372 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
7373 | * calls depends on these resources to complete port setup. | |
7374 | */ | |
7375 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
7376 | if (rc) { | |
7377 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7378 | "2920 Failed to alloc Resource IDs " | |
7379 | "rc = x%x\n", rc); | |
7380 | goto out_free_mbox; | |
7381 | } | |
7382 | ||
61bda8f7 JS |
7383 | lpfc_set_host_data(phba, mboxq); |
7384 | ||
7385 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7386 | if (rc) { | |
7387 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
7388 | "2134 Failed to set host os driver version %x", | |
7389 | rc); | |
7390 | } | |
7391 | ||
da0436e9 | 7392 | /* Read the port's service parameters. */ |
9f1177a3 JS |
7393 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
7394 | if (rc) { | |
7395 | phba->link_state = LPFC_HBA_ERROR; | |
7396 | rc = -ENOMEM; | |
76a95d75 | 7397 | goto out_free_mbox; |
9f1177a3 JS |
7398 | } |
7399 | ||
da0436e9 JS |
7400 | mboxq->vport = vport; |
7401 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
3e1f0718 | 7402 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
da0436e9 JS |
7403 | if (rc == MBX_SUCCESS) { |
7404 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
7405 | rc = 0; | |
7406 | } | |
7407 | ||
7408 | /* | |
7409 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
7410 | * it to the mbuf pool. | |
7411 | */ | |
7412 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
7413 | kfree(mp); | |
3e1f0718 | 7414 | mboxq->ctx_buf = NULL; |
da0436e9 JS |
7415 | if (unlikely(rc)) { |
7416 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7417 | "0382 READ_SPARAM command failed " | |
7418 | "status %d, mbxStatus x%x\n", | |
7419 | rc, bf_get(lpfc_mqe_status, mqe)); | |
7420 | phba->link_state = LPFC_HBA_ERROR; | |
7421 | rc = -EIO; | |
76a95d75 | 7422 | goto out_free_mbox; |
da0436e9 JS |
7423 | } |
7424 | ||
0558056c | 7425 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
7426 | |
7427 | /* Update the fc_host data structures with new wwn. */ | |
7428 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
7429 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
7430 | ||
895427bd JS |
7431 | /* Create all the SLI4 queues */ |
7432 | rc = lpfc_sli4_queue_create(phba); | |
7433 | if (rc) { | |
7434 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7435 | "3089 Failed to allocate queues\n"); | |
7436 | rc = -ENODEV; | |
7437 | goto out_free_mbox; | |
7438 | } | |
7439 | /* Set up all the queues to the device */ | |
7440 | rc = lpfc_sli4_queue_setup(phba); | |
7441 | if (unlikely(rc)) { | |
7442 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7443 | "0381 Error %d during queue setup.\n ", rc); | |
7444 | goto out_stop_timers; | |
7445 | } | |
7446 | /* Initialize the driver internal SLI layer lists. */ | |
7447 | lpfc_sli4_setup(phba); | |
7448 | lpfc_sli4_queue_init(phba); | |
7449 | ||
7450 | /* update host els xri-sgl sizes and mappings */ | |
7451 | rc = lpfc_sli4_els_sgl_update(phba); | |
8a9d2e80 JS |
7452 | if (unlikely(rc)) { |
7453 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7454 | "1400 Failed to update xri-sgl size and " | |
7455 | "mapping: %d\n", rc); | |
895427bd | 7456 | goto out_destroy_queue; |
da0436e9 JS |
7457 | } |
7458 | ||
8a9d2e80 | 7459 | /* register the els sgl pool to the port */ |
895427bd JS |
7460 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
7461 | phba->sli4_hba.els_xri_cnt); | |
7462 | if (unlikely(rc < 0)) { | |
8a9d2e80 JS |
7463 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
7464 | "0582 Error %d during els sgl post " | |
7465 | "operation\n", rc); | |
7466 | rc = -ENODEV; | |
895427bd | 7467 | goto out_destroy_queue; |
8a9d2e80 | 7468 | } |
895427bd | 7469 | phba->sli4_hba.els_xri_cnt = rc; |
8a9d2e80 | 7470 | |
f358dd0c JS |
7471 | if (phba->nvmet_support) { |
7472 | /* update host nvmet xri-sgl sizes and mappings */ | |
7473 | rc = lpfc_sli4_nvmet_sgl_update(phba); | |
7474 | if (unlikely(rc)) { | |
7475 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7476 | "6308 Failed to update nvmet-sgl size " | |
7477 | "and mapping: %d\n", rc); | |
7478 | goto out_destroy_queue; | |
7479 | } | |
7480 | ||
7481 | /* register the nvmet sgl pool to the port */ | |
7482 | rc = lpfc_sli4_repost_sgl_list( | |
7483 | phba, | |
7484 | &phba->sli4_hba.lpfc_nvmet_sgl_list, | |
7485 | phba->sli4_hba.nvmet_xri_cnt); | |
7486 | if (unlikely(rc < 0)) { | |
7487 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7488 | "3117 Error %d during nvmet " | |
7489 | "sgl post\n", rc); | |
7490 | rc = -ENODEV; | |
7491 | goto out_destroy_queue; | |
7492 | } | |
7493 | phba->sli4_hba.nvmet_xri_cnt = rc; | |
6c621a22 JS |
7494 | |
7495 | cnt = phba->cfg_iocb_cnt * 1024; | |
7496 | /* We need 1 iocbq for every SGL, for IO processing */ | |
7497 | cnt += phba->sli4_hba.nvmet_xri_cnt; | |
f358dd0c | 7498 | } else { |
895427bd JS |
7499 | /* update host scsi xri-sgl sizes and mappings */ |
7500 | rc = lpfc_sli4_scsi_sgl_update(phba); | |
7501 | if (unlikely(rc)) { | |
7502 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7503 | "6309 Failed to update scsi-sgl size " | |
7504 | "and mapping: %d\n", rc); | |
7505 | goto out_destroy_queue; | |
7506 | } | |
7507 | ||
7508 | /* update host nvme xri-sgl sizes and mappings */ | |
7509 | rc = lpfc_sli4_nvme_sgl_update(phba); | |
7510 | if (unlikely(rc)) { | |
7511 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7512 | "6082 Failed to update nvme-sgl size " | |
7513 | "and mapping: %d\n", rc); | |
7514 | goto out_destroy_queue; | |
7515 | } | |
6c621a22 JS |
7516 | |
7517 | cnt = phba->cfg_iocb_cnt * 1024; | |
11e644e2 JS |
7518 | } |
7519 | ||
7520 | if (!phba->sli.iocbq_lookup) { | |
6c621a22 JS |
7521 | /* Initialize and populate the iocb list per host */ |
7522 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
11e644e2 | 7523 | "2821 initialize iocb list %d total %d\n", |
6c621a22 JS |
7524 | phba->cfg_iocb_cnt, cnt); |
7525 | rc = lpfc_init_iocb_list(phba, cnt); | |
7526 | if (rc) { | |
7527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11e644e2 | 7528 | "1413 Failed to init iocb list.\n"); |
6c621a22 JS |
7529 | goto out_destroy_queue; |
7530 | } | |
895427bd JS |
7531 | } |
7532 | ||
11e644e2 JS |
7533 | if (phba->nvmet_support) |
7534 | lpfc_nvmet_create_targetport(phba); | |
7535 | ||
2d7dbc4c | 7536 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
2d7dbc4c JS |
7537 | /* Post initial buffers to all RQs created */ |
7538 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { | |
7539 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; | |
7540 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); | |
7541 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; | |
7542 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; | |
61f3d4bf | 7543 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
2d7dbc4c JS |
7544 | rqbp->buffer_count = 0; |
7545 | ||
2d7dbc4c JS |
7546 | lpfc_post_rq_buffer( |
7547 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], | |
7548 | phba->sli4_hba.nvmet_mrq_data[i], | |
2448e484 | 7549 | phba->cfg_nvmet_mrq_post, i); |
2d7dbc4c JS |
7550 | } |
7551 | } | |
7552 | ||
895427bd JS |
7553 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
7554 | /* register the allocated scsi sgl pool to the port */ | |
7555 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
7556 | if (unlikely(rc)) { | |
7557 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7558 | "0383 Error %d during scsi sgl post " | |
7559 | "operation\n", rc); | |
7560 | /* Some Scsi buffers were moved to abort scsi list */ | |
7561 | /* A pci function reset will repost them */ | |
7562 | rc = -ENODEV; | |
7563 | goto out_destroy_queue; | |
7564 | } | |
da0436e9 JS |
7565 | } |
7566 | ||
01649561 JS |
7567 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
7568 | (phba->nvmet_support == 0)) { | |
7569 | ||
7570 | /* register the allocated nvme sgl pool to the port */ | |
7571 | rc = lpfc_repost_nvme_sgl_list(phba); | |
7572 | if (unlikely(rc)) { | |
7573 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7574 | "6116 Error %d during nvme sgl post " | |
7575 | "operation\n", rc); | |
7576 | /* Some NVME buffers were moved to abort nvme list */ | |
7577 | /* A pci function reset will repost them */ | |
7578 | rc = -ENODEV; | |
7579 | goto out_destroy_queue; | |
7580 | } | |
da0436e9 JS |
7581 | } |
7582 | ||
7583 | /* Post the rpi header region to the device. */ | |
7584 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
7585 | if (unlikely(rc)) { | |
7586 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7587 | "0393 Error %d during rpi post operation\n", | |
7588 | rc); | |
7589 | rc = -ENODEV; | |
895427bd | 7590 | goto out_destroy_queue; |
da0436e9 | 7591 | } |
97f2ecf1 | 7592 | lpfc_sli4_node_prep(phba); |
da0436e9 | 7593 | |
895427bd | 7594 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
2d7dbc4c | 7595 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
895427bd JS |
7596 | /* |
7597 | * The FC Port needs to register FCFI (index 0) | |
7598 | */ | |
7599 | lpfc_reg_fcfi(phba, mboxq); | |
7600 | mboxq->vport = phba->pport; | |
7601 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7602 | if (rc != MBX_SUCCESS) | |
7603 | goto out_unset_queue; | |
7604 | rc = 0; | |
7605 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
7606 | &mboxq->u.mqe.un.reg_fcfi); | |
2d7dbc4c JS |
7607 | } else { |
7608 | /* We are a NVME Target mode with MRQ > 1 */ | |
7609 | ||
7610 | /* First register the FCFI */ | |
7611 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); | |
7612 | mboxq->vport = phba->pport; | |
7613 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7614 | if (rc != MBX_SUCCESS) | |
7615 | goto out_unset_queue; | |
7616 | rc = 0; | |
7617 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, | |
7618 | &mboxq->u.mqe.un.reg_fcfi_mrq); | |
7619 | ||
7620 | /* Next register the MRQs */ | |
7621 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); | |
7622 | mboxq->vport = phba->pport; | |
7623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7624 | if (rc != MBX_SUCCESS) | |
7625 | goto out_unset_queue; | |
7626 | rc = 0; | |
895427bd JS |
7627 | } |
7628 | /* Check if the port is configured to be disabled */ | |
7629 | lpfc_sli_read_link_ste(phba); | |
da0436e9 JS |
7630 | } |
7631 | ||
7632 | /* Arm the CQs and then EQs on device */ | |
7633 | lpfc_sli4_arm_cqeq_intr(phba); | |
7634 | ||
7635 | /* Indicate device interrupt mode */ | |
7636 | phba->sli4_hba.intr_enable = 1; | |
7637 | ||
7638 | /* Allow asynchronous mailbox command to go through */ | |
7639 | spin_lock_irq(&phba->hbalock); | |
7640 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7641 | spin_unlock_irq(&phba->hbalock); | |
7642 | ||
7643 | /* Post receive buffers to the device */ | |
7644 | lpfc_sli4_rb_setup(phba); | |
7645 | ||
fc2b989b JS |
7646 | /* Reset HBA FCF states after HBA reset */ |
7647 | phba->fcf.fcf_flag = 0; | |
7648 | phba->fcf.current_rec.flag = 0; | |
7649 | ||
da0436e9 | 7650 | /* Start the ELS watchdog timer */ |
8fa38513 | 7651 | mod_timer(&vport->els_tmofunc, |
256ec0d0 | 7652 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
da0436e9 JS |
7653 | |
7654 | /* Start heart beat timer */ | |
7655 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 | 7656 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
da0436e9 JS |
7657 | phba->hb_outstanding = 0; |
7658 | phba->last_completion_time = jiffies; | |
7659 | ||
7660 | /* Start error attention (ERATT) polling timer */ | |
256ec0d0 | 7661 | mod_timer(&phba->eratt_poll, |
65791f1f | 7662 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
da0436e9 | 7663 | |
75baf696 JS |
7664 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
7665 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
7666 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
7667 | if (!rc) { | |
7668 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7669 | "2829 This device supports " | |
7670 | "Advanced Error Reporting (AER)\n"); | |
7671 | spin_lock_irq(&phba->hbalock); | |
7672 | phba->hba_flag |= HBA_AER_ENABLED; | |
7673 | spin_unlock_irq(&phba->hbalock); | |
7674 | } else { | |
7675 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7676 | "2830 This device does not support " | |
7677 | "Advanced Error Reporting (AER)\n"); | |
7678 | phba->cfg_aer_support = 0; | |
7679 | } | |
0a96e975 | 7680 | rc = 0; |
75baf696 JS |
7681 | } |
7682 | ||
da0436e9 JS |
7683 | /* |
7684 | * The port is ready, set the host's link state to LINK_DOWN | |
7685 | * in preparation for link interrupts. | |
7686 | */ | |
da0436e9 JS |
7687 | spin_lock_irq(&phba->hbalock); |
7688 | phba->link_state = LPFC_LINK_DOWN; | |
1dc5ec24 JS |
7689 | |
7690 | /* Check if physical ports are trunked */ | |
7691 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) | |
7692 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; | |
7693 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) | |
7694 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; | |
7695 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) | |
7696 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; | |
7697 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) | |
7698 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; | |
da0436e9 | 7699 | spin_unlock_irq(&phba->hbalock); |
1dc5ec24 | 7700 | |
026abb87 JS |
7701 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
7702 | (phba->hba_flag & LINK_DISABLED)) { | |
7703 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
7704 | "3103 Adapter Link is disabled.\n"); | |
7705 | lpfc_down_link(phba, mboxq); | |
7706 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7707 | if (rc != MBX_SUCCESS) { | |
7708 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
7709 | "3104 Adapter failed to issue " | |
7710 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
7711 | goto out_unset_queue; | |
7712 | } | |
7713 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
1b51197d JS |
7714 | /* don't perform init_link on SLI4 FC port loopback test */ |
7715 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { | |
7716 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
7717 | if (rc) | |
7718 | goto out_unset_queue; | |
7719 | } | |
5350d872 JS |
7720 | } |
7721 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7722 | return rc; | |
76a95d75 | 7723 | out_unset_queue: |
da0436e9 | 7724 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
7725 | lpfc_sli4_queue_unset(phba); |
7726 | out_destroy_queue: | |
6c621a22 | 7727 | lpfc_free_iocb_list(phba); |
5350d872 | 7728 | lpfc_sli4_queue_destroy(phba); |
da0436e9 | 7729 | out_stop_timers: |
5350d872 | 7730 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
7731 | out_free_mbox: |
7732 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7733 | return rc; | |
7734 | } | |
7735 | ||
7736 | /** | |
7737 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
7738 | * @ptr: context object - pointer to hba structure. | |
7739 | * | |
7740 | * This is the callback function for mailbox timer. The mailbox | |
7741 | * timer is armed when a new mailbox command is issued and the timer | |
7742 | * is deleted when the mailbox complete. The function is called by | |
7743 | * the kernel timer code when a mailbox does not complete within | |
7744 | * expected time. This function wakes up the worker thread to | |
7745 | * process the mailbox timeout and returns. All the processing is | |
7746 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
7747 | **/ | |
7748 | void | |
f22eb4d3 | 7749 | lpfc_mbox_timeout(struct timer_list *t) |
da0436e9 | 7750 | { |
f22eb4d3 | 7751 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
da0436e9 JS |
7752 | unsigned long iflag; |
7753 | uint32_t tmo_posted; | |
7754 | ||
7755 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
7756 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
7757 | if (!tmo_posted) | |
7758 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
7759 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
7760 | ||
7761 | if (!tmo_posted) | |
7762 | lpfc_worker_wake_up(phba); | |
7763 | return; | |
7764 | } | |
7765 | ||
e8d3c3b1 JS |
7766 | /** |
7767 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions | |
7768 | * are pending | |
7769 | * @phba: Pointer to HBA context object. | |
7770 | * | |
7771 | * This function checks if any mailbox completions are present on the mailbox | |
7772 | * completion queue. | |
7773 | **/ | |
3bb11fc5 | 7774 | static bool |
e8d3c3b1 JS |
7775 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
7776 | { | |
7777 | ||
7778 | uint32_t idx; | |
7779 | struct lpfc_queue *mcq; | |
7780 | struct lpfc_mcqe *mcqe; | |
7781 | bool pending_completions = false; | |
7365f6fd | 7782 | uint8_t qe_valid; |
e8d3c3b1 JS |
7783 | |
7784 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
7785 | return false; | |
7786 | ||
7787 | /* Check for completions on mailbox completion queue */ | |
7788 | ||
7789 | mcq = phba->sli4_hba.mbx_cq; | |
7790 | idx = mcq->hba_index; | |
7365f6fd JS |
7791 | qe_valid = mcq->qe_valid; |
7792 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe) == qe_valid) { | |
e8d3c3b1 JS |
7793 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
7794 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && | |
7795 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { | |
7796 | pending_completions = true; | |
7797 | break; | |
7798 | } | |
7799 | idx = (idx + 1) % mcq->entry_count; | |
7800 | if (mcq->hba_index == idx) | |
7801 | break; | |
7365f6fd JS |
7802 | |
7803 | /* if the index wrapped around, toggle the valid bit */ | |
7804 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) | |
7805 | qe_valid = (qe_valid) ? 0 : 1; | |
e8d3c3b1 JS |
7806 | } |
7807 | return pending_completions; | |
7808 | ||
7809 | } | |
7810 | ||
7811 | /** | |
7812 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions | |
7813 | * that were missed. | |
7814 | * @phba: Pointer to HBA context object. | |
7815 | * | |
7816 | * For sli4, it is possible to miss an interrupt. As such mbox completions | |
7817 | * maybe missed causing erroneous mailbox timeouts to occur. This function | |
7818 | * checks to see if mbox completions are on the mailbox completion queue | |
7819 | * and will process all the completions associated with the eq for the | |
7820 | * mailbox completion queue. | |
7821 | **/ | |
7822 | bool | |
7823 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) | |
7824 | { | |
b71413dd | 7825 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
e8d3c3b1 JS |
7826 | uint32_t eqidx; |
7827 | struct lpfc_queue *fpeq = NULL; | |
7828 | struct lpfc_eqe *eqe; | |
7829 | bool mbox_pending; | |
7830 | ||
7831 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) | |
7832 | return false; | |
7833 | ||
7834 | /* Find the eq associated with the mcq */ | |
7835 | ||
b71413dd | 7836 | if (sli4_hba->hba_eq) |
895427bd | 7837 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
b71413dd JS |
7838 | if (sli4_hba->hba_eq[eqidx]->queue_id == |
7839 | sli4_hba->mbx_cq->assoc_qid) { | |
7840 | fpeq = sli4_hba->hba_eq[eqidx]; | |
e8d3c3b1 JS |
7841 | break; |
7842 | } | |
7843 | if (!fpeq) | |
7844 | return false; | |
7845 | ||
7846 | /* Turn off interrupts from this EQ */ | |
7847 | ||
b71413dd | 7848 | sli4_hba->sli4_eq_clr_intr(fpeq); |
e8d3c3b1 JS |
7849 | |
7850 | /* Check to see if a mbox completion is pending */ | |
7851 | ||
7852 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); | |
7853 | ||
7854 | /* | |
7855 | * If a mbox completion is pending, process all the events on EQ | |
7856 | * associated with the mbox completion queue (this could include | |
7857 | * mailbox commands, async events, els commands, receive queue data | |
7858 | * and fcp commands) | |
7859 | */ | |
7860 | ||
7861 | if (mbox_pending) | |
7862 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
7863 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); | |
7864 | fpeq->EQ_processed++; | |
7865 | } | |
7866 | ||
7867 | /* Always clear and re-arm the EQ */ | |
7868 | ||
b71413dd | 7869 | sli4_hba->sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
e8d3c3b1 JS |
7870 | |
7871 | return mbox_pending; | |
7872 | ||
7873 | } | |
da0436e9 JS |
7874 | |
7875 | /** | |
7876 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
7877 | * @phba: Pointer to HBA context object. | |
7878 | * | |
7879 | * This function is called from worker thread when a mailbox command times out. | |
7880 | * The caller is not required to hold any locks. This function will reset the | |
7881 | * HBA and recover all the pending commands. | |
7882 | **/ | |
7883 | void | |
7884 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
7885 | { | |
7886 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
eb016566 JS |
7887 | MAILBOX_t *mb = NULL; |
7888 | ||
da0436e9 | 7889 | struct lpfc_sli *psli = &phba->sli; |
da0436e9 | 7890 | |
e8d3c3b1 JS |
7891 | /* If the mailbox completed, process the completion and return */ |
7892 | if (lpfc_sli4_process_missed_mbox_completions(phba)) | |
7893 | return; | |
7894 | ||
eb016566 JS |
7895 | if (pmbox != NULL) |
7896 | mb = &pmbox->u.mb; | |
da0436e9 JS |
7897 | /* Check the pmbox pointer first. There is a race condition |
7898 | * between the mbox timeout handler getting executed in the | |
7899 | * worklist and the mailbox actually completing. When this | |
7900 | * race condition occurs, the mbox_active will be NULL. | |
7901 | */ | |
7902 | spin_lock_irq(&phba->hbalock); | |
7903 | if (pmbox == NULL) { | |
7904 | lpfc_printf_log(phba, KERN_WARNING, | |
7905 | LOG_MBOX | LOG_SLI, | |
7906 | "0353 Active Mailbox cleared - mailbox timeout " | |
7907 | "exiting\n"); | |
7908 | spin_unlock_irq(&phba->hbalock); | |
7909 | return; | |
7910 | } | |
7911 | ||
7912 | /* Mbox cmd <mbxCommand> timeout */ | |
7913 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7914 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
7915 | mb->mbxCommand, | |
7916 | phba->pport->port_state, | |
7917 | phba->sli.sli_flag, | |
7918 | phba->sli.mbox_active); | |
7919 | spin_unlock_irq(&phba->hbalock); | |
7920 | ||
7921 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
7922 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 7923 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
7924 | */ |
7925 | spin_lock_irq(&phba->pport->work_port_lock); | |
7926 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
7927 | spin_unlock_irq(&phba->pport->work_port_lock); | |
7928 | spin_lock_irq(&phba->hbalock); | |
7929 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 7930 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
7931 | spin_unlock_irq(&phba->hbalock); |
7932 | ||
db55fba8 | 7933 | lpfc_sli_abort_fcp_rings(phba); |
da0436e9 JS |
7934 | |
7935 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7936 | "0345 Resetting board due to mailbox timeout\n"); | |
7937 | ||
7938 | /* Reset the HBA device */ | |
7939 | lpfc_reset_hba(phba); | |
7940 | } | |
7941 | ||
7942 | /** | |
7943 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
7944 | * @phba: Pointer to HBA context object. | |
7945 | * @pmbox: Pointer to mailbox object. | |
7946 | * @flag: Flag indicating how the mailbox need to be processed. | |
7947 | * | |
7948 | * This function is called by discovery code and HBA management code | |
7949 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
7950 | * function gets the hbalock to protect the data structures. | |
7951 | * The mailbox command can be submitted in polling mode, in which case | |
7952 | * this function will wait in a polling loop for the completion of the | |
7953 | * mailbox. | |
7954 | * If the mailbox is submitted in no_wait mode (not polling) the | |
7955 | * function will submit the command and returns immediately without waiting | |
7956 | * for the mailbox completion. The no_wait is supported only when HBA | |
7957 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
7958 | * The SLI interface allows only one mailbox pending at a time. If the | |
7959 | * mailbox is issued in polling mode and there is already a mailbox | |
7960 | * pending, then the function will return an error. If the mailbox is issued | |
7961 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
7962 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
7963 | * The sli layer owns the mailbox object until the completion of mailbox | |
7964 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
7965 | * return codes the caller owns the mailbox command after the return of | |
7966 | * the function. | |
e59058c4 | 7967 | **/ |
3772a991 JS |
7968 | static int |
7969 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
7970 | uint32_t flag) | |
dea3101e | 7971 | { |
bf07bdea | 7972 | MAILBOX_t *mbx; |
2e0fef85 | 7973 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 7974 | uint32_t status, evtctr; |
9940b97b | 7975 | uint32_t ha_copy, hc_copy; |
dea3101e | 7976 | int i; |
09372820 | 7977 | unsigned long timeout; |
dea3101e | 7978 | unsigned long drvr_flag = 0; |
34b02dcd | 7979 | uint32_t word0, ldata; |
dea3101e | 7980 | void __iomem *to_slim; |
58da1ffb JS |
7981 | int processing_queue = 0; |
7982 | ||
7983 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
7984 | if (!pmbox) { | |
8568a4d2 | 7985 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 7986 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
7987 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
7988 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7989 | return MBX_SUCCESS; | |
7990 | } | |
58da1ffb | 7991 | processing_queue = 1; |
58da1ffb JS |
7992 | pmbox = lpfc_mbox_get(phba); |
7993 | if (!pmbox) { | |
7994 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
7995 | return MBX_SUCCESS; | |
7996 | } | |
7997 | } | |
dea3101e | 7998 | |
ed957684 | 7999 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 8000 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 8001 | if(!pmbox->vport) { |
58da1ffb | 8002 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 8003 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 8004 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 8005 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 8006 | pmbox->u.mb.mbxCommand); |
ed957684 | 8007 | dump_stack(); |
58da1ffb | 8008 | goto out_not_finished; |
ed957684 JS |
8009 | } |
8010 | } | |
8011 | ||
8d63f375 | 8012 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
8013 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
8014 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
8015 | goto out_not_finished; | |
8016 | } | |
8d63f375 | 8017 | |
a257bf90 JS |
8018 | /* If HBA has a deferred error attention, fail the iocb. */ |
8019 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
8020 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
8021 | goto out_not_finished; | |
8022 | } | |
8023 | ||
dea3101e | 8024 | psli = &phba->sli; |
92d7f7b0 | 8025 | |
bf07bdea | 8026 | mbx = &pmbox->u.mb; |
dea3101e JB |
8027 | status = MBX_SUCCESS; |
8028 | ||
2e0fef85 JS |
8029 | if (phba->link_state == LPFC_HBA_ERROR) { |
8030 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
8031 | |
8032 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
8033 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
8034 | "(%d):0311 Mailbox command x%x cannot " | |
8035 | "issue Data: x%x x%x\n", | |
8036 | pmbox->vport ? pmbox->vport->vpi : 0, | |
8037 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 8038 | goto out_not_finished; |
41415862 JW |
8039 | } |
8040 | ||
bf07bdea | 8041 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
9940b97b JS |
8042 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
8043 | !(hc_copy & HC_MBINT_ENA)) { | |
8044 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
8045 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
8046 | "(%d):2528 Mailbox command x%x cannot " |
8047 | "issue Data: x%x x%x\n", | |
8048 | pmbox->vport ? pmbox->vport->vpi : 0, | |
8049 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
8050 | goto out_not_finished; |
8051 | } | |
9290831f JS |
8052 | } |
8053 | ||
dea3101e JB |
8054 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
8055 | /* Polling for a mbox command when another one is already active | |
8056 | * is not allowed in SLI. Also, the driver must have established | |
8057 | * SLI2 mode to queue and process multiple mbox commands. | |
8058 | */ | |
8059 | ||
8060 | if (flag & MBX_POLL) { | |
2e0fef85 | 8061 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
8062 | |
8063 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
8064 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
8065 | "(%d):2529 Mailbox command x%x " | |
8066 | "cannot issue Data: x%x x%x\n", | |
8067 | pmbox->vport ? pmbox->vport->vpi : 0, | |
8068 | pmbox->u.mb.mbxCommand, | |
8069 | psli->sli_flag, flag); | |
58da1ffb | 8070 | goto out_not_finished; |
dea3101e JB |
8071 | } |
8072 | ||
3772a991 | 8073 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 8074 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 8075 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
8076 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
8077 | "(%d):2530 Mailbox command x%x " | |
8078 | "cannot issue Data: x%x x%x\n", | |
8079 | pmbox->vport ? pmbox->vport->vpi : 0, | |
8080 | pmbox->u.mb.mbxCommand, | |
8081 | psli->sli_flag, flag); | |
58da1ffb | 8082 | goto out_not_finished; |
dea3101e JB |
8083 | } |
8084 | ||
dea3101e JB |
8085 | /* Another mailbox command is still being processed, queue this |
8086 | * command to be processed later. | |
8087 | */ | |
8088 | lpfc_mbox_put(phba, pmbox); | |
8089 | ||
8090 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 8091 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 8092 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 8093 | "x%x x%x x%x x%x\n", |
92d7f7b0 | 8094 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
e92974f6 JS |
8095 | mbx->mbxCommand, |
8096 | phba->pport ? phba->pport->port_state : 0xff, | |
92d7f7b0 | 8097 | psli->sli_flag, flag); |
dea3101e JB |
8098 | |
8099 | psli->slistat.mbox_busy++; | |
2e0fef85 | 8100 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 8101 | |
858c9f6c JS |
8102 | if (pmbox->vport) { |
8103 | lpfc_debugfs_disc_trc(pmbox->vport, | |
8104 | LPFC_DISC_TRC_MBOX_VPORT, | |
8105 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
8106 | (uint32_t)mbx->mbxCommand, |
8107 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
8108 | } |
8109 | else { | |
8110 | lpfc_debugfs_disc_trc(phba->pport, | |
8111 | LPFC_DISC_TRC_MBOX, | |
8112 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
8113 | (uint32_t)mbx->mbxCommand, |
8114 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
8115 | } |
8116 | ||
2e0fef85 | 8117 | return MBX_BUSY; |
dea3101e JB |
8118 | } |
8119 | ||
dea3101e JB |
8120 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
8121 | ||
8122 | /* If we are not polling, we MUST be in SLI2 mode */ | |
8123 | if (flag != MBX_POLL) { | |
3772a991 | 8124 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
bf07bdea | 8125 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 8126 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 8127 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 8128 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
8129 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
8130 | "(%d):2531 Mailbox command x%x " | |
8131 | "cannot issue Data: x%x x%x\n", | |
8132 | pmbox->vport ? pmbox->vport->vpi : 0, | |
8133 | pmbox->u.mb.mbxCommand, | |
8134 | psli->sli_flag, flag); | |
58da1ffb | 8135 | goto out_not_finished; |
dea3101e JB |
8136 | } |
8137 | /* timeout active mbox command */ | |
256ec0d0 JS |
8138 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
8139 | 1000); | |
8140 | mod_timer(&psli->mbox_tmo, jiffies + timeout); | |
dea3101e JB |
8141 | } |
8142 | ||
8143 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 8144 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 8145 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 8146 | "x%x\n", |
e8b62011 | 8147 | pmbox->vport ? pmbox->vport->vpi : 0, |
e92974f6 JS |
8148 | mbx->mbxCommand, |
8149 | phba->pport ? phba->pport->port_state : 0xff, | |
92d7f7b0 | 8150 | psli->sli_flag, flag); |
dea3101e | 8151 | |
bf07bdea | 8152 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
858c9f6c JS |
8153 | if (pmbox->vport) { |
8154 | lpfc_debugfs_disc_trc(pmbox->vport, | |
8155 | LPFC_DISC_TRC_MBOX_VPORT, | |
8156 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
8157 | (uint32_t)mbx->mbxCommand, |
8158 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
8159 | } |
8160 | else { | |
8161 | lpfc_debugfs_disc_trc(phba->pport, | |
8162 | LPFC_DISC_TRC_MBOX, | |
8163 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
bf07bdea RD |
8164 | (uint32_t)mbx->mbxCommand, |
8165 | mbx->un.varWords[0], mbx->un.varWords[1]); | |
858c9f6c JS |
8166 | } |
8167 | } | |
8168 | ||
dea3101e JB |
8169 | psli->slistat.mbox_cmd++; |
8170 | evtctr = psli->slistat.mbox_event; | |
8171 | ||
8172 | /* next set own bit for the adapter and copy over command word */ | |
bf07bdea | 8173 | mbx->mbxOwner = OWN_CHIP; |
dea3101e | 8174 | |
3772a991 | 8175 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
8176 | /* Populate mbox extension offset word. */ |
8177 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
bf07bdea | 8178 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
8179 | = (uint8_t *)phba->mbox_ext |
8180 | - (uint8_t *)phba->mbox; | |
8181 | } | |
8182 | ||
8183 | /* Copy the mailbox extension data */ | |
3e1f0718 JS |
8184 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
8185 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, | |
8186 | (uint8_t *)phba->mbox_ext, | |
8187 | pmbox->in_ext_byte_len); | |
7a470277 JS |
8188 | } |
8189 | /* Copy command data to host SLIM area */ | |
bf07bdea | 8190 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 8191 | } else { |
7a470277 JS |
8192 | /* Populate mbox extension offset word. */ |
8193 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
bf07bdea | 8194 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
7a470277 JS |
8195 | = MAILBOX_HBA_EXT_OFFSET; |
8196 | ||
8197 | /* Copy the mailbox extension data */ | |
3e1f0718 | 8198 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
7a470277 JS |
8199 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
8200 | MAILBOX_HBA_EXT_OFFSET, | |
3e1f0718 | 8201 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
7a470277 | 8202 | |
895427bd | 8203 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
dea3101e | 8204 | /* copy command data into host mbox for cmpl */ |
895427bd JS |
8205 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
8206 | MAILBOX_CMD_SIZE); | |
dea3101e JB |
8207 | |
8208 | /* First copy mbox command data to HBA SLIM, skip past first | |
8209 | word */ | |
8210 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
bf07bdea | 8211 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
dea3101e JB |
8212 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
8213 | ||
8214 | /* Next copy over first word, with mbxOwner set */ | |
bf07bdea | 8215 | ldata = *((uint32_t *)mbx); |
dea3101e JB |
8216 | to_slim = phba->MBslimaddr; |
8217 | writel(ldata, to_slim); | |
8218 | readl(to_slim); /* flush */ | |
8219 | ||
895427bd | 8220 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
dea3101e | 8221 | /* switch over to host mailbox */ |
3772a991 | 8222 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
8223 | } |
8224 | ||
8225 | wmb(); | |
dea3101e JB |
8226 | |
8227 | switch (flag) { | |
8228 | case MBX_NOWAIT: | |
09372820 | 8229 | /* Set up reference to mailbox command */ |
dea3101e | 8230 | psli->mbox_active = pmbox; |
09372820 JS |
8231 | /* Interrupt board to do it */ |
8232 | writel(CA_MBATT, phba->CAregaddr); | |
8233 | readl(phba->CAregaddr); /* flush */ | |
8234 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
8235 | break; |
8236 | ||
8237 | case MBX_POLL: | |
09372820 | 8238 | /* Set up null reference to mailbox command */ |
dea3101e | 8239 | psli->mbox_active = NULL; |
09372820 JS |
8240 | /* Interrupt board to do it */ |
8241 | writel(CA_MBATT, phba->CAregaddr); | |
8242 | readl(phba->CAregaddr); /* flush */ | |
8243 | ||
3772a991 | 8244 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 8245 | /* First read mbox status word */ |
34b02dcd | 8246 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
8247 | word0 = le32_to_cpu(word0); |
8248 | } else { | |
8249 | /* First read mbox status word */ | |
9940b97b JS |
8250 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
8251 | spin_unlock_irqrestore(&phba->hbalock, | |
8252 | drvr_flag); | |
8253 | goto out_not_finished; | |
8254 | } | |
dea3101e JB |
8255 | } |
8256 | ||
8257 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
8258 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
8259 | spin_unlock_irqrestore(&phba->hbalock, | |
8260 | drvr_flag); | |
8261 | goto out_not_finished; | |
8262 | } | |
a183a15f JS |
8263 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
8264 | 1000) + jiffies; | |
09372820 | 8265 | i = 0; |
dea3101e | 8266 | /* Wait for command to complete */ |
41415862 JW |
8267 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
8268 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 8269 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 8270 | if (time_after(jiffies, timeout)) { |
dea3101e | 8271 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 8272 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 8273 | drvr_flag); |
58da1ffb | 8274 | goto out_not_finished; |
dea3101e JB |
8275 | } |
8276 | ||
8277 | /* Check if we took a mbox interrupt while we were | |
8278 | polling */ | |
8279 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
8280 | && (evtctr != psli->slistat.mbox_event)) | |
8281 | break; | |
8282 | ||
09372820 JS |
8283 | if (i++ > 10) { |
8284 | spin_unlock_irqrestore(&phba->hbalock, | |
8285 | drvr_flag); | |
8286 | msleep(1); | |
8287 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
8288 | } | |
dea3101e | 8289 | |
3772a991 | 8290 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 8291 | /* First copy command data */ |
34b02dcd | 8292 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 8293 | word0 = le32_to_cpu(word0); |
bf07bdea | 8294 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 8295 | MAILBOX_t *slimmb; |
34b02dcd | 8296 | uint32_t slimword0; |
dea3101e JB |
8297 | /* Check real SLIM for any errors */ |
8298 | slimword0 = readl(phba->MBslimaddr); | |
8299 | slimmb = (MAILBOX_t *) & slimword0; | |
8300 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
8301 | && slimmb->mbxStatus) { | |
8302 | psli->sli_flag &= | |
3772a991 | 8303 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
8304 | word0 = slimword0; |
8305 | } | |
8306 | } | |
8307 | } else { | |
8308 | /* First copy command data */ | |
8309 | word0 = readl(phba->MBslimaddr); | |
8310 | } | |
8311 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
8312 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
8313 | spin_unlock_irqrestore(&phba->hbalock, | |
8314 | drvr_flag); | |
8315 | goto out_not_finished; | |
8316 | } | |
dea3101e JB |
8317 | } |
8318 | ||
3772a991 | 8319 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 8320 | /* copy results back to user */ |
2ea259ee JS |
8321 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
8322 | MAILBOX_CMD_SIZE); | |
7a470277 | 8323 | /* Copy the mailbox extension data */ |
3e1f0718 | 8324 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
7a470277 | 8325 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
3e1f0718 | 8326 | pmbox->ctx_buf, |
7a470277 JS |
8327 | pmbox->out_ext_byte_len); |
8328 | } | |
dea3101e JB |
8329 | } else { |
8330 | /* First copy command data */ | |
bf07bdea | 8331 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
2ea259ee | 8332 | MAILBOX_CMD_SIZE); |
7a470277 | 8333 | /* Copy the mailbox extension data */ |
3e1f0718 JS |
8334 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
8335 | lpfc_memcpy_from_slim( | |
8336 | pmbox->ctx_buf, | |
7a470277 JS |
8337 | phba->MBslimaddr + |
8338 | MAILBOX_HBA_EXT_OFFSET, | |
8339 | pmbox->out_ext_byte_len); | |
dea3101e JB |
8340 | } |
8341 | } | |
8342 | ||
8343 | writel(HA_MBATT, phba->HAregaddr); | |
8344 | readl(phba->HAregaddr); /* flush */ | |
8345 | ||
8346 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
bf07bdea | 8347 | status = mbx->mbxStatus; |
dea3101e JB |
8348 | } |
8349 | ||
2e0fef85 JS |
8350 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
8351 | return status; | |
58da1ffb JS |
8352 | |
8353 | out_not_finished: | |
8354 | if (processing_queue) { | |
da0436e9 | 8355 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
8356 | lpfc_mbox_cmpl_put(phba, pmbox); |
8357 | } | |
8358 | return MBX_NOT_FINISHED; | |
dea3101e JB |
8359 | } |
8360 | ||
f1126688 JS |
8361 | /** |
8362 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
8363 | * @phba: Pointer to HBA context object. | |
8364 | * | |
8365 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
8366 | * the driver internal pending mailbox queue. It will then try to wait out the | |
8367 | * possible outstanding mailbox command before return. | |
8368 | * | |
8369 | * Returns: | |
8370 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
8371 | * the outstanding mailbox command timed out. | |
8372 | **/ | |
8373 | static int | |
8374 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
8375 | { | |
8376 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 8377 | int rc = 0; |
a183a15f | 8378 | unsigned long timeout = 0; |
f1126688 JS |
8379 | |
8380 | /* Mark the asynchronous mailbox command posting as blocked */ | |
8381 | spin_lock_irq(&phba->hbalock); | |
8382 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
8383 | /* Determine how long we might wait for the active mailbox |
8384 | * command to be gracefully completed by firmware. | |
8385 | */ | |
a183a15f JS |
8386 | if (phba->sli.mbox_active) |
8387 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
8388 | phba->sli.mbox_active) * | |
8389 | 1000) + jiffies; | |
8390 | spin_unlock_irq(&phba->hbalock); | |
8391 | ||
e8d3c3b1 JS |
8392 | /* Make sure the mailbox is really active */ |
8393 | if (timeout) | |
8394 | lpfc_sli4_process_missed_mbox_completions(phba); | |
8395 | ||
f1126688 JS |
8396 | /* Wait for the outstnading mailbox command to complete */ |
8397 | while (phba->sli.mbox_active) { | |
8398 | /* Check active mailbox complete status every 2ms */ | |
8399 | msleep(2); | |
8400 | if (time_after(jiffies, timeout)) { | |
8401 | /* Timeout, marked the outstanding cmd not complete */ | |
8402 | rc = 1; | |
8403 | break; | |
8404 | } | |
8405 | } | |
8406 | ||
8407 | /* Can not cleanly block async mailbox command, fails it */ | |
8408 | if (rc) { | |
8409 | spin_lock_irq(&phba->hbalock); | |
8410 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
8411 | spin_unlock_irq(&phba->hbalock); | |
8412 | } | |
8413 | return rc; | |
8414 | } | |
8415 | ||
8416 | /** | |
8417 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
8418 | * @phba: Pointer to HBA context object. | |
8419 | * | |
8420 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
8421 | * commands from the driver internal pending mailbox queue. It makes sure | |
8422 | * that there is no outstanding mailbox command before resuming posting | |
8423 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
8424 | * mailbox command, it will try to wait it out before resuming asynchronous | |
8425 | * mailbox command posting. | |
8426 | **/ | |
8427 | static void | |
8428 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
8429 | { | |
8430 | struct lpfc_sli *psli = &phba->sli; | |
8431 | ||
8432 | spin_lock_irq(&phba->hbalock); | |
8433 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
8434 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
8435 | spin_unlock_irq(&phba->hbalock); | |
8436 | return; | |
8437 | } | |
8438 | ||
8439 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
8440 | * successful or timeout, after timing-out the outstanding mailbox | |
8441 | * command shall always be removed, so just unblock posting async | |
8442 | * mailbox command and resume | |
8443 | */ | |
8444 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
8445 | spin_unlock_irq(&phba->hbalock); | |
8446 | ||
8447 | /* wake up worker thread to post asynchronlous mailbox command */ | |
8448 | lpfc_worker_wake_up(phba); | |
8449 | } | |
8450 | ||
2d843edc JS |
8451 | /** |
8452 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready | |
8453 | * @phba: Pointer to HBA context object. | |
8454 | * @mboxq: Pointer to mailbox object. | |
8455 | * | |
8456 | * The function waits for the bootstrap mailbox register ready bit from | |
8457 | * port for twice the regular mailbox command timeout value. | |
8458 | * | |
8459 | * 0 - no timeout on waiting for bootstrap mailbox register ready. | |
8460 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. | |
8461 | **/ | |
8462 | static int | |
8463 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8464 | { | |
8465 | uint32_t db_ready; | |
8466 | unsigned long timeout; | |
8467 | struct lpfc_register bmbx_reg; | |
8468 | ||
8469 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) | |
8470 | * 1000) + jiffies; | |
8471 | ||
8472 | do { | |
8473 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
8474 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
8475 | if (!db_ready) | |
8476 | msleep(2); | |
8477 | ||
8478 | if (time_after(jiffies, timeout)) | |
8479 | return MBXERR_ERROR; | |
8480 | } while (!db_ready); | |
8481 | ||
8482 | return 0; | |
8483 | } | |
8484 | ||
da0436e9 JS |
8485 | /** |
8486 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
8487 | * @phba: Pointer to HBA context object. | |
8488 | * @mboxq: Pointer to mailbox object. | |
8489 | * | |
8490 | * The function posts a mailbox to the port. The mailbox is expected | |
8491 | * to be comletely filled in and ready for the port to operate on it. | |
8492 | * This routine executes a synchronous completion operation on the | |
8493 | * mailbox by polling for its completion. | |
8494 | * | |
8495 | * The caller must not be holding any locks when calling this routine. | |
8496 | * | |
8497 | * Returns: | |
8498 | * MBX_SUCCESS - mailbox posted successfully | |
8499 | * Any of the MBX error values. | |
8500 | **/ | |
8501 | static int | |
8502 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8503 | { | |
8504 | int rc = MBX_SUCCESS; | |
8505 | unsigned long iflag; | |
da0436e9 JS |
8506 | uint32_t mcqe_status; |
8507 | uint32_t mbx_cmnd; | |
da0436e9 JS |
8508 | struct lpfc_sli *psli = &phba->sli; |
8509 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
8510 | struct lpfc_bmbx_create *mbox_rgn; | |
8511 | struct dma_address *dma_address; | |
da0436e9 JS |
8512 | |
8513 | /* | |
8514 | * Only one mailbox can be active to the bootstrap mailbox region | |
8515 | * at a time and there is no queueing provided. | |
8516 | */ | |
8517 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8518 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8519 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8520 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 8521 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
8522 | "cannot issue Data: x%x x%x\n", |
8523 | mboxq->vport ? mboxq->vport->vpi : 0, | |
8524 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8525 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8526 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8527 | psli->sli_flag, MBX_POLL); |
8528 | return MBXERR_ERROR; | |
8529 | } | |
8530 | /* The server grabs the token and owns it until release */ | |
8531 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
8532 | phba->sli.mbox_active = mboxq; | |
8533 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8534 | ||
2d843edc JS |
8535 | /* wait for bootstrap mbox register for readyness */ |
8536 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
8537 | if (rc) | |
8538 | goto exit; | |
8539 | ||
da0436e9 JS |
8540 | /* |
8541 | * Initialize the bootstrap memory region to avoid stale data areas | |
8542 | * in the mailbox post. Then copy the caller's mailbox contents to | |
8543 | * the bmbx mailbox region. | |
8544 | */ | |
8545 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
8546 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
48f8fdb4 JS |
8547 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
8548 | sizeof(struct lpfc_mqe)); | |
da0436e9 JS |
8549 | |
8550 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
8551 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
8552 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
8553 | ||
2d843edc JS |
8554 | /* wait for bootstrap mbox register for hi-address write done */ |
8555 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
8556 | if (rc) | |
8557 | goto exit; | |
da0436e9 JS |
8558 | |
8559 | /* Post the low mailbox dma address to the port. */ | |
8560 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
da0436e9 | 8561 | |
2d843edc JS |
8562 | /* wait for bootstrap mbox register for low address write done */ |
8563 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); | |
8564 | if (rc) | |
8565 | goto exit; | |
da0436e9 JS |
8566 | |
8567 | /* | |
8568 | * Read the CQ to ensure the mailbox has completed. | |
8569 | * If so, update the mailbox status so that the upper layers | |
8570 | * can complete the request normally. | |
8571 | */ | |
48f8fdb4 JS |
8572 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
8573 | sizeof(struct lpfc_mqe)); | |
da0436e9 | 8574 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
48f8fdb4 JS |
8575 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
8576 | sizeof(struct lpfc_mcqe)); | |
da0436e9 | 8577 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
0558056c JS |
8578 | /* |
8579 | * When the CQE status indicates a failure and the mailbox status | |
8580 | * indicates success then copy the CQE status into the mailbox status | |
8581 | * (and prefix it with x4000). | |
8582 | */ | |
da0436e9 | 8583 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
8584 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
8585 | bf_set(lpfc_mqe_status, mb, | |
8586 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 8587 | rc = MBXERR_ERROR; |
d7c47992 JS |
8588 | } else |
8589 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
8590 | |
8591 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 8592 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
8593 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
8594 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
8595 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
8596 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
8597 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8598 | bf_get(lpfc_mqe_status, mb), |
8599 | mb->un.mb_words[0], mb->un.mb_words[1], | |
8600 | mb->un.mb_words[2], mb->un.mb_words[3], | |
8601 | mb->un.mb_words[4], mb->un.mb_words[5], | |
8602 | mb->un.mb_words[6], mb->un.mb_words[7], | |
8603 | mb->un.mb_words[8], mb->un.mb_words[9], | |
8604 | mb->un.mb_words[10], mb->un.mb_words[11], | |
8605 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
8606 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
8607 | mboxq->mcqe.trailer); | |
8608 | exit: | |
8609 | /* We are holding the token, no needed for lock when release */ | |
8610 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8611 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8612 | phba->sli.mbox_active = NULL; | |
8613 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8614 | return rc; | |
8615 | } | |
8616 | ||
8617 | /** | |
8618 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
8619 | * @phba: Pointer to HBA context object. | |
8620 | * @pmbox: Pointer to mailbox object. | |
8621 | * @flag: Flag indicating how the mailbox need to be processed. | |
8622 | * | |
8623 | * This function is called by discovery code and HBA management code to submit | |
8624 | * a mailbox command to firmware with SLI-4 interface spec. | |
8625 | * | |
8626 | * Return codes the caller owns the mailbox command after the return of the | |
8627 | * function. | |
8628 | **/ | |
8629 | static int | |
8630 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
8631 | uint32_t flag) | |
8632 | { | |
8633 | struct lpfc_sli *psli = &phba->sli; | |
8634 | unsigned long iflags; | |
8635 | int rc; | |
8636 | ||
b76f2dc9 JS |
8637 | /* dump from issue mailbox command if setup */ |
8638 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
8639 | ||
8fa38513 JS |
8640 | rc = lpfc_mbox_dev_check(phba); |
8641 | if (unlikely(rc)) { | |
8642 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 8643 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
8644 | "cannot issue Data: x%x x%x\n", |
8645 | mboxq->vport ? mboxq->vport->vpi : 0, | |
8646 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8647 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8648 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
8649 | psli->sli_flag, flag); |
8650 | goto out_not_finished; | |
8651 | } | |
8652 | ||
da0436e9 JS |
8653 | /* Detect polling mode and jump to a handler */ |
8654 | if (!phba->sli4_hba.intr_enable) { | |
8655 | if (flag == MBX_POLL) | |
8656 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
8657 | else | |
8658 | rc = -EIO; | |
8659 | if (rc != MBX_SUCCESS) | |
0558056c | 8660 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 8661 | "(%d):2541 Mailbox command x%x " |
cc459f19 JS |
8662 | "(x%x/x%x) failure: " |
8663 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
8664 | "Data: x%x x%x\n,", | |
da0436e9 JS |
8665 | mboxq->vport ? mboxq->vport->vpi : 0, |
8666 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8667 | lpfc_sli_config_mbox_subsys_get(phba, |
8668 | mboxq), | |
8669 | lpfc_sli_config_mbox_opcode_get(phba, | |
8670 | mboxq), | |
cc459f19 JS |
8671 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
8672 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
8673 | bf_get(lpfc_mcqe_ext_status, | |
8674 | &mboxq->mcqe), | |
da0436e9 JS |
8675 | psli->sli_flag, flag); |
8676 | return rc; | |
8677 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
8678 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
8679 | "(%d):2542 Try to issue mailbox command " | |
7365f6fd | 8680 | "x%x (x%x/x%x) synchronously ahead of async " |
f1126688 | 8681 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
8682 | mboxq->vport ? mboxq->vport->vpi : 0, |
8683 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8684 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8685 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 8686 | psli->sli_flag, flag); |
f1126688 JS |
8687 | /* Try to block the asynchronous mailbox posting */ |
8688 | rc = lpfc_sli4_async_mbox_block(phba); | |
8689 | if (!rc) { | |
8690 | /* Successfully blocked, now issue sync mbox cmd */ | |
8691 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
8692 | if (rc != MBX_SUCCESS) | |
cc459f19 | 8693 | lpfc_printf_log(phba, KERN_WARNING, |
a183a15f | 8694 | LOG_MBOX | LOG_SLI, |
cc459f19 JS |
8695 | "(%d):2597 Sync Mailbox command " |
8696 | "x%x (x%x/x%x) failure: " | |
8697 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
8698 | "Data: x%x x%x\n,", | |
8699 | mboxq->vport ? mboxq->vport->vpi : 0, | |
a183a15f JS |
8700 | mboxq->u.mb.mbxCommand, |
8701 | lpfc_sli_config_mbox_subsys_get(phba, | |
8702 | mboxq), | |
8703 | lpfc_sli_config_mbox_opcode_get(phba, | |
8704 | mboxq), | |
cc459f19 JS |
8705 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
8706 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
8707 | bf_get(lpfc_mcqe_ext_status, | |
8708 | &mboxq->mcqe), | |
a183a15f | 8709 | psli->sli_flag, flag); |
f1126688 JS |
8710 | /* Unblock the async mailbox posting afterward */ |
8711 | lpfc_sli4_async_mbox_unblock(phba); | |
8712 | } | |
8713 | return rc; | |
da0436e9 JS |
8714 | } |
8715 | ||
8716 | /* Now, interrupt mode asynchrous mailbox command */ | |
8717 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
8718 | if (rc) { | |
8719 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 8720 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
8721 | "cannot issue Data: x%x x%x\n", |
8722 | mboxq->vport ? mboxq->vport->vpi : 0, | |
8723 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8724 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8725 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8726 | psli->sli_flag, flag); |
8727 | goto out_not_finished; | |
8728 | } | |
da0436e9 JS |
8729 | |
8730 | /* Put the mailbox command to the driver internal FIFO */ | |
8731 | psli->slistat.mbox_busy++; | |
8732 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8733 | lpfc_mbox_put(phba, mboxq); | |
8734 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8735 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
8736 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 8737 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
8738 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
8739 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
8740 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8741 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8742 | phba->pport->port_state, |
8743 | psli->sli_flag, MBX_NOWAIT); | |
8744 | /* Wake up worker thread to transport mailbox command from head */ | |
8745 | lpfc_worker_wake_up(phba); | |
8746 | ||
8747 | return MBX_BUSY; | |
8748 | ||
8749 | out_not_finished: | |
8750 | return MBX_NOT_FINISHED; | |
8751 | } | |
8752 | ||
8753 | /** | |
8754 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
8755 | * @phba: Pointer to HBA context object. | |
8756 | * | |
8757 | * This function is called by worker thread to send a mailbox command to | |
8758 | * SLI4 HBA firmware. | |
8759 | * | |
8760 | **/ | |
8761 | int | |
8762 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
8763 | { | |
8764 | struct lpfc_sli *psli = &phba->sli; | |
8765 | LPFC_MBOXQ_t *mboxq; | |
8766 | int rc = MBX_SUCCESS; | |
8767 | unsigned long iflags; | |
8768 | struct lpfc_mqe *mqe; | |
8769 | uint32_t mbx_cmnd; | |
8770 | ||
8771 | /* Check interrupt mode before post async mailbox command */ | |
8772 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
8773 | return MBX_NOT_FINISHED; | |
8774 | ||
8775 | /* Check for mailbox command service token */ | |
8776 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8777 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
8778 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8779 | return MBX_NOT_FINISHED; | |
8780 | } | |
8781 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8782 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8783 | return MBX_NOT_FINISHED; | |
8784 | } | |
8785 | if (unlikely(phba->sli.mbox_active)) { | |
8786 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8787 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
8788 | "0384 There is pending active mailbox cmd\n"); | |
8789 | return MBX_NOT_FINISHED; | |
8790 | } | |
8791 | /* Take the mailbox command service token */ | |
8792 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
8793 | ||
8794 | /* Get the next mailbox command from head of queue */ | |
8795 | mboxq = lpfc_mbox_get(phba); | |
8796 | ||
8797 | /* If no more mailbox command waiting for post, we're done */ | |
8798 | if (!mboxq) { | |
8799 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8800 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8801 | return MBX_SUCCESS; | |
8802 | } | |
8803 | phba->sli.mbox_active = mboxq; | |
8804 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8805 | ||
8806 | /* Check device readiness for posting mailbox command */ | |
8807 | rc = lpfc_mbox_dev_check(phba); | |
8808 | if (unlikely(rc)) | |
8809 | /* Driver clean routine will clean up pending mailbox */ | |
8810 | goto out_not_finished; | |
8811 | ||
8812 | /* Prepare the mbox command to be posted */ | |
8813 | mqe = &mboxq->u.mqe; | |
8814 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
8815 | ||
8816 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
8817 | mod_timer(&psli->mbox_tmo, (jiffies + | |
256ec0d0 | 8818 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
8819 | |
8820 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 8821 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
8822 | "x%x x%x\n", |
8823 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
8824 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8825 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8826 | phba->pport->port_state, psli->sli_flag); |
8827 | ||
8828 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
8829 | if (mboxq->vport) { | |
8830 | lpfc_debugfs_disc_trc(mboxq->vport, | |
8831 | LPFC_DISC_TRC_MBOX_VPORT, | |
8832 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
8833 | mbx_cmnd, mqe->un.mb_words[0], | |
8834 | mqe->un.mb_words[1]); | |
8835 | } else { | |
8836 | lpfc_debugfs_disc_trc(phba->pport, | |
8837 | LPFC_DISC_TRC_MBOX, | |
8838 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
8839 | mbx_cmnd, mqe->un.mb_words[0], | |
8840 | mqe->un.mb_words[1]); | |
8841 | } | |
8842 | } | |
8843 | psli->slistat.mbox_cmd++; | |
8844 | ||
8845 | /* Post the mailbox command to the port */ | |
8846 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
8847 | if (rc != MBX_SUCCESS) { | |
8848 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 8849 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
8850 | "cannot issue Data: x%x x%x\n", |
8851 | mboxq->vport ? mboxq->vport->vpi : 0, | |
8852 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
8853 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
8854 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
8855 | psli->sli_flag, MBX_NOWAIT); |
8856 | goto out_not_finished; | |
8857 | } | |
8858 | ||
8859 | return rc; | |
8860 | ||
8861 | out_not_finished: | |
8862 | spin_lock_irqsave(&phba->hbalock, iflags); | |
d7069f09 JS |
8863 | if (phba->sli.mbox_active) { |
8864 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8865 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
8866 | /* Release the token */ | |
8867 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8868 | phba->sli.mbox_active = NULL; | |
8869 | } | |
da0436e9 JS |
8870 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
8871 | ||
8872 | return MBX_NOT_FINISHED; | |
8873 | } | |
8874 | ||
8875 | /** | |
8876 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
8877 | * @phba: Pointer to HBA context object. | |
8878 | * @pmbox: Pointer to mailbox object. | |
8879 | * @flag: Flag indicating how the mailbox need to be processed. | |
8880 | * | |
8881 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
8882 | * the API jump table function pointer from the lpfc_hba struct. | |
8883 | * | |
8884 | * Return codes the caller owns the mailbox command after the return of the | |
8885 | * function. | |
8886 | **/ | |
8887 | int | |
8888 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
8889 | { | |
8890 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
8891 | } | |
8892 | ||
8893 | /** | |
25985edc | 8894 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
8895 | * @phba: The hba struct for which this call is being executed. |
8896 | * @dev_grp: The HBA PCI-Device group number. | |
8897 | * | |
8898 | * This routine sets up the mbox interface API function jump table in @phba | |
8899 | * struct. | |
8900 | * Returns: 0 - success, -ENODEV - failure. | |
8901 | **/ | |
8902 | int | |
8903 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8904 | { | |
8905 | ||
8906 | switch (dev_grp) { | |
8907 | case LPFC_PCI_DEV_LP: | |
8908 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
8909 | phba->lpfc_sli_handle_slow_ring_event = | |
8910 | lpfc_sli_handle_slow_ring_event_s3; | |
8911 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
8912 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
8913 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
8914 | break; | |
8915 | case LPFC_PCI_DEV_OC: | |
8916 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
8917 | phba->lpfc_sli_handle_slow_ring_event = | |
8918 | lpfc_sli_handle_slow_ring_event_s4; | |
8919 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
8920 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
8921 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
8922 | break; | |
8923 | default: | |
8924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8925 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
8926 | dev_grp); | |
8927 | return -ENODEV; | |
8928 | break; | |
8929 | } | |
8930 | return 0; | |
8931 | } | |
8932 | ||
e59058c4 | 8933 | /** |
3621a710 | 8934 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
8935 | * @phba: Pointer to HBA context object. |
8936 | * @pring: Pointer to driver SLI ring object. | |
8937 | * @piocb: Pointer to address of newly added command iocb. | |
8938 | * | |
8939 | * This function is called with hbalock held to add a command | |
8940 | * iocb to the txq when SLI layer cannot submit the command iocb | |
8941 | * to the ring. | |
8942 | **/ | |
2a9bf3d0 | 8943 | void |
92d7f7b0 | 8944 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 8945 | struct lpfc_iocbq *piocb) |
dea3101e | 8946 | { |
1c2ba475 | 8947 | lockdep_assert_held(&phba->hbalock); |
dea3101e JB |
8948 | /* Insert the caller's iocb in the txq tail for later processing. */ |
8949 | list_add_tail(&piocb->list, &pring->txq); | |
dea3101e JB |
8950 | } |
8951 | ||
e59058c4 | 8952 | /** |
3621a710 | 8953 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
8954 | * @phba: Pointer to HBA context object. |
8955 | * @pring: Pointer to driver SLI ring object. | |
8956 | * @piocb: Pointer to address of newly added command iocb. | |
8957 | * | |
8958 | * This function is called with hbalock held before a new | |
8959 | * iocb is submitted to the firmware. This function checks | |
8960 | * txq to flush the iocbs in txq to Firmware before | |
8961 | * submitting new iocbs to the Firmware. | |
8962 | * If there are iocbs in the txq which need to be submitted | |
8963 | * to firmware, lpfc_sli_next_iocb returns the first element | |
8964 | * of the txq after dequeuing it from txq. | |
8965 | * If there is no iocb in the txq then the function will return | |
8966 | * *piocb and *piocb is set to NULL. Caller needs to check | |
8967 | * *piocb to find if there are more commands in the txq. | |
8968 | **/ | |
dea3101e JB |
8969 | static struct lpfc_iocbq * |
8970 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 8971 | struct lpfc_iocbq **piocb) |
dea3101e JB |
8972 | { |
8973 | struct lpfc_iocbq * nextiocb; | |
8974 | ||
1c2ba475 JT |
8975 | lockdep_assert_held(&phba->hbalock); |
8976 | ||
dea3101e JB |
8977 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
8978 | if (!nextiocb) { | |
8979 | nextiocb = *piocb; | |
8980 | *piocb = NULL; | |
8981 | } | |
8982 | ||
8983 | return nextiocb; | |
8984 | } | |
8985 | ||
e59058c4 | 8986 | /** |
3772a991 | 8987 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 8988 | * @phba: Pointer to HBA context object. |
3772a991 | 8989 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
8990 | * @piocb: Pointer to command iocb. |
8991 | * @flag: Flag indicating if this command can be put into txq. | |
8992 | * | |
3772a991 JS |
8993 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
8994 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
8995 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
8996 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
8997 | * this function allows only iocbs for posting buffers. This function finds | |
8998 | * next available slot in the command ring and posts the command to the | |
8999 | * available slot and writes the port attention register to request HBA start | |
9000 | * processing new iocb. If there is no slot available in the ring and | |
9001 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
9002 | * the function returns IOCB_BUSY. | |
e59058c4 | 9003 | * |
3772a991 JS |
9004 | * This function is called with hbalock held. The function will return success |
9005 | * after it successfully submit the iocb to firmware or after adding to the | |
9006 | * txq. | |
e59058c4 | 9007 | **/ |
98c9ea5c | 9008 | static int |
3772a991 | 9009 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
9010 | struct lpfc_iocbq *piocb, uint32_t flag) |
9011 | { | |
9012 | struct lpfc_iocbq *nextiocb; | |
9013 | IOCB_t *iocb; | |
895427bd | 9014 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
dea3101e | 9015 | |
1c2ba475 JT |
9016 | lockdep_assert_held(&phba->hbalock); |
9017 | ||
92d7f7b0 JS |
9018 | if (piocb->iocb_cmpl && (!piocb->vport) && |
9019 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
9020 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
9021 | lpfc_printf_log(phba, KERN_ERR, | |
9022 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 9023 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
9024 | piocb->iocb.ulpCommand); |
9025 | dump_stack(); | |
9026 | return IOCB_ERROR; | |
9027 | } | |
9028 | ||
9029 | ||
8d63f375 LV |
9030 | /* If the PCI channel is in offline state, do not post iocbs. */ |
9031 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
9032 | return IOCB_ERROR; | |
9033 | ||
a257bf90 JS |
9034 | /* If HBA has a deferred error attention, fail the iocb. */ |
9035 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
9036 | return IOCB_ERROR; | |
9037 | ||
dea3101e JB |
9038 | /* |
9039 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
9040 | */ | |
2e0fef85 | 9041 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
9042 | return IOCB_ERROR; |
9043 | ||
9044 | /* | |
9045 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 9046 | * outstanding event. |
dea3101e | 9047 | */ |
0b727fea | 9048 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
9049 | goto iocb_busy; |
9050 | ||
2e0fef85 | 9051 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 9052 | /* |
2680eeaa | 9053 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
9054 | * can be issued if the link is not up. |
9055 | */ | |
9056 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
9057 | case CMD_GEN_REQUEST64_CR: |
9058 | case CMD_GEN_REQUEST64_CX: | |
9059 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
9060 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 9061 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
9062 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
9063 | MENLO_TRANSPORT_TYPE)) | |
9064 | ||
9065 | goto iocb_busy; | |
9066 | break; | |
dea3101e JB |
9067 | case CMD_QUE_RING_BUF_CN: |
9068 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
9069 | /* |
9070 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
9071 | * completion, iocb_cmpl MUST be 0. | |
9072 | */ | |
9073 | if (piocb->iocb_cmpl) | |
9074 | piocb->iocb_cmpl = NULL; | |
9075 | /*FALLTHROUGH*/ | |
9076 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
9077 | case CMD_CLOSE_XRI_CN: |
9078 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
9079 | break; |
9080 | default: | |
9081 | goto iocb_busy; | |
9082 | } | |
9083 | ||
9084 | /* | |
9085 | * For FCP commands, we must be in a state where we can process link | |
9086 | * attention events. | |
9087 | */ | |
895427bd | 9088 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
92d7f7b0 | 9089 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 9090 | goto iocb_busy; |
92d7f7b0 | 9091 | } |
dea3101e | 9092 | |
dea3101e JB |
9093 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
9094 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
9095 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
9096 | ||
9097 | if (iocb) | |
9098 | lpfc_sli_update_ring(phba, pring); | |
9099 | else | |
9100 | lpfc_sli_update_full_ring(phba, pring); | |
9101 | ||
9102 | if (!piocb) | |
9103 | return IOCB_SUCCESS; | |
9104 | ||
9105 | goto out_busy; | |
9106 | ||
9107 | iocb_busy: | |
9108 | pring->stats.iocb_cmd_delay++; | |
9109 | ||
9110 | out_busy: | |
9111 | ||
9112 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 9113 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
9114 | return IOCB_SUCCESS; |
9115 | } | |
9116 | ||
9117 | return IOCB_BUSY; | |
9118 | } | |
9119 | ||
3772a991 | 9120 | /** |
4f774513 JS |
9121 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
9122 | * @phba: Pointer to HBA context object. | |
9123 | * @piocb: Pointer to command iocb. | |
9124 | * @sglq: Pointer to the scatter gather queue object. | |
9125 | * | |
9126 | * This routine converts the bpl or bde that is in the IOCB | |
9127 | * to a sgl list for the sli4 hardware. The physical address | |
9128 | * of the bpl/bde is converted back to a virtual address. | |
9129 | * If the IOCB contains a BPL then the list of BDE's is | |
9130 | * converted to sli4_sge's. If the IOCB contains a single | |
9131 | * BDE then it is converted to a single sli_sge. | |
9132 | * The IOCB is still in cpu endianess so the contents of | |
9133 | * the bpl can be used without byte swapping. | |
9134 | * | |
9135 | * Returns valid XRI = Success, NO_XRI = Failure. | |
9136 | **/ | |
9137 | static uint16_t | |
9138 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
9139 | struct lpfc_sglq *sglq) | |
3772a991 | 9140 | { |
4f774513 JS |
9141 | uint16_t xritag = NO_XRI; |
9142 | struct ulp_bde64 *bpl = NULL; | |
9143 | struct ulp_bde64 bde; | |
9144 | struct sli4_sge *sgl = NULL; | |
1b51197d | 9145 | struct lpfc_dmabuf *dmabuf; |
4f774513 JS |
9146 | IOCB_t *icmd; |
9147 | int numBdes = 0; | |
9148 | int i = 0; | |
63e801ce JS |
9149 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
9150 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 9151 | |
4f774513 JS |
9152 | if (!piocbq || !sglq) |
9153 | return xritag; | |
9154 | ||
9155 | sgl = (struct sli4_sge *)sglq->sgl; | |
9156 | icmd = &piocbq->iocb; | |
6b5151fd JS |
9157 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
9158 | return sglq->sli4_xritag; | |
4f774513 JS |
9159 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
9160 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
9161 | sizeof(struct ulp_bde64); | |
9162 | /* The addrHigh and addrLow fields within the IOCB | |
9163 | * have not been byteswapped yet so there is no | |
9164 | * need to swap them back. | |
9165 | */ | |
1b51197d JS |
9166 | if (piocbq->context3) |
9167 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; | |
9168 | else | |
9169 | return xritag; | |
4f774513 | 9170 | |
1b51197d | 9171 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
4f774513 JS |
9172 | if (!bpl) |
9173 | return xritag; | |
9174 | ||
9175 | for (i = 0; i < numBdes; i++) { | |
9176 | /* Should already be byte swapped. */ | |
28baac74 JS |
9177 | sgl->addr_hi = bpl->addrHigh; |
9178 | sgl->addr_lo = bpl->addrLow; | |
9179 | ||
0558056c | 9180 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
9181 | if ((i+1) == numBdes) |
9182 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
9183 | else | |
9184 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
9185 | /* swap the size field back to the cpu so we |
9186 | * can assign it to the sgl. | |
9187 | */ | |
9188 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
9189 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
9190 | /* The offsets in the sgl need to be accumulated |
9191 | * separately for the request and reply lists. | |
9192 | * The request is always first, the reply follows. | |
9193 | */ | |
9194 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
9195 | /* add up the reply sg entries */ | |
9196 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
9197 | inbound++; | |
9198 | /* first inbound? reset the offset */ | |
9199 | if (inbound == 1) | |
9200 | offset = 0; | |
9201 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
9202 | bf_set(lpfc_sli4_sge_type, sgl, |
9203 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
9204 | offset += bde.tus.f.bdeSize; |
9205 | } | |
546fc854 | 9206 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
9207 | bpl++; |
9208 | sgl++; | |
9209 | } | |
9210 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
9211 | /* The addrHigh and addrLow fields of the BDE have not | |
9212 | * been byteswapped yet so they need to be swapped | |
9213 | * before putting them in the sgl. | |
9214 | */ | |
9215 | sgl->addr_hi = | |
9216 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
9217 | sgl->addr_lo = | |
9218 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 9219 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
9220 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
9221 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
9222 | sgl->sge_len = |
9223 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
9224 | } |
9225 | return sglq->sli4_xritag; | |
3772a991 | 9226 | } |
92d7f7b0 | 9227 | |
e59058c4 | 9228 | /** |
4f774513 | 9229 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 9230 | * @phba: Pointer to HBA context object. |
4f774513 JS |
9231 | * @piocb: Pointer to command iocb. |
9232 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 9233 | * |
4f774513 JS |
9234 | * This routine converts the iocb command to its Work Queue Entry |
9235 | * equivalent. The wqe pointer should not have any fields set when | |
9236 | * this routine is called because it will memcpy over them. | |
9237 | * This routine does not set the CQ_ID or the WQEC bits in the | |
9238 | * wqe. | |
e59058c4 | 9239 | * |
4f774513 | 9240 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 9241 | **/ |
cf5bf97e | 9242 | static int |
4f774513 | 9243 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
205e8240 | 9244 | union lpfc_wqe128 *wqe) |
cf5bf97e | 9245 | { |
5ffc266e | 9246 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
9247 | uint8_t ct = 0; |
9248 | uint32_t fip; | |
9249 | uint32_t abort_tag; | |
9250 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
9251 | uint8_t cmnd; | |
9252 | uint16_t xritag; | |
dcf2a4e0 JS |
9253 | uint16_t abrt_iotag; |
9254 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 9255 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 9256 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
9257 | int numBdes, i; |
9258 | struct ulp_bde64 bde; | |
c31098ce | 9259 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 9260 | uint32_t *pcmd; |
1b51197d | 9261 | uint32_t if_type; |
4f774513 | 9262 | |
45ed1190 | 9263 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 9264 | /* The fcp commands will set command type */ |
0c287589 | 9265 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 9266 | command_type = FCP_COMMAND; |
c868595d | 9267 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
9268 | command_type = ELS_COMMAND_FIP; |
9269 | else | |
9270 | command_type = ELS_COMMAND_NON_FIP; | |
9271 | ||
b5c53958 JS |
9272 | if (phba->fcp_embed_io) |
9273 | memset(wqe, 0, sizeof(union lpfc_wqe128)); | |
4f774513 JS |
9274 | /* Some of the fields are in the right position already */ |
9275 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
ae9e28f3 JS |
9276 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
9277 | /* The ct field has moved so reset */ | |
9278 | wqe->generic.wqe_com.word7 = 0; | |
9279 | wqe->generic.wqe_com.word10 = 0; | |
9280 | } | |
b5c53958 JS |
9281 | |
9282 | abort_tag = (uint32_t) iocbq->iotag; | |
9283 | xritag = iocbq->sli4_xritag; | |
4f774513 JS |
9284 | /* words0-2 bpl convert bde */ |
9285 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
9286 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
9287 | sizeof(struct ulp_bde64); | |
4f774513 JS |
9288 | bpl = (struct ulp_bde64 *) |
9289 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
9290 | if (!bpl) | |
9291 | return IOCB_ERROR; | |
cf5bf97e | 9292 | |
4f774513 JS |
9293 | /* Should already be byte swapped. */ |
9294 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
9295 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
9296 | /* swap the size field back to the cpu so we | |
9297 | * can assign it to the sgl. | |
9298 | */ | |
9299 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
9300 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
9301 | total_len = 0; | |
9302 | for (i = 0; i < numBdes; i++) { | |
9303 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
9304 | total_len += bde.tus.f.bdeSize; | |
9305 | } | |
4f774513 | 9306 | } else |
5ffc266e | 9307 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 9308 | |
4f774513 JS |
9309 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
9310 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 9311 | |
4f774513 JS |
9312 | switch (iocbq->iocb.ulpCommand) { |
9313 | case CMD_ELS_REQUEST64_CR: | |
93d1379e JS |
9314 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
9315 | ndlp = iocbq->context_un.ndlp; | |
9316 | else | |
9317 | ndlp = (struct lpfc_nodelist *)iocbq->context1; | |
4f774513 JS |
9318 | if (!iocbq->iocb.ulpLe) { |
9319 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9320 | "2007 Only Limited Edition cmd Format" | |
9321 | " supported 0x%x\n", | |
9322 | iocbq->iocb.ulpCommand); | |
9323 | return IOCB_ERROR; | |
9324 | } | |
ff78d8f9 | 9325 | |
5ffc266e | 9326 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
9327 | /* Els_reguest64 has a TMO */ |
9328 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
9329 | iocbq->iocb.ulpTimeout); | |
9330 | /* Need a VF for word 4 set the vf bit*/ | |
9331 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
9332 | /* And a VFID for word 12 */ | |
9333 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 9334 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
9335 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
9336 | iocbq->iocb.ulpContext); | |
9337 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
9338 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 9339 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 9340 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
9341 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
9342 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
9343 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
9344 | iocbq->context2)->virt); | |
1b51197d JS |
9345 | if_type = bf_get(lpfc_sli_intf_if_type, |
9346 | &phba->sli4_hba.sli_intf); | |
27d6ac0a | 9347 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
ff78d8f9 | 9348 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
cb69f7de | 9349 | *pcmd == ELS_CMD_SCR || |
6b5151fd | 9350 | *pcmd == ELS_CMD_FDISC || |
bdcd2b92 | 9351 | *pcmd == ELS_CMD_LOGO || |
ff78d8f9 JS |
9352 | *pcmd == ELS_CMD_PLOGI)) { |
9353 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
9354 | bf_set(els_req64_sid, &wqe->els_req, | |
9355 | iocbq->vport->fc_myDID); | |
939723a4 JS |
9356 | if ((*pcmd == ELS_CMD_FLOGI) && |
9357 | !(phba->fc_topology == | |
9358 | LPFC_TOPOLOGY_LOOP)) | |
9359 | bf_set(els_req64_sid, &wqe->els_req, 0); | |
ff78d8f9 JS |
9360 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
9361 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
a7dd9c0f | 9362 | phba->vpi_ids[iocbq->vport->vpi]); |
3ef6d24c | 9363 | } else if (pcmd && iocbq->context1) { |
ff78d8f9 JS |
9364 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
9365 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
9366 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
9367 | } | |
c868595d | 9368 | } |
6d368e53 JS |
9369 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
9370 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
9371 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
9372 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
9373 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
9374 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
9375 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
9376 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
af22741c | 9377 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
7851fe2c | 9378 | break; |
5ffc266e | 9379 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
9380 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
9381 | iocbq->iocb.un.ulpWord[3]); | |
9382 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 9383 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
9384 | /* The entire sequence is transmitted for this IOCB */ |
9385 | xmit_len = total_len; | |
9386 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
1b51197d JS |
9387 | if (phba->link_flag & LS_LOOPBACK_MODE) |
9388 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); | |
4f774513 | 9389 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
9390 | /* word3 iocb=io_tag32 wqe=reserved */ |
9391 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
9392 | /* word4 relative_offset memcpy */ |
9393 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
9394 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
9395 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
9396 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
9397 | LPFC_WQE_IOD_WRITE); | |
9398 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
9399 | LPFC_WQE_LENLOC_WORD12); | |
9400 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
9401 | wqe->xmit_sequence.xmit_len = xmit_len; |
9402 | command_type = OTHER_COMMAND; | |
7851fe2c | 9403 | break; |
4f774513 | 9404 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
9405 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
9406 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
9407 | /* word4 iocb=rsvd wqe=rsvd */ |
9408 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
9409 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 9410 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 9411 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
9412 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
9413 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
9414 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
9415 | LPFC_WQE_LENLOC_WORD3); | |
9416 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 9417 | break; |
4f774513 JS |
9418 | case CMD_FCP_IWRITE64_CR: |
9419 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
9420 | /* word3 iocb=iotag wqe=payload_offset_len */ |
9421 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
9422 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
9423 | xmit_len + sizeof(struct fcp_rsp)); | |
9424 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, | |
9425 | 0); | |
f0d9bccc JS |
9426 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
9427 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
9428 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
9429 | iocbq->iocb.ulpFCP2Rcvy); | |
9430 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
9431 | /* Always open the exchange */ | |
f0d9bccc JS |
9432 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
9433 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
9434 | LPFC_WQE_LENLOC_WORD4); | |
f0d9bccc | 9435 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
acd6859b | 9436 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
1ba981fd JS |
9437 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
9438 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); | |
c92c841c JS |
9439 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
9440 | if (iocbq->priority) { | |
9441 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, | |
9442 | (iocbq->priority << 1)); | |
9443 | } else { | |
1ba981fd JS |
9444 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
9445 | (phba->cfg_XLanePriority << 1)); | |
9446 | } | |
9447 | } | |
b5c53958 JS |
9448 | /* Note, word 10 is already initialized to 0 */ |
9449 | ||
414abe0a JS |
9450 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
9451 | if (phba->cfg_enable_pbde) | |
0bc2b7c5 JS |
9452 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
9453 | else | |
9454 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); | |
9455 | ||
b5c53958 JS |
9456 | if (phba->fcp_embed_io) { |
9457 | struct lpfc_scsi_buf *lpfc_cmd; | |
9458 | struct sli4_sge *sgl; | |
b5c53958 JS |
9459 | struct fcp_cmnd *fcp_cmnd; |
9460 | uint32_t *ptr; | |
9461 | ||
9462 | /* 128 byte wqe support here */ | |
b5c53958 JS |
9463 | |
9464 | lpfc_cmd = iocbq->context1; | |
9465 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
9466 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
9467 | ||
9468 | /* Word 0-2 - FCP_CMND */ | |
205e8240 | 9469 | wqe->generic.bde.tus.f.bdeFlags = |
b5c53958 | 9470 | BUFF_TYPE_BDE_IMMED; |
205e8240 JS |
9471 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
9472 | wqe->generic.bde.addrHigh = 0; | |
9473 | wqe->generic.bde.addrLow = 88; /* Word 22 */ | |
b5c53958 | 9474 | |
205e8240 JS |
9475 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
9476 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); | |
b5c53958 JS |
9477 | |
9478 | /* Word 22-29 FCP CMND Payload */ | |
205e8240 | 9479 | ptr = &wqe->words[22]; |
b5c53958 JS |
9480 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
9481 | } | |
7851fe2c | 9482 | break; |
4f774513 | 9483 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
9484 | /* word3 iocb=iotag wqe=payload_offset_len */ |
9485 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
0ba4b219 JS |
9486 | bf_set(payload_offset_len, &wqe->fcp_iread, |
9487 | xmit_len + sizeof(struct fcp_rsp)); | |
9488 | bf_set(cmd_buff_len, &wqe->fcp_iread, | |
9489 | 0); | |
f0d9bccc JS |
9490 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
9491 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
9492 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
9493 | iocbq->iocb.ulpFCP2Rcvy); | |
9494 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 | 9495 | /* Always open the exchange */ |
f0d9bccc JS |
9496 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
9497 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
9498 | LPFC_WQE_LENLOC_WORD4); | |
f0d9bccc | 9499 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
acd6859b | 9500 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
1ba981fd JS |
9501 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
9502 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); | |
c92c841c JS |
9503 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
9504 | if (iocbq->priority) { | |
9505 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, | |
9506 | (iocbq->priority << 1)); | |
9507 | } else { | |
1ba981fd JS |
9508 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
9509 | (phba->cfg_XLanePriority << 1)); | |
9510 | } | |
9511 | } | |
b5c53958 JS |
9512 | /* Note, word 10 is already initialized to 0 */ |
9513 | ||
414abe0a JS |
9514 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
9515 | if (phba->cfg_enable_pbde) | |
0bc2b7c5 JS |
9516 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
9517 | else | |
9518 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); | |
9519 | ||
b5c53958 JS |
9520 | if (phba->fcp_embed_io) { |
9521 | struct lpfc_scsi_buf *lpfc_cmd; | |
9522 | struct sli4_sge *sgl; | |
b5c53958 JS |
9523 | struct fcp_cmnd *fcp_cmnd; |
9524 | uint32_t *ptr; | |
9525 | ||
9526 | /* 128 byte wqe support here */ | |
b5c53958 JS |
9527 | |
9528 | lpfc_cmd = iocbq->context1; | |
9529 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
9530 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
9531 | ||
9532 | /* Word 0-2 - FCP_CMND */ | |
205e8240 | 9533 | wqe->generic.bde.tus.f.bdeFlags = |
b5c53958 | 9534 | BUFF_TYPE_BDE_IMMED; |
205e8240 JS |
9535 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
9536 | wqe->generic.bde.addrHigh = 0; | |
9537 | wqe->generic.bde.addrLow = 88; /* Word 22 */ | |
b5c53958 | 9538 | |
205e8240 JS |
9539 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
9540 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); | |
b5c53958 JS |
9541 | |
9542 | /* Word 22-29 FCP CMND Payload */ | |
205e8240 | 9543 | ptr = &wqe->words[22]; |
b5c53958 JS |
9544 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
9545 | } | |
7851fe2c | 9546 | break; |
4f774513 | 9547 | case CMD_FCP_ICMND64_CR: |
0ba4b219 JS |
9548 | /* word3 iocb=iotag wqe=payload_offset_len */ |
9549 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
9550 | bf_set(payload_offset_len, &wqe->fcp_icmd, | |
9551 | xmit_len + sizeof(struct fcp_rsp)); | |
9552 | bf_set(cmd_buff_len, &wqe->fcp_icmd, | |
9553 | 0); | |
f0d9bccc | 9554 | /* word3 iocb=IO_TAG wqe=reserved */ |
f0d9bccc | 9555 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
4f774513 | 9556 | /* Always open the exchange */ |
f0d9bccc JS |
9557 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
9558 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
9559 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
9560 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
9561 | LPFC_WQE_LENLOC_NONE); | |
2a94aea4 JS |
9562 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
9563 | iocbq->iocb.ulpFCP2Rcvy); | |
1ba981fd JS |
9564 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
9565 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); | |
c92c841c JS |
9566 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
9567 | if (iocbq->priority) { | |
9568 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, | |
9569 | (iocbq->priority << 1)); | |
9570 | } else { | |
1ba981fd JS |
9571 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
9572 | (phba->cfg_XLanePriority << 1)); | |
9573 | } | |
9574 | } | |
b5c53958 JS |
9575 | /* Note, word 10 is already initialized to 0 */ |
9576 | ||
9577 | if (phba->fcp_embed_io) { | |
9578 | struct lpfc_scsi_buf *lpfc_cmd; | |
9579 | struct sli4_sge *sgl; | |
b5c53958 JS |
9580 | struct fcp_cmnd *fcp_cmnd; |
9581 | uint32_t *ptr; | |
9582 | ||
9583 | /* 128 byte wqe support here */ | |
b5c53958 JS |
9584 | |
9585 | lpfc_cmd = iocbq->context1; | |
9586 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; | |
9587 | fcp_cmnd = lpfc_cmd->fcp_cmnd; | |
9588 | ||
9589 | /* Word 0-2 - FCP_CMND */ | |
205e8240 | 9590 | wqe->generic.bde.tus.f.bdeFlags = |
b5c53958 | 9591 | BUFF_TYPE_BDE_IMMED; |
205e8240 JS |
9592 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
9593 | wqe->generic.bde.addrHigh = 0; | |
9594 | wqe->generic.bde.addrLow = 88; /* Word 22 */ | |
b5c53958 | 9595 | |
205e8240 JS |
9596 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
9597 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); | |
b5c53958 JS |
9598 | |
9599 | /* Word 22-29 FCP CMND Payload */ | |
205e8240 | 9600 | ptr = &wqe->words[22]; |
b5c53958 JS |
9601 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
9602 | } | |
7851fe2c | 9603 | break; |
4f774513 | 9604 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
9605 | /* For this command calculate the xmit length of the |
9606 | * request bde. | |
9607 | */ | |
9608 | xmit_len = 0; | |
9609 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
9610 | sizeof(struct ulp_bde64); | |
9611 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 9612 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
9613 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
9614 | break; | |
63e801ce JS |
9615 | xmit_len += bde.tus.f.bdeSize; |
9616 | } | |
f0d9bccc JS |
9617 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
9618 | wqe->gen_req.request_payload_len = xmit_len; | |
9619 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
9620 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
9621 | /* word6 context tag copied in memcpy */ |
9622 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
9623 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
9624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9625 | "2015 Invalid CT %x command 0x%x\n", | |
9626 | ct, iocbq->iocb.ulpCommand); | |
9627 | return IOCB_ERROR; | |
9628 | } | |
f0d9bccc JS |
9629 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
9630 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
9631 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
9632 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
9633 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
9634 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
9635 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
9636 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
af22741c | 9637 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
4f774513 | 9638 | command_type = OTHER_COMMAND; |
7851fe2c | 9639 | break; |
4f774513 | 9640 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 9641 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 9642 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
9643 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
9644 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
939723a4 JS |
9645 | /* word4 */ |
9646 | wqe->xmit_els_rsp.word4 = 0; | |
4f774513 JS |
9647 | /* word5 iocb=rsvd wge=did */ |
9648 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
939723a4 JS |
9649 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
9650 | ||
9651 | if_type = bf_get(lpfc_sli_intf_if_type, | |
9652 | &phba->sli4_hba.sli_intf); | |
27d6ac0a | 9653 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
939723a4 JS |
9654 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
9655 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); | |
9656 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
9657 | iocbq->vport->fc_myDID); | |
9658 | if (iocbq->vport->fc_myDID == Fabric_DID) { | |
9659 | bf_set(wqe_els_did, | |
9660 | &wqe->xmit_els_rsp.wqe_dest, 0); | |
9661 | } | |
9662 | } | |
9663 | } | |
f0d9bccc JS |
9664 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
9665 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
9666 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
9667 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 9668 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 9669 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 9670 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 9671 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
9672 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
9673 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
9674 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
9675 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
9676 | LPFC_WQE_LENLOC_WORD3); | |
9677 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
9678 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
9679 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
9680 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
9681 | iocbq->context2)->virt); | |
9682 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
939723a4 JS |
9683 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
9684 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
ff78d8f9 | 9685 | iocbq->vport->fc_myDID); |
939723a4 JS |
9686 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
9687 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, | |
ff78d8f9 JS |
9688 | phba->vpi_ids[phba->pport->vpi]); |
9689 | } | |
4f774513 | 9690 | command_type = OTHER_COMMAND; |
7851fe2c | 9691 | break; |
4f774513 JS |
9692 | case CMD_CLOSE_XRI_CN: |
9693 | case CMD_ABORT_XRI_CN: | |
9694 | case CMD_ABORT_XRI_CX: | |
9695 | /* words 0-2 memcpy should be 0 rserved */ | |
9696 | /* port will send abts */ | |
dcf2a4e0 JS |
9697 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
9698 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
9699 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
9700 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
9701 | } else | |
9702 | fip = 0; | |
9703 | ||
9704 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 9705 | /* |
dcf2a4e0 JS |
9706 | * The link is down, or the command was ELS_FIP |
9707 | * so the fw does not need to send abts | |
4f774513 JS |
9708 | * on the wire. |
9709 | */ | |
9710 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
9711 | else | |
9712 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
9713 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
9714 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
9715 | wqe->abort_cmd.rsrvd5 = 0; | |
9716 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
9717 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
9718 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
9719 | /* |
9720 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
9721 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
9722 | */ | |
f0d9bccc JS |
9723 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
9724 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
9725 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
9726 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
9727 | cmnd = CMD_ABORT_XRI_CX; |
9728 | command_type = OTHER_COMMAND; | |
9729 | xritag = 0; | |
7851fe2c | 9730 | break; |
6669f9bb | 9731 | case CMD_XMIT_BLS_RSP64_CX: |
6b5151fd | 9732 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
546fc854 | 9733 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
9734 | * we re-construct this WQE here based on information in |
9735 | * iocbq from scratch. | |
9736 | */ | |
9737 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 9738 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 9739 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
9740 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
9741 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
9742 | LPFC_ABTS_UNSOL_INT) { |
9743 | /* ABTS sent by initiator to CT exchange, the | |
9744 | * RX_ID field will be filled with the newly | |
9745 | * allocated responder XRI. | |
9746 | */ | |
9747 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
9748 | iocbq->sli4_xritag); | |
9749 | } else { | |
9750 | /* ABTS sent by responder to CT exchange, the | |
9751 | * RX_ID field will be filled with the responder | |
9752 | * RX_ID from ABTS. | |
9753 | */ | |
9754 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 9755 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 9756 | } |
6669f9bb JS |
9757 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
9758 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6b5151fd JS |
9759 | |
9760 | /* Use CT=VPI */ | |
9761 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, | |
9762 | ndlp->nlp_DID); | |
9763 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, | |
9764 | iocbq->iocb.ulpContext); | |
9765 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); | |
6669f9bb | 9766 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
6b5151fd | 9767 | phba->vpi_ids[phba->pport->vpi]); |
f0d9bccc JS |
9768 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
9769 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
9770 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
9771 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
9772 | command_type = OTHER_COMMAND; | |
546fc854 JS |
9773 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
9774 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
9775 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
9776 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
9777 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
9778 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
9779 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
9780 | } | |
9781 | ||
7851fe2c | 9782 | break; |
ae9e28f3 JS |
9783 | case CMD_SEND_FRAME: |
9784 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); | |
9785 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
9786 | return 0; | |
4f774513 JS |
9787 | case CMD_XRI_ABORTED_CX: |
9788 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
9789 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
9790 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
9791 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
9792 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
9793 | default: | |
9794 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9795 | "2014 Invalid command 0x%x\n", | |
9796 | iocbq->iocb.ulpCommand); | |
9797 | return IOCB_ERROR; | |
7851fe2c | 9798 | break; |
4f774513 | 9799 | } |
6d368e53 | 9800 | |
8012cc38 JS |
9801 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
9802 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); | |
9803 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) | |
9804 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); | |
9805 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) | |
9806 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); | |
9807 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | | |
9808 | LPFC_IO_DIF_INSERT); | |
f0d9bccc JS |
9809 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
9810 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
9811 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
9812 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
9813 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
9814 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
9815 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
9816 | return 0; |
9817 | } | |
9818 | ||
9819 | /** | |
9820 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
9821 | * @phba: Pointer to HBA context object. | |
9822 | * @ring_number: SLI ring number to issue iocb on. | |
9823 | * @piocb: Pointer to command iocb. | |
9824 | * @flag: Flag indicating if this command can be put into txq. | |
9825 | * | |
9826 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
9827 | * an iocb command to an HBA with SLI-4 interface spec. | |
9828 | * | |
9829 | * This function is called with hbalock held. The function will return success | |
9830 | * after it successfully submit the iocb to firmware or after adding to the | |
9831 | * txq. | |
9832 | **/ | |
9833 | static int | |
9834 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
9835 | struct lpfc_iocbq *piocb, uint32_t flag) | |
9836 | { | |
9837 | struct lpfc_sglq *sglq; | |
205e8240 | 9838 | union lpfc_wqe128 wqe; |
1ba981fd | 9839 | struct lpfc_queue *wq; |
895427bd | 9840 | struct lpfc_sli_ring *pring; |
4f774513 | 9841 | |
895427bd JS |
9842 | /* Get the WQ */ |
9843 | if ((piocb->iocb_flag & LPFC_IO_FCP) || | |
9844 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
9845 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) | |
9846 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; | |
9847 | else | |
9848 | wq = phba->sli4_hba.oas_wq; | |
9849 | } else { | |
9850 | wq = phba->sli4_hba.els_wq; | |
9851 | } | |
9852 | ||
9853 | /* Get corresponding ring */ | |
9854 | pring = wq->pring; | |
1c2ba475 | 9855 | |
b5c53958 JS |
9856 | /* |
9857 | * The WQE can be either 64 or 128 bytes, | |
b5c53958 | 9858 | */ |
b5c53958 | 9859 | |
895427bd JS |
9860 | lockdep_assert_held(&phba->hbalock); |
9861 | ||
4f774513 JS |
9862 | if (piocb->sli4_xritag == NO_XRI) { |
9863 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6b5151fd | 9864 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
9865 | sglq = NULL; |
9866 | else { | |
0e9bb8d7 | 9867 | if (!list_empty(&pring->txq)) { |
2a9bf3d0 JS |
9868 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
9869 | __lpfc_sli_ringtx_put(phba, | |
9870 | pring, piocb); | |
9871 | return IOCB_SUCCESS; | |
9872 | } else { | |
9873 | return IOCB_BUSY; | |
9874 | } | |
9875 | } else { | |
895427bd | 9876 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
2a9bf3d0 JS |
9877 | if (!sglq) { |
9878 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
9879 | __lpfc_sli_ringtx_put(phba, | |
9880 | pring, | |
9881 | piocb); | |
9882 | return IOCB_SUCCESS; | |
9883 | } else | |
9884 | return IOCB_BUSY; | |
9885 | } | |
9886 | } | |
4f774513 | 9887 | } |
2ea259ee | 9888 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
6d368e53 JS |
9889 | /* These IO's already have an XRI and a mapped sgl. */ |
9890 | sglq = NULL; | |
2ea259ee | 9891 | else { |
6d368e53 JS |
9892 | /* |
9893 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
9894 | * sglq is on the active list |
9895 | */ | |
edccdc17 | 9896 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
4f774513 JS |
9897 | if (!sglq) |
9898 | return IOCB_ERROR; | |
9899 | } | |
9900 | ||
9901 | if (sglq) { | |
6d368e53 | 9902 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 9903 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 9904 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
9905 | return IOCB_ERROR; |
9906 | } | |
9907 | ||
205e8240 | 9908 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
4f774513 JS |
9909 | return IOCB_ERROR; |
9910 | ||
205e8240 | 9911 | if (lpfc_sli4_wq_put(wq, &wqe)) |
895427bd | 9912 | return IOCB_ERROR; |
4f774513 JS |
9913 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
9914 | ||
9915 | return 0; | |
9916 | } | |
9917 | ||
9918 | /** | |
9919 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
9920 | * | |
9921 | * This routine wraps the actual lockless version for issusing IOCB function | |
9922 | * pointer from the lpfc_hba struct. | |
9923 | * | |
9924 | * Return codes: | |
b5c53958 JS |
9925 | * IOCB_ERROR - Error |
9926 | * IOCB_SUCCESS - Success | |
9927 | * IOCB_BUSY - Busy | |
4f774513 | 9928 | **/ |
2a9bf3d0 | 9929 | int |
4f774513 JS |
9930 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
9931 | struct lpfc_iocbq *piocb, uint32_t flag) | |
9932 | { | |
9933 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
9934 | } | |
9935 | ||
9936 | /** | |
25985edc | 9937 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
9938 | * @phba: The hba struct for which this call is being executed. |
9939 | * @dev_grp: The HBA PCI-Device group number. | |
9940 | * | |
9941 | * This routine sets up the SLI interface API function jump table in @phba | |
9942 | * struct. | |
9943 | * Returns: 0 - success, -ENODEV - failure. | |
9944 | **/ | |
9945 | int | |
9946 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
9947 | { | |
9948 | ||
9949 | switch (dev_grp) { | |
9950 | case LPFC_PCI_DEV_LP: | |
9951 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
9952 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
9953 | break; | |
9954 | case LPFC_PCI_DEV_OC: | |
9955 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
9956 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
9957 | break; | |
9958 | default: | |
9959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9960 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
9961 | dev_grp); | |
9962 | return -ENODEV; | |
9963 | break; | |
9964 | } | |
9965 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
9966 | return 0; | |
9967 | } | |
9968 | ||
a1efe163 | 9969 | /** |
895427bd | 9970 | * lpfc_sli4_calc_ring - Calculates which ring to use |
a1efe163 | 9971 | * @phba: Pointer to HBA context object. |
a1efe163 JS |
9972 | * @piocb: Pointer to command iocb. |
9973 | * | |
895427bd JS |
9974 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
9975 | * hba_wqidx, thus we need to calculate the corresponding ring. | |
a1efe163 | 9976 | * Since ABORTS must go on the same WQ of the command they are |
895427bd | 9977 | * aborting, we use command's hba_wqidx. |
a1efe163 | 9978 | */ |
895427bd JS |
9979 | struct lpfc_sli_ring * |
9980 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) | |
9bd2bff5 | 9981 | { |
895427bd | 9982 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
8b0dff14 | 9983 | if (!(phba->cfg_fof) || |
895427bd | 9984 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
8b0dff14 | 9985 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
895427bd | 9986 | return NULL; |
8b0dff14 | 9987 | /* |
895427bd | 9988 | * for abort iocb hba_wqidx should already |
8b0dff14 JS |
9989 | * be setup based on what work queue we used. |
9990 | */ | |
8e036a94 | 9991 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
895427bd | 9992 | piocb->hba_wqidx = |
8b0dff14 JS |
9993 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
9994 | piocb->context1); | |
8e036a94 DK |
9995 | piocb->hba_wqidx = piocb->hba_wqidx % |
9996 | phba->cfg_fcp_io_channel; | |
9997 | } | |
895427bd | 9998 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
8b0dff14 JS |
9999 | } else { |
10000 | if (unlikely(!phba->sli4_hba.oas_wq)) | |
895427bd JS |
10001 | return NULL; |
10002 | piocb->hba_wqidx = 0; | |
10003 | return phba->sli4_hba.oas_wq->pring; | |
9bd2bff5 | 10004 | } |
895427bd JS |
10005 | } else { |
10006 | if (unlikely(!phba->sli4_hba.els_wq)) | |
10007 | return NULL; | |
10008 | piocb->hba_wqidx = 0; | |
10009 | return phba->sli4_hba.els_wq->pring; | |
9bd2bff5 | 10010 | } |
9bd2bff5 JS |
10011 | } |
10012 | ||
4f774513 JS |
10013 | /** |
10014 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
10015 | * @phba: Pointer to HBA context object. | |
10016 | * @pring: Pointer to driver SLI ring object. | |
10017 | * @piocb: Pointer to command iocb. | |
10018 | * @flag: Flag indicating if this command can be put into txq. | |
10019 | * | |
10020 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
10021 | * function. This function gets the hbalock and calls | |
10022 | * __lpfc_sli_issue_iocb function and will return the error returned | |
10023 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
10024 | * functions which do not hold hbalock. | |
10025 | **/ | |
10026 | int | |
10027 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
10028 | struct lpfc_iocbq *piocb, uint32_t flag) | |
10029 | { | |
895427bd | 10030 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
2a76a283 | 10031 | struct lpfc_sli_ring *pring; |
ba20c853 JS |
10032 | struct lpfc_queue *fpeq; |
10033 | struct lpfc_eqe *eqe; | |
4f774513 | 10034 | unsigned long iflags; |
2a76a283 | 10035 | int rc, idx; |
4f774513 | 10036 | |
7e56aa25 | 10037 | if (phba->sli_rev == LPFC_SLI_REV4) { |
895427bd JS |
10038 | pring = lpfc_sli4_calc_ring(phba, piocb); |
10039 | if (unlikely(pring == NULL)) | |
9bd2bff5 | 10040 | return IOCB_ERROR; |
ba20c853 | 10041 | |
9bd2bff5 JS |
10042 | spin_lock_irqsave(&pring->ring_lock, iflags); |
10043 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
10044 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
ba20c853 | 10045 | |
9bd2bff5 | 10046 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
895427bd JS |
10047 | idx = piocb->hba_wqidx; |
10048 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; | |
4f774513 | 10049 | |
895427bd | 10050 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
ba20c853 | 10051 | |
9bd2bff5 JS |
10052 | /* Get associated EQ with this index */ |
10053 | fpeq = phba->sli4_hba.hba_eq[idx]; | |
ba20c853 | 10054 | |
9bd2bff5 | 10055 | /* Turn off interrupts from this EQ */ |
b71413dd | 10056 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
ba20c853 | 10057 | |
9bd2bff5 JS |
10058 | /* |
10059 | * Process all the events on FCP EQ | |
10060 | */ | |
10061 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
10062 | lpfc_sli4_hba_handle_eqe(phba, | |
10063 | eqe, idx); | |
10064 | fpeq->EQ_processed++; | |
ba20c853 | 10065 | } |
ba20c853 | 10066 | |
9bd2bff5 | 10067 | /* Always clear and re-arm the EQ */ |
b71413dd | 10068 | phba->sli4_hba.sli4_eq_release(fpeq, |
9bd2bff5 JS |
10069 | LPFC_QUEUE_REARM); |
10070 | } | |
895427bd | 10071 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
2a76a283 | 10072 | } |
7e56aa25 JS |
10073 | } else { |
10074 | /* For now, SLI2/3 will still use hbalock */ | |
10075 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10076 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
10077 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10078 | } | |
4f774513 JS |
10079 | return rc; |
10080 | } | |
10081 | ||
10082 | /** | |
10083 | * lpfc_extra_ring_setup - Extra ring setup function | |
10084 | * @phba: Pointer to HBA context object. | |
10085 | * | |
10086 | * This function is called while driver attaches with the | |
10087 | * HBA to setup the extra ring. The extra ring is used | |
10088 | * only when driver needs to support target mode functionality | |
10089 | * or IP over FC functionalities. | |
10090 | * | |
895427bd | 10091 | * This function is called with no lock held. SLI3 only. |
4f774513 JS |
10092 | **/ |
10093 | static int | |
10094 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
10095 | { | |
10096 | struct lpfc_sli *psli; | |
10097 | struct lpfc_sli_ring *pring; | |
10098 | ||
10099 | psli = &phba->sli; | |
10100 | ||
10101 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
10102 | ||
10103 | /* Take some away from the FCP ring */ | |
895427bd | 10104 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
7e56aa25 JS |
10105 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
10106 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
10107 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
10108 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e | 10109 | |
a4bc3379 | 10110 | /* and give them to the extra ring */ |
895427bd | 10111 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
a4bc3379 | 10112 | |
7e56aa25 JS |
10113 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
10114 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
10115 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
10116 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e JW |
10117 | |
10118 | /* Setup default profile for this ring */ | |
10119 | pring->iotag_max = 4096; | |
10120 | pring->num_mask = 1; | |
10121 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
10122 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
10123 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
10124 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
10125 | return 0; | |
10126 | } | |
10127 | ||
cb69f7de JS |
10128 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
10129 | * @phba: Pointer to HBA context object. | |
10130 | * @iocbq: Pointer to iocb object. | |
10131 | * | |
10132 | * The async_event handler calls this routine when it receives | |
10133 | * an ASYNC_STATUS_CN event from the port. The port generates | |
10134 | * this event when an Abort Sequence request to an rport fails | |
10135 | * twice in succession. The abort could be originated by the | |
10136 | * driver or by the port. The ABTS could have been for an ELS | |
10137 | * or FCP IO. The port only generates this event when an ABTS | |
10138 | * fails to complete after one retry. | |
10139 | */ | |
10140 | static void | |
10141 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
10142 | struct lpfc_iocbq *iocbq) | |
10143 | { | |
10144 | struct lpfc_nodelist *ndlp = NULL; | |
10145 | uint16_t rpi = 0, vpi = 0; | |
10146 | struct lpfc_vport *vport = NULL; | |
10147 | ||
10148 | /* The rpi in the ulpContext is vport-sensitive. */ | |
10149 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
10150 | rpi = iocbq->iocb.ulpContext; | |
10151 | ||
10152 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10153 | "3092 Port generated ABTS async event " | |
10154 | "on vpi %d rpi %d status 0x%x\n", | |
10155 | vpi, rpi, iocbq->iocb.ulpStatus); | |
10156 | ||
10157 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
10158 | if (!vport) | |
10159 | goto err_exit; | |
10160 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
10161 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
10162 | goto err_exit; | |
10163 | ||
10164 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
10165 | lpfc_sli_abts_recover_port(vport, ndlp); | |
10166 | return; | |
10167 | ||
10168 | err_exit: | |
10169 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
10170 | "3095 Event Context not found, no " | |
10171 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
10172 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
10173 | vpi, rpi); | |
10174 | } | |
10175 | ||
10176 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
10177 | * @phba: pointer to HBA context object. | |
10178 | * @ndlp: nodelist pointer for the impacted rport. | |
10179 | * @axri: pointer to the wcqe containing the failed exchange. | |
10180 | * | |
10181 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
10182 | * port. The port generates this event when an abort exchange request to an | |
10183 | * rport fails twice in succession with no reply. The abort could be originated | |
10184 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
10185 | */ | |
10186 | void | |
10187 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
10188 | struct lpfc_nodelist *ndlp, | |
10189 | struct sli4_wcqe_xri_aborted *axri) | |
10190 | { | |
10191 | struct lpfc_vport *vport; | |
5c1db2ac | 10192 | uint32_t ext_status = 0; |
cb69f7de | 10193 | |
6b5151fd | 10194 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
cb69f7de JS |
10195 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
10196 | "3115 Node Context not found, driver " | |
10197 | "ignoring abts err event\n"); | |
6b5151fd JS |
10198 | return; |
10199 | } | |
10200 | ||
cb69f7de JS |
10201 | vport = ndlp->vport; |
10202 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10203 | "3116 Port generated FCP XRI ABORT event on " | |
5c1db2ac | 10204 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
8e668af5 | 10205 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
cb69f7de | 10206 | bf_get(lpfc_wcqe_xa_xri, axri), |
5c1db2ac JS |
10207 | bf_get(lpfc_wcqe_xa_status, axri), |
10208 | axri->parameter); | |
cb69f7de | 10209 | |
5c1db2ac JS |
10210 | /* |
10211 | * Catch the ABTS protocol failure case. Older OCe FW releases returned | |
10212 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and | |
10213 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. | |
10214 | */ | |
e3d2b802 | 10215 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
5c1db2ac JS |
10216 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
10217 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) | |
cb69f7de JS |
10218 | lpfc_sli_abts_recover_port(vport, ndlp); |
10219 | } | |
10220 | ||
e59058c4 | 10221 | /** |
3621a710 | 10222 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
10223 | * @phba: Pointer to HBA context object. |
10224 | * @pring: Pointer to driver SLI ring object. | |
10225 | * @iocbq: Pointer to iocb object. | |
10226 | * | |
10227 | * This function is called by the slow ring event handler | |
10228 | * function when there is an ASYNC event iocb in the ring. | |
10229 | * This function is called with no lock held. | |
10230 | * Currently this function handles only temperature related | |
10231 | * ASYNC events. The function decodes the temperature sensor | |
10232 | * event message and posts events for the management applications. | |
10233 | **/ | |
98c9ea5c | 10234 | static void |
57127f15 JS |
10235 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
10236 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
10237 | { | |
10238 | IOCB_t *icmd; | |
10239 | uint16_t evt_code; | |
57127f15 JS |
10240 | struct temp_event temp_event_data; |
10241 | struct Scsi_Host *shost; | |
a257bf90 | 10242 | uint32_t *iocb_w; |
57127f15 JS |
10243 | |
10244 | icmd = &iocbq->iocb; | |
10245 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 10246 | |
cb69f7de JS |
10247 | switch (evt_code) { |
10248 | case ASYNC_TEMP_WARN: | |
10249 | case ASYNC_TEMP_SAFE: | |
10250 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
10251 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
10252 | if (evt_code == ASYNC_TEMP_WARN) { | |
10253 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
10254 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
10255 | "0347 Adapter is very hot, please take " | |
10256 | "corrective action. temperature : %d Celsius\n", | |
10257 | (uint32_t) icmd->ulpContext); | |
10258 | } else { | |
10259 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
10260 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
10261 | "0340 Adapter temperature is OK now. " | |
10262 | "temperature : %d Celsius\n", | |
10263 | (uint32_t) icmd->ulpContext); | |
10264 | } | |
10265 | ||
10266 | /* Send temperature change event to applications */ | |
10267 | shost = lpfc_shost_from_vport(phba->pport); | |
10268 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
10269 | sizeof(temp_event_data), (char *) &temp_event_data, | |
10270 | LPFC_NL_VENDOR_ID); | |
10271 | break; | |
10272 | case ASYNC_STATUS_CN: | |
10273 | lpfc_sli_abts_err_handler(phba, iocbq); | |
10274 | break; | |
10275 | default: | |
a257bf90 | 10276 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 10278 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 10279 | " evt_code 0x%x\n" |
a257bf90 JS |
10280 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
10281 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
10282 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
10283 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 10284 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
10285 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
10286 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
10287 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
10288 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
10289 | ||
cb69f7de | 10290 | break; |
57127f15 | 10291 | } |
57127f15 JS |
10292 | } |
10293 | ||
10294 | ||
e59058c4 | 10295 | /** |
895427bd | 10296 | * lpfc_sli4_setup - SLI ring setup function |
e59058c4 JS |
10297 | * @phba: Pointer to HBA context object. |
10298 | * | |
10299 | * lpfc_sli_setup sets up rings of the SLI interface with | |
10300 | * number of iocbs per ring and iotags. This function is | |
10301 | * called while driver attach to the HBA and before the | |
10302 | * interrupts are enabled. So there is no need for locking. | |
10303 | * | |
10304 | * This function always returns 0. | |
10305 | **/ | |
dea3101e | 10306 | int |
895427bd JS |
10307 | lpfc_sli4_setup(struct lpfc_hba *phba) |
10308 | { | |
10309 | struct lpfc_sli_ring *pring; | |
10310 | ||
10311 | pring = phba->sli4_hba.els_wq->pring; | |
10312 | pring->num_mask = LPFC_MAX_RING_MASK; | |
10313 | pring->prt[0].profile = 0; /* Mask 0 */ | |
10314 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; | |
10315 | pring->prt[0].type = FC_TYPE_ELS; | |
10316 | pring->prt[0].lpfc_sli_rcv_unsol_event = | |
10317 | lpfc_els_unsol_event; | |
10318 | pring->prt[1].profile = 0; /* Mask 1 */ | |
10319 | pring->prt[1].rctl = FC_RCTL_ELS_REP; | |
10320 | pring->prt[1].type = FC_TYPE_ELS; | |
10321 | pring->prt[1].lpfc_sli_rcv_unsol_event = | |
10322 | lpfc_els_unsol_event; | |
10323 | pring->prt[2].profile = 0; /* Mask 2 */ | |
10324 | /* NameServer Inquiry */ | |
10325 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; | |
10326 | /* NameServer */ | |
10327 | pring->prt[2].type = FC_TYPE_CT; | |
10328 | pring->prt[2].lpfc_sli_rcv_unsol_event = | |
10329 | lpfc_ct_unsol_event; | |
10330 | pring->prt[3].profile = 0; /* Mask 3 */ | |
10331 | /* NameServer response */ | |
10332 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; | |
10333 | /* NameServer */ | |
10334 | pring->prt[3].type = FC_TYPE_CT; | |
10335 | pring->prt[3].lpfc_sli_rcv_unsol_event = | |
10336 | lpfc_ct_unsol_event; | |
10337 | return 0; | |
10338 | } | |
10339 | ||
10340 | /** | |
10341 | * lpfc_sli_setup - SLI ring setup function | |
10342 | * @phba: Pointer to HBA context object. | |
10343 | * | |
10344 | * lpfc_sli_setup sets up rings of the SLI interface with | |
10345 | * number of iocbs per ring and iotags. This function is | |
10346 | * called while driver attach to the HBA and before the | |
10347 | * interrupts are enabled. So there is no need for locking. | |
10348 | * | |
10349 | * This function always returns 0. SLI3 only. | |
10350 | **/ | |
10351 | int | |
dea3101e JB |
10352 | lpfc_sli_setup(struct lpfc_hba *phba) |
10353 | { | |
ed957684 | 10354 | int i, totiocbsize = 0; |
dea3101e JB |
10355 | struct lpfc_sli *psli = &phba->sli; |
10356 | struct lpfc_sli_ring *pring; | |
10357 | ||
2a76a283 | 10358 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
dea3101e | 10359 | psli->sli_flag = 0; |
dea3101e | 10360 | |
604a3e30 JB |
10361 | psli->iocbq_lookup = NULL; |
10362 | psli->iocbq_lookup_len = 0; | |
10363 | psli->last_iotag = 0; | |
10364 | ||
dea3101e | 10365 | for (i = 0; i < psli->num_rings; i++) { |
895427bd | 10366 | pring = &psli->sli3_ring[i]; |
dea3101e JB |
10367 | switch (i) { |
10368 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
10369 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
10370 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
10371 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
10372 | pring->sli.sli3.numCiocb += | |
10373 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
10374 | pring->sli.sli3.numRiocb += | |
10375 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
10376 | pring->sli.sli3.numCiocb += | |
10377 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
10378 | pring->sli.sli3.numRiocb += | |
10379 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
10380 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
10381 | SLI3_IOCB_CMD_SIZE : |
10382 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 10383 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
10384 | SLI3_IOCB_RSP_SIZE : |
10385 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
10386 | pring->iotag_ctr = 0; |
10387 | pring->iotag_max = | |
92d7f7b0 | 10388 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
10389 | pring->fast_iotag = pring->iotag_max; |
10390 | pring->num_mask = 0; | |
10391 | break; | |
a4bc3379 | 10392 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 10393 | /* numCiocb and numRiocb are used in config_port */ |
7e56aa25 JS |
10394 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
10395 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
10396 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
10397 | SLI3_IOCB_CMD_SIZE : |
10398 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 10399 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
10400 | SLI3_IOCB_RSP_SIZE : |
10401 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 10402 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
10403 | pring->num_mask = 0; |
10404 | break; | |
10405 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
10406 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
10407 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
10408 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
10409 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
10410 | SLI3_IOCB_CMD_SIZE : |
10411 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 10412 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
10413 | SLI3_IOCB_RSP_SIZE : |
10414 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
10415 | pring->fast_iotag = 0; |
10416 | pring->iotag_ctr = 0; | |
10417 | pring->iotag_max = 4096; | |
57127f15 JS |
10418 | pring->lpfc_sli_rcv_async_status = |
10419 | lpfc_sli_async_event_handler; | |
6669f9bb | 10420 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 10421 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
10422 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
10423 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 10424 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 10425 | lpfc_els_unsol_event; |
dea3101e | 10426 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
10427 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
10428 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 10429 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 10430 | lpfc_els_unsol_event; |
dea3101e JB |
10431 | pring->prt[2].profile = 0; /* Mask 2 */ |
10432 | /* NameServer Inquiry */ | |
6a9c52cf | 10433 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 10434 | /* NameServer */ |
6a9c52cf | 10435 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 10436 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 10437 | lpfc_ct_unsol_event; |
dea3101e JB |
10438 | pring->prt[3].profile = 0; /* Mask 3 */ |
10439 | /* NameServer response */ | |
6a9c52cf | 10440 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 10441 | /* NameServer */ |
6a9c52cf | 10442 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 10443 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 10444 | lpfc_ct_unsol_event; |
dea3101e JB |
10445 | break; |
10446 | } | |
7e56aa25 JS |
10447 | totiocbsize += (pring->sli.sli3.numCiocb * |
10448 | pring->sli.sli3.sizeCiocb) + | |
10449 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); | |
dea3101e | 10450 | } |
ed957684 | 10451 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 10452 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
10453 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
10454 | "SLI2 SLIM Data: x%x x%lx\n", | |
10455 | phba->brd_no, totiocbsize, | |
10456 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 10457 | } |
cf5bf97e JW |
10458 | if (phba->cfg_multi_ring_support == 2) |
10459 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
10460 | |
10461 | return 0; | |
10462 | } | |
10463 | ||
e59058c4 | 10464 | /** |
895427bd | 10465 | * lpfc_sli4_queue_init - Queue initialization function |
e59058c4 JS |
10466 | * @phba: Pointer to HBA context object. |
10467 | * | |
895427bd | 10468 | * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each |
e59058c4 JS |
10469 | * ring. This function also initializes ring indices of each ring. |
10470 | * This function is called during the initialization of the SLI | |
10471 | * interface of an HBA. | |
10472 | * This function is called with no lock held and always returns | |
10473 | * 1. | |
10474 | **/ | |
895427bd JS |
10475 | void |
10476 | lpfc_sli4_queue_init(struct lpfc_hba *phba) | |
dea3101e JB |
10477 | { |
10478 | struct lpfc_sli *psli; | |
10479 | struct lpfc_sli_ring *pring; | |
604a3e30 | 10480 | int i; |
dea3101e JB |
10481 | |
10482 | psli = &phba->sli; | |
2e0fef85 | 10483 | spin_lock_irq(&phba->hbalock); |
dea3101e | 10484 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 10485 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e | 10486 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
895427bd JS |
10487 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
10488 | pring = phba->sli4_hba.fcp_wq[i]->pring; | |
68e814f5 | 10489 | pring->flag = 0; |
895427bd | 10490 | pring->ringno = LPFC_FCP_RING; |
dea3101e JB |
10491 | INIT_LIST_HEAD(&pring->txq); |
10492 | INIT_LIST_HEAD(&pring->txcmplq); | |
10493 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
7e56aa25 | 10494 | spin_lock_init(&pring->ring_lock); |
dea3101e | 10495 | } |
895427bd JS |
10496 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
10497 | pring = phba->sli4_hba.nvme_wq[i]->pring; | |
10498 | pring->flag = 0; | |
10499 | pring->ringno = LPFC_FCP_RING; | |
10500 | INIT_LIST_HEAD(&pring->txq); | |
10501 | INIT_LIST_HEAD(&pring->txcmplq); | |
10502 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
10503 | spin_lock_init(&pring->ring_lock); | |
10504 | } | |
10505 | pring = phba->sli4_hba.els_wq->pring; | |
10506 | pring->flag = 0; | |
10507 | pring->ringno = LPFC_ELS_RING; | |
10508 | INIT_LIST_HEAD(&pring->txq); | |
10509 | INIT_LIST_HEAD(&pring->txcmplq); | |
10510 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
10511 | spin_lock_init(&pring->ring_lock); | |
dea3101e | 10512 | |
895427bd JS |
10513 | if (phba->cfg_nvme_io_channel) { |
10514 | pring = phba->sli4_hba.nvmels_wq->pring; | |
10515 | pring->flag = 0; | |
10516 | pring->ringno = LPFC_ELS_RING; | |
10517 | INIT_LIST_HEAD(&pring->txq); | |
10518 | INIT_LIST_HEAD(&pring->txcmplq); | |
10519 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
10520 | spin_lock_init(&pring->ring_lock); | |
10521 | } | |
10522 | ||
10523 | if (phba->cfg_fof) { | |
10524 | pring = phba->sli4_hba.oas_wq->pring; | |
10525 | pring->flag = 0; | |
10526 | pring->ringno = LPFC_FCP_RING; | |
10527 | INIT_LIST_HEAD(&pring->txq); | |
10528 | INIT_LIST_HEAD(&pring->txcmplq); | |
10529 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
10530 | spin_lock_init(&pring->ring_lock); | |
10531 | } | |
10532 | ||
10533 | spin_unlock_irq(&phba->hbalock); | |
10534 | } | |
10535 | ||
10536 | /** | |
10537 | * lpfc_sli_queue_init - Queue initialization function | |
10538 | * @phba: Pointer to HBA context object. | |
10539 | * | |
10540 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each | |
10541 | * ring. This function also initializes ring indices of each ring. | |
10542 | * This function is called during the initialization of the SLI | |
10543 | * interface of an HBA. | |
10544 | * This function is called with no lock held and always returns | |
10545 | * 1. | |
10546 | **/ | |
10547 | void | |
10548 | lpfc_sli_queue_init(struct lpfc_hba *phba) | |
dea3101e JB |
10549 | { |
10550 | struct lpfc_sli *psli; | |
10551 | struct lpfc_sli_ring *pring; | |
604a3e30 | 10552 | int i; |
dea3101e JB |
10553 | |
10554 | psli = &phba->sli; | |
2e0fef85 | 10555 | spin_lock_irq(&phba->hbalock); |
dea3101e | 10556 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 10557 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
10558 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
10559 | for (i = 0; i < psli->num_rings; i++) { | |
895427bd | 10560 | pring = &psli->sli3_ring[i]; |
dea3101e | 10561 | pring->ringno = i; |
7e56aa25 JS |
10562 | pring->sli.sli3.next_cmdidx = 0; |
10563 | pring->sli.sli3.local_getidx = 0; | |
10564 | pring->sli.sli3.cmdidx = 0; | |
dea3101e | 10565 | INIT_LIST_HEAD(&pring->iocb_continueq); |
9c2face6 | 10566 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 10567 | INIT_LIST_HEAD(&pring->postbufq); |
895427bd JS |
10568 | pring->flag = 0; |
10569 | INIT_LIST_HEAD(&pring->txq); | |
10570 | INIT_LIST_HEAD(&pring->txcmplq); | |
7e56aa25 | 10571 | spin_lock_init(&pring->ring_lock); |
dea3101e | 10572 | } |
2e0fef85 | 10573 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
10574 | } |
10575 | ||
04c68496 JS |
10576 | /** |
10577 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
10578 | * @phba: Pointer to HBA context object. | |
10579 | * | |
10580 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
10581 | * flush all the mailbox commands in the three possible stages in the mailbox | |
10582 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
10583 | * command; and completed mailbox command queue. It is caller's responsibility | |
10584 | * to make sure that the driver is in the proper state to flush the mailbox | |
10585 | * command sub-system. Namely, the posting of mailbox commands into the | |
10586 | * pending mailbox command queue from the various clients must be stopped; | |
10587 | * either the HBA is in a state that it will never works on the outstanding | |
10588 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
10589 | * mailbox command has been completed. | |
10590 | **/ | |
10591 | static void | |
10592 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
10593 | { | |
10594 | LIST_HEAD(completions); | |
10595 | struct lpfc_sli *psli = &phba->sli; | |
10596 | LPFC_MBOXQ_t *pmb; | |
10597 | unsigned long iflag; | |
10598 | ||
523128e5 JS |
10599 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
10600 | local_bh_disable(); | |
10601 | ||
04c68496 JS |
10602 | /* Flush all the mailbox commands in the mbox system */ |
10603 | spin_lock_irqsave(&phba->hbalock, iflag); | |
523128e5 | 10604 | |
04c68496 JS |
10605 | /* The pending mailbox command queue */ |
10606 | list_splice_init(&phba->sli.mboxq, &completions); | |
10607 | /* The outstanding active mailbox command */ | |
10608 | if (psli->mbox_active) { | |
10609 | list_add_tail(&psli->mbox_active->list, &completions); | |
10610 | psli->mbox_active = NULL; | |
10611 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
10612 | } | |
10613 | /* The completed mailbox command queue */ | |
10614 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
10615 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10616 | ||
523128e5 JS |
10617 | /* Enable softirqs again, done with phba->hbalock */ |
10618 | local_bh_enable(); | |
10619 | ||
04c68496 JS |
10620 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
10621 | while (!list_empty(&completions)) { | |
10622 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
10623 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
10624 | if (pmb->mbox_cmpl) | |
10625 | pmb->mbox_cmpl(phba, pmb); | |
10626 | } | |
10627 | } | |
10628 | ||
e59058c4 | 10629 | /** |
3621a710 | 10630 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
10631 | * @vport: Pointer to virtual port object. |
10632 | * | |
10633 | * lpfc_sli_host_down is called to clean up the resources | |
10634 | * associated with a vport before destroying virtual | |
10635 | * port data structures. | |
10636 | * This function does following operations: | |
10637 | * - Free discovery resources associated with this virtual | |
10638 | * port. | |
10639 | * - Free iocbs associated with this virtual port in | |
10640 | * the txq. | |
10641 | * - Send abort for all iocb commands associated with this | |
10642 | * vport in txcmplq. | |
10643 | * | |
10644 | * This function is called with no lock held and always returns 1. | |
10645 | **/ | |
92d7f7b0 JS |
10646 | int |
10647 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
10648 | { | |
858c9f6c | 10649 | LIST_HEAD(completions); |
92d7f7b0 JS |
10650 | struct lpfc_hba *phba = vport->phba; |
10651 | struct lpfc_sli *psli = &phba->sli; | |
895427bd | 10652 | struct lpfc_queue *qp = NULL; |
92d7f7b0 JS |
10653 | struct lpfc_sli_ring *pring; |
10654 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
10655 | int i; |
10656 | unsigned long flags = 0; | |
10657 | uint16_t prev_pring_flag; | |
10658 | ||
10659 | lpfc_cleanup_discovery_resources(vport); | |
10660 | ||
10661 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 | 10662 | |
895427bd JS |
10663 | /* |
10664 | * Error everything on the txq since these iocbs | |
10665 | * have not been given to the FW yet. | |
10666 | * Also issue ABTS for everything on the txcmplq | |
10667 | */ | |
10668 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
10669 | for (i = 0; i < psli->num_rings; i++) { | |
10670 | pring = &psli->sli3_ring[i]; | |
10671 | prev_pring_flag = pring->flag; | |
10672 | /* Only slow rings */ | |
10673 | if (pring->ringno == LPFC_ELS_RING) { | |
10674 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | |
10675 | /* Set the lpfc data pending flag */ | |
10676 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
10677 | } | |
10678 | list_for_each_entry_safe(iocb, next_iocb, | |
10679 | &pring->txq, list) { | |
10680 | if (iocb->vport != vport) | |
10681 | continue; | |
10682 | list_move_tail(&iocb->list, &completions); | |
10683 | } | |
10684 | list_for_each_entry_safe(iocb, next_iocb, | |
10685 | &pring->txcmplq, list) { | |
10686 | if (iocb->vport != vport) | |
10687 | continue; | |
10688 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
10689 | } | |
10690 | pring->flag = prev_pring_flag; | |
10691 | } | |
10692 | } else { | |
10693 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
10694 | pring = qp->pring; | |
10695 | if (!pring) | |
92d7f7b0 | 10696 | continue; |
895427bd JS |
10697 | if (pring == phba->sli4_hba.els_wq->pring) { |
10698 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | |
10699 | /* Set the lpfc data pending flag */ | |
10700 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
10701 | } | |
10702 | prev_pring_flag = pring->flag; | |
10703 | spin_lock_irq(&pring->ring_lock); | |
10704 | list_for_each_entry_safe(iocb, next_iocb, | |
10705 | &pring->txq, list) { | |
10706 | if (iocb->vport != vport) | |
10707 | continue; | |
10708 | list_move_tail(&iocb->list, &completions); | |
10709 | } | |
10710 | spin_unlock_irq(&pring->ring_lock); | |
10711 | list_for_each_entry_safe(iocb, next_iocb, | |
10712 | &pring->txcmplq, list) { | |
10713 | if (iocb->vport != vport) | |
10714 | continue; | |
10715 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
10716 | } | |
10717 | pring->flag = prev_pring_flag; | |
92d7f7b0 | 10718 | } |
92d7f7b0 | 10719 | } |
92d7f7b0 JS |
10720 | spin_unlock_irqrestore(&phba->hbalock, flags); |
10721 | ||
a257bf90 JS |
10722 | /* Cancel all the IOCBs from the completions list */ |
10723 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
10724 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
10725 | return 1; |
10726 | } | |
10727 | ||
e59058c4 | 10728 | /** |
3621a710 | 10729 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
10730 | * @phba: Pointer to HBA context object. |
10731 | * | |
10732 | * This function cleans up all iocb, buffers, mailbox commands | |
10733 | * while shutting down the HBA. This function is called with no | |
10734 | * lock held and always returns 1. | |
10735 | * This function does the following to cleanup driver resources: | |
10736 | * - Free discovery resources for each virtual port | |
10737 | * - Cleanup any pending fabric iocbs | |
10738 | * - Iterate through the iocb txq and free each entry | |
10739 | * in the list. | |
10740 | * - Free up any buffer posted to the HBA | |
10741 | * - Free mailbox commands in the mailbox queue. | |
10742 | **/ | |
dea3101e | 10743 | int |
2e0fef85 | 10744 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 10745 | { |
2534ba75 | 10746 | LIST_HEAD(completions); |
2e0fef85 | 10747 | struct lpfc_sli *psli = &phba->sli; |
895427bd | 10748 | struct lpfc_queue *qp = NULL; |
dea3101e | 10749 | struct lpfc_sli_ring *pring; |
0ff10d46 | 10750 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 10751 | unsigned long flags = 0; |
04c68496 JS |
10752 | int i; |
10753 | ||
10754 | /* Shutdown the mailbox command sub-system */ | |
618a5230 | 10755 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
dea3101e | 10756 | |
dea3101e JB |
10757 | lpfc_hba_down_prep(phba); |
10758 | ||
523128e5 JS |
10759 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
10760 | local_bh_disable(); | |
10761 | ||
92d7f7b0 JS |
10762 | lpfc_fabric_abort_hba(phba); |
10763 | ||
2e0fef85 | 10764 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 10765 | |
895427bd JS |
10766 | /* |
10767 | * Error everything on the txq since these iocbs | |
10768 | * have not been given to the FW yet. | |
10769 | */ | |
10770 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
10771 | for (i = 0; i < psli->num_rings; i++) { | |
10772 | pring = &psli->sli3_ring[i]; | |
10773 | /* Only slow rings */ | |
10774 | if (pring->ringno == LPFC_ELS_RING) { | |
10775 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | |
10776 | /* Set the lpfc data pending flag */ | |
10777 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
10778 | } | |
10779 | list_splice_init(&pring->txq, &completions); | |
10780 | } | |
10781 | } else { | |
10782 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
10783 | pring = qp->pring; | |
10784 | if (!pring) | |
10785 | continue; | |
10786 | spin_lock_irq(&pring->ring_lock); | |
10787 | list_splice_init(&pring->txq, &completions); | |
10788 | spin_unlock_irq(&pring->ring_lock); | |
10789 | if (pring == phba->sli4_hba.els_wq->pring) { | |
10790 | pring->flag |= LPFC_DEFERRED_RING_EVENT; | |
10791 | /* Set the lpfc data pending flag */ | |
10792 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
10793 | } | |
10794 | } | |
2534ba75 | 10795 | } |
2e0fef85 | 10796 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 10797 | |
a257bf90 JS |
10798 | /* Cancel all the IOCBs from the completions list */ |
10799 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
10800 | IOERR_SLI_DOWN); | |
dea3101e | 10801 | |
0ff10d46 JS |
10802 | spin_lock_irqsave(&phba->hbalock, flags); |
10803 | list_splice_init(&phba->elsbuf, &completions); | |
10804 | phba->elsbuf_cnt = 0; | |
10805 | phba->elsbuf_prev_cnt = 0; | |
10806 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
10807 | ||
10808 | while (!list_empty(&completions)) { | |
10809 | list_remove_head(&completions, buf_ptr, | |
10810 | struct lpfc_dmabuf, list); | |
10811 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
10812 | kfree(buf_ptr); | |
10813 | } | |
10814 | ||
523128e5 JS |
10815 | /* Enable softirqs again, done with phba->hbalock */ |
10816 | local_bh_enable(); | |
10817 | ||
dea3101e JB |
10818 | /* Return any active mbox cmds */ |
10819 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 10820 | |
da0436e9 | 10821 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 10822 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 10823 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 10824 | |
da0436e9 JS |
10825 | return 1; |
10826 | } | |
10827 | ||
e59058c4 | 10828 | /** |
3621a710 | 10829 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
10830 | * @srcp: Source memory pointer. |
10831 | * @destp: Destination memory pointer. | |
10832 | * @cnt: Number of words required to be copied. | |
10833 | * | |
10834 | * This function is used for copying data between driver memory | |
10835 | * and the SLI memory. This function also changes the endianness | |
10836 | * of each word if native endianness is different from SLI | |
10837 | * endianness. This function can be called with or without | |
10838 | * lock. | |
10839 | **/ | |
dea3101e JB |
10840 | void |
10841 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
10842 | { | |
10843 | uint32_t *src = srcp; | |
10844 | uint32_t *dest = destp; | |
10845 | uint32_t ldata; | |
10846 | int i; | |
10847 | ||
10848 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
10849 | ldata = *src; | |
10850 | ldata = le32_to_cpu(ldata); | |
10851 | *dest = ldata; | |
10852 | src++; | |
10853 | dest++; | |
10854 | } | |
10855 | } | |
10856 | ||
e59058c4 | 10857 | |
a0c87cbd JS |
10858 | /** |
10859 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
10860 | * @srcp: Source memory pointer. | |
10861 | * @destp: Destination memory pointer. | |
10862 | * @cnt: Number of words required to be copied. | |
10863 | * | |
10864 | * This function is used for copying data between a data structure | |
10865 | * with big endian representation to local endianness. | |
10866 | * This function can be called with or without lock. | |
10867 | **/ | |
10868 | void | |
10869 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
10870 | { | |
10871 | uint32_t *src = srcp; | |
10872 | uint32_t *dest = destp; | |
10873 | uint32_t ldata; | |
10874 | int i; | |
10875 | ||
10876 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
10877 | ldata = *src; | |
10878 | ldata = be32_to_cpu(ldata); | |
10879 | *dest = ldata; | |
10880 | src++; | |
10881 | dest++; | |
10882 | } | |
10883 | } | |
10884 | ||
e59058c4 | 10885 | /** |
3621a710 | 10886 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
10887 | * @phba: Pointer to HBA context object. |
10888 | * @pring: Pointer to driver SLI ring object. | |
10889 | * @mp: Pointer to driver buffer object. | |
10890 | * | |
10891 | * This function is called with no lock held. | |
10892 | * It always return zero after adding the buffer to the postbufq | |
10893 | * buffer list. | |
10894 | **/ | |
dea3101e | 10895 | int |
2e0fef85 JS |
10896 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
10897 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
10898 | { |
10899 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
10900 | later */ | |
2e0fef85 | 10901 | spin_lock_irq(&phba->hbalock); |
dea3101e | 10902 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 10903 | pring->postbufq_cnt++; |
2e0fef85 | 10904 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
10905 | return 0; |
10906 | } | |
10907 | ||
e59058c4 | 10908 | /** |
3621a710 | 10909 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
10910 | * @phba: Pointer to HBA context object. |
10911 | * | |
10912 | * When HBQ is enabled, buffers are searched based on tags. This function | |
10913 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
10914 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
10915 | * does not conflict with tags of buffer posted for unsolicited events. | |
10916 | * The function returns the allocated tag. The function is called with | |
10917 | * no locks held. | |
10918 | **/ | |
76bb24ef JS |
10919 | uint32_t |
10920 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
10921 | { | |
10922 | spin_lock_irq(&phba->hbalock); | |
10923 | phba->buffer_tag_count++; | |
10924 | /* | |
10925 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
10926 | * a tag assigned by HBQ. | |
10927 | */ | |
10928 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
10929 | spin_unlock_irq(&phba->hbalock); | |
10930 | return phba->buffer_tag_count; | |
10931 | } | |
10932 | ||
e59058c4 | 10933 | /** |
3621a710 | 10934 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
10935 | * @phba: Pointer to HBA context object. |
10936 | * @pring: Pointer to driver SLI ring object. | |
10937 | * @tag: Buffer tag. | |
10938 | * | |
10939 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
10940 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
10941 | * iocb is posted to the response ring with the tag of the buffer. | |
10942 | * This function searches the pring->postbufq list using the tag | |
10943 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
10944 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
10945 | * buffer is returned to the caller else NULL is returned. | |
10946 | * This function is called with no lock held. | |
10947 | **/ | |
76bb24ef JS |
10948 | struct lpfc_dmabuf * |
10949 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
10950 | uint32_t tag) | |
10951 | { | |
10952 | struct lpfc_dmabuf *mp, *next_mp; | |
10953 | struct list_head *slp = &pring->postbufq; | |
10954 | ||
25985edc | 10955 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
10956 | spin_lock_irq(&phba->hbalock); |
10957 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
10958 | if (mp->buffer_tag == tag) { | |
10959 | list_del_init(&mp->list); | |
10960 | pring->postbufq_cnt--; | |
10961 | spin_unlock_irq(&phba->hbalock); | |
10962 | return mp; | |
10963 | } | |
10964 | } | |
10965 | ||
10966 | spin_unlock_irq(&phba->hbalock); | |
10967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 10968 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
10969 | "ring %d Data x%lx x%p x%p x%x\n", |
10970 | pring->ringno, (unsigned long) tag, | |
10971 | slp->next, slp->prev, pring->postbufq_cnt); | |
10972 | ||
10973 | return NULL; | |
10974 | } | |
dea3101e | 10975 | |
e59058c4 | 10976 | /** |
3621a710 | 10977 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
10978 | * @phba: Pointer to HBA context object. |
10979 | * @pring: Pointer to driver SLI ring object. | |
10980 | * @phys: DMA address of the buffer. | |
10981 | * | |
10982 | * This function searches the buffer list using the dma_address | |
10983 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
10984 | * corresponding to the dma_address. The function returns the | |
10985 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
10986 | * This function is called by the ct and els unsolicited event | |
10987 | * handlers to get the buffer associated with the unsolicited | |
10988 | * event. | |
10989 | * | |
10990 | * This function is called with no lock held. | |
10991 | **/ | |
dea3101e JB |
10992 | struct lpfc_dmabuf * |
10993 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
10994 | dma_addr_t phys) | |
10995 | { | |
10996 | struct lpfc_dmabuf *mp, *next_mp; | |
10997 | struct list_head *slp = &pring->postbufq; | |
10998 | ||
25985edc | 10999 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 11000 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
11001 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
11002 | if (mp->phys == phys) { | |
11003 | list_del_init(&mp->list); | |
11004 | pring->postbufq_cnt--; | |
2e0fef85 | 11005 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
11006 | return mp; |
11007 | } | |
11008 | } | |
11009 | ||
2e0fef85 | 11010 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 11011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 11012 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 11013 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 11014 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
11015 | slp->next, slp->prev, pring->postbufq_cnt); |
11016 | return NULL; | |
11017 | } | |
11018 | ||
e59058c4 | 11019 | /** |
3621a710 | 11020 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
11021 | * @phba: Pointer to HBA context object. |
11022 | * @cmdiocb: Pointer to driver command iocb object. | |
11023 | * @rspiocb: Pointer to driver response iocb object. | |
11024 | * | |
11025 | * This function is the completion handler for the abort iocbs for | |
11026 | * ELS commands. This function is called from the ELS ring event | |
11027 | * handler with no lock held. This function frees memory resources | |
11028 | * associated with the abort iocb. | |
11029 | **/ | |
dea3101e | 11030 | static void |
2e0fef85 JS |
11031 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
11032 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 11033 | { |
2e0fef85 | 11034 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 11035 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 11036 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
11037 | |
11038 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
11039 | |
11040 | /* | |
11041 | * Assume that the port already completed and returned, or | |
11042 | * will return the iocb. Just Log the message. | |
11043 | */ | |
2680eeaa JS |
11044 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
11045 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
11046 | ||
2e0fef85 | 11047 | spin_lock_irq(&phba->hbalock); |
45ed1190 | 11048 | if (phba->sli_rev < LPFC_SLI_REV4) { |
faa832e9 JS |
11049 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
11050 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && | |
11051 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { | |
11052 | spin_unlock_irq(&phba->hbalock); | |
11053 | goto release_iocb; | |
11054 | } | |
45ed1190 JS |
11055 | if (abort_iotag != 0 && |
11056 | abort_iotag <= phba->sli.last_iotag) | |
11057 | abort_iocb = | |
11058 | phba->sli.iocbq_lookup[abort_iotag]; | |
11059 | } else | |
11060 | /* For sli4 the abort_tag is the XRI, | |
11061 | * so the abort routine puts the iotag of the iocb | |
11062 | * being aborted in the context field of the abort | |
11063 | * IOCB. | |
11064 | */ | |
11065 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 11066 | |
2a9bf3d0 JS |
11067 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
11068 | "0327 Cannot abort els iocb %p " | |
11069 | "with tag %x context %x, abort status %x, " | |
11070 | "abort code %x\n", | |
11071 | abort_iocb, abort_iotag, abort_context, | |
11072 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 11073 | |
ff78d8f9 | 11074 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 11075 | } |
faa832e9 | 11076 | release_iocb: |
604a3e30 | 11077 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
11078 | return; |
11079 | } | |
11080 | ||
e59058c4 | 11081 | /** |
3621a710 | 11082 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
11083 | * @phba: Pointer to HBA context object. |
11084 | * @cmdiocb: Pointer to driver command iocb object. | |
11085 | * @rspiocb: Pointer to driver response iocb object. | |
11086 | * | |
11087 | * The function is called from SLI ring event handler with no | |
11088 | * lock held. This function is the completion handler for ELS commands | |
11089 | * which are aborted. The function frees memory resources used for | |
11090 | * the aborted ELS commands. | |
11091 | **/ | |
92d7f7b0 JS |
11092 | static void |
11093 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
11094 | struct lpfc_iocbq *rspiocb) | |
11095 | { | |
11096 | IOCB_t *irsp = &rspiocb->iocb; | |
11097 | ||
11098 | /* ELS cmd tag <ulpIoTag> completes */ | |
11099 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 11100 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 11101 | "x%x x%x x%x\n", |
e8b62011 | 11102 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 11103 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
11104 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
11105 | lpfc_ct_free_iocb(phba, cmdiocb); | |
11106 | else | |
11107 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
11108 | return; |
11109 | } | |
11110 | ||
e59058c4 | 11111 | /** |
5af5eee7 | 11112 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
11113 | * @phba: Pointer to HBA context object. |
11114 | * @pring: Pointer to driver SLI ring object. | |
11115 | * @cmdiocb: Pointer to driver command iocb object. | |
11116 | * | |
5af5eee7 JS |
11117 | * This function issues an abort iocb for the provided command iocb down to |
11118 | * the port. Other than the case the outstanding command iocb is an abort | |
11119 | * request, this function issues abort out unconditionally. This function is | |
11120 | * called with hbalock held. The function returns 0 when it fails due to | |
11121 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 11122 | **/ |
5af5eee7 JS |
11123 | static int |
11124 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 11125 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 11126 | { |
2e0fef85 | 11127 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 11128 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
11129 | IOCB_t *icmd = NULL; |
11130 | IOCB_t *iabt = NULL; | |
5af5eee7 | 11131 | int retval; |
7e56aa25 | 11132 | unsigned long iflags; |
faa832e9 | 11133 | struct lpfc_nodelist *ndlp; |
07951076 | 11134 | |
1c2ba475 JT |
11135 | lockdep_assert_held(&phba->hbalock); |
11136 | ||
92d7f7b0 JS |
11137 | /* |
11138 | * There are certain command types we don't want to abort. And we | |
11139 | * don't want to abort commands that are already in the process of | |
11140 | * being aborted. | |
07951076 JS |
11141 | */ |
11142 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 11143 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
11144 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
11145 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
11146 | return 0; |
11147 | ||
dea3101e | 11148 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 11149 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
11150 | if (abtsiocbp == NULL) |
11151 | return 0; | |
dea3101e | 11152 | |
07951076 | 11153 | /* This signals the response to set the correct status |
341af102 | 11154 | * before calling the completion handler |
07951076 JS |
11155 | */ |
11156 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
11157 | ||
dea3101e | 11158 | iabt = &abtsiocbp->iocb; |
07951076 JS |
11159 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
11160 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 11161 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 11162 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 | 11163 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
faa832e9 | 11164 | } else { |
da0436e9 | 11165 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
faa832e9 JS |
11166 | if (pring->ringno == LPFC_ELS_RING) { |
11167 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); | |
11168 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; | |
11169 | } | |
11170 | } | |
07951076 JS |
11171 | iabt->ulpLe = 1; |
11172 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 11173 | |
5ffc266e | 11174 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
895427bd | 11175 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
341af102 JS |
11176 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
11177 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
11178 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
11179 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; | |
5ffc266e | 11180 | |
2e0fef85 | 11181 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
11182 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
11183 | else | |
11184 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 11185 | |
07951076 | 11186 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
e6c6acc0 | 11187 | abtsiocbp->vport = vport; |
5b8bd0c9 | 11188 | |
e8b62011 JS |
11189 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
11190 | "0339 Abort xri x%x, original iotag x%x, " | |
11191 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 11192 | iabt->un.acxri.abortIoTag, |
e8b62011 | 11193 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 11194 | abtsiocbp->iotag); |
7e56aa25 JS |
11195 | |
11196 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
895427bd JS |
11197 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
11198 | if (unlikely(pring == NULL)) | |
9bd2bff5 | 11199 | return 0; |
7e56aa25 JS |
11200 | /* Note: both hbalock and ring_lock need to be set here */ |
11201 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
11202 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
11203 | abtsiocbp, 0); | |
11204 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
11205 | } else { | |
11206 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
11207 | abtsiocbp, 0); | |
11208 | } | |
dea3101e | 11209 | |
d7c255b2 JS |
11210 | if (retval) |
11211 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
11212 | |
11213 | /* | |
11214 | * Caller to this routine should check for IOCB_ERROR | |
11215 | * and handle it properly. This routine no longer removes | |
11216 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
11217 | */ | |
11218 | return retval; | |
11219 | } | |
11220 | ||
11221 | /** | |
11222 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
11223 | * @phba: Pointer to HBA context object. | |
11224 | * @pring: Pointer to driver SLI ring object. | |
11225 | * @cmdiocb: Pointer to driver command iocb object. | |
11226 | * | |
11227 | * This function issues an abort iocb for the provided command iocb. In case | |
11228 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
11229 | * ring. Instead, the callback function shall be changed to those commands | |
11230 | * so that nothing happens when them finishes. This function is called with | |
11231 | * hbalock held. The function returns 0 when the command iocb is an abort | |
11232 | * request. | |
11233 | **/ | |
11234 | int | |
11235 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
11236 | struct lpfc_iocbq *cmdiocb) | |
11237 | { | |
11238 | struct lpfc_vport *vport = cmdiocb->vport; | |
11239 | int retval = IOCB_ERROR; | |
11240 | IOCB_t *icmd = NULL; | |
11241 | ||
1c2ba475 JT |
11242 | lockdep_assert_held(&phba->hbalock); |
11243 | ||
5af5eee7 JS |
11244 | /* |
11245 | * There are certain command types we don't want to abort. And we | |
11246 | * don't want to abort commands that are already in the process of | |
11247 | * being aborted. | |
11248 | */ | |
11249 | icmd = &cmdiocb->iocb; | |
11250 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
11251 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
11252 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
11253 | return 0; | |
11254 | ||
1234a6d5 DK |
11255 | if (!pring) { |
11256 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
11257 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
11258 | else | |
11259 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
11260 | goto abort_iotag_exit; | |
11261 | } | |
11262 | ||
5af5eee7 JS |
11263 | /* |
11264 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
11265 | * the callback so that nothing happens when it finishes. | |
11266 | */ | |
11267 | if ((vport->load_flag & FC_UNLOADING) && | |
11268 | (pring->ringno == LPFC_ELS_RING)) { | |
11269 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
11270 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
11271 | else | |
11272 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
11273 | goto abort_iotag_exit; | |
11274 | } | |
11275 | ||
11276 | /* Now, we try to issue the abort to the cmdiocb out */ | |
11277 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
11278 | ||
07951076 | 11279 | abort_iotag_exit: |
2e0fef85 JS |
11280 | /* |
11281 | * Caller to this routine should check for IOCB_ERROR | |
11282 | * and handle it properly. This routine no longer removes | |
11283 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 11284 | */ |
2e0fef85 | 11285 | return retval; |
dea3101e JB |
11286 | } |
11287 | ||
895427bd JS |
11288 | /** |
11289 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb | |
11290 | * @phba: Pointer to HBA context object. | |
11291 | * @pring: Pointer to driver SLI ring object. | |
11292 | * @cmdiocb: Pointer to driver command iocb object. | |
11293 | * | |
11294 | * This function issues an abort iocb for the provided command iocb down to | |
11295 | * the port. Other than the case the outstanding command iocb is an abort | |
11296 | * request, this function issues abort out unconditionally. This function is | |
11297 | * called with hbalock held. The function returns 0 when it fails due to | |
11298 | * memory allocation failure or when the command iocb is an abort request. | |
11299 | **/ | |
11300 | static int | |
11301 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
11302 | struct lpfc_iocbq *cmdiocb) | |
11303 | { | |
11304 | struct lpfc_vport *vport = cmdiocb->vport; | |
11305 | struct lpfc_iocbq *abtsiocbp; | |
205e8240 | 11306 | union lpfc_wqe128 *abts_wqe; |
895427bd JS |
11307 | int retval; |
11308 | ||
11309 | /* | |
11310 | * There are certain command types we don't want to abort. And we | |
11311 | * don't want to abort commands that are already in the process of | |
11312 | * being aborted. | |
11313 | */ | |
11314 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
11315 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || | |
11316 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
11317 | return 0; | |
11318 | ||
11319 | /* issue ABTS for this io based on iotag */ | |
11320 | abtsiocbp = __lpfc_sli_get_iocbq(phba); | |
11321 | if (abtsiocbp == NULL) | |
11322 | return 0; | |
11323 | ||
11324 | /* This signals the response to set the correct status | |
11325 | * before calling the completion handler | |
11326 | */ | |
11327 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
11328 | ||
11329 | /* Complete prepping the abort wqe and issue to the FW. */ | |
11330 | abts_wqe = &abtsiocbp->wqe; | |
11331 | bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0); | |
11332 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); | |
11333 | ||
11334 | /* Explicitly set reserved fields to zero.*/ | |
11335 | abts_wqe->abort_cmd.rsrvd4 = 0; | |
11336 | abts_wqe->abort_cmd.rsrvd5 = 0; | |
11337 | ||
11338 | /* WQE Common - word 6. Context is XRI tag. Set 0. */ | |
11339 | bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0); | |
11340 | bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0); | |
11341 | ||
11342 | /* word 7 */ | |
11343 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); | |
11344 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); | |
11345 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, | |
11346 | cmdiocb->iocb.ulpClass); | |
11347 | ||
11348 | /* word 8 - tell the FW to abort the IO associated with this | |
11349 | * outstanding exchange ID. | |
11350 | */ | |
11351 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; | |
11352 | ||
11353 | /* word 9 - this is the iotag for the abts_wqe completion. */ | |
11354 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, | |
11355 | abtsiocbp->iotag); | |
11356 | ||
11357 | /* word 10 */ | |
11358 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx); | |
11359 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); | |
11360 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); | |
11361 | ||
11362 | /* word 11 */ | |
11363 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); | |
11364 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); | |
11365 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
11366 | ||
11367 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
11368 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; | |
11369 | abtsiocbp->vport = vport; | |
01649561 | 11370 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
895427bd | 11371 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
cd22d605 | 11372 | if (retval) { |
895427bd JS |
11373 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
11374 | "6147 Failed abts issue_wqe with status x%x " | |
11375 | "for oxid x%x\n", | |
11376 | retval, cmdiocb->sli4_xritag); | |
11377 | lpfc_sli_release_iocbq(phba, abtsiocbp); | |
11378 | return retval; | |
11379 | } | |
11380 | ||
11381 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, | |
11382 | "6148 Drv Abort NVME Request Issued for " | |
11383 | "ox_id x%x on reqtag x%x\n", | |
11384 | cmdiocb->sli4_xritag, | |
11385 | abtsiocbp->iotag); | |
11386 | ||
11387 | return retval; | |
11388 | } | |
11389 | ||
5af5eee7 JS |
11390 | /** |
11391 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
11392 | * @phba: pointer to lpfc HBA data structure. | |
11393 | * | |
11394 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
11395 | **/ | |
11396 | void | |
11397 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
11398 | { | |
11399 | struct lpfc_sli *psli = &phba->sli; | |
11400 | struct lpfc_sli_ring *pring; | |
895427bd | 11401 | struct lpfc_queue *qp = NULL; |
5af5eee7 JS |
11402 | int i; |
11403 | ||
895427bd JS |
11404 | if (phba->sli_rev != LPFC_SLI_REV4) { |
11405 | for (i = 0; i < psli->num_rings; i++) { | |
11406 | pring = &psli->sli3_ring[i]; | |
11407 | lpfc_sli_abort_iocb_ring(phba, pring); | |
11408 | } | |
11409 | return; | |
11410 | } | |
11411 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
11412 | pring = qp->pring; | |
11413 | if (!pring) | |
11414 | continue; | |
db55fba8 | 11415 | lpfc_sli_abort_iocb_ring(phba, pring); |
5af5eee7 JS |
11416 | } |
11417 | } | |
11418 | ||
e59058c4 | 11419 | /** |
3621a710 | 11420 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
11421 | * @iocbq: Pointer to driver iocb object. |
11422 | * @vport: Pointer to driver virtual port object. | |
11423 | * @tgt_id: SCSI ID of the target. | |
11424 | * @lun_id: LUN ID of the scsi device. | |
11425 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
11426 | * | |
3621a710 | 11427 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
11428 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
11429 | * 0 if the filtering criteria is met for the given iocb and will return | |
11430 | * 1 if the filtering criteria is not met. | |
11431 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
11432 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
11433 | * lun_id parameter. | |
11434 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
11435 | * given iocb is for the SCSI target specified by vport and tgt_id | |
11436 | * parameters. | |
11437 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
11438 | * given iocb is for the SCSI host associated with the given vport. | |
11439 | * This function is called with no locks held. | |
11440 | **/ | |
dea3101e | 11441 | static int |
51ef4c26 JS |
11442 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
11443 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 11444 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 11445 | { |
0bd4ca25 | 11446 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
11447 | int rc = 1; |
11448 | ||
b0e83012 | 11449 | if (iocbq->vport != vport) |
0bd4ca25 JSEC |
11450 | return rc; |
11451 | ||
b0e83012 JS |
11452 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
11453 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) | |
51ef4c26 JS |
11454 | return rc; |
11455 | ||
0bd4ca25 | 11456 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 11457 | |
495a714c | 11458 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
11459 | return rc; |
11460 | ||
11461 | switch (ctx_cmd) { | |
11462 | case LPFC_CTX_LUN: | |
b0e83012 | 11463 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
495a714c JS |
11464 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
11465 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
11466 | rc = 0; |
11467 | break; | |
11468 | case LPFC_CTX_TGT: | |
b0e83012 | 11469 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
495a714c | 11470 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
dea3101e JB |
11471 | rc = 0; |
11472 | break; | |
dea3101e JB |
11473 | case LPFC_CTX_HOST: |
11474 | rc = 0; | |
11475 | break; | |
11476 | default: | |
11477 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 11478 | __func__, ctx_cmd); |
dea3101e JB |
11479 | break; |
11480 | } | |
11481 | ||
11482 | return rc; | |
11483 | } | |
11484 | ||
e59058c4 | 11485 | /** |
3621a710 | 11486 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
11487 | * @vport: Pointer to virtual port. |
11488 | * @tgt_id: SCSI ID of the target. | |
11489 | * @lun_id: LUN ID of the scsi device. | |
11490 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
11491 | * | |
11492 | * This function returns number of FCP commands pending for the vport. | |
11493 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
11494 | * commands pending on the vport associated with SCSI device specified | |
11495 | * by tgt_id and lun_id parameters. | |
11496 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
11497 | * commands pending on the vport associated with SCSI target specified | |
11498 | * by tgt_id parameter. | |
11499 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
11500 | * commands pending on the vport. | |
11501 | * This function returns the number of iocbs which satisfy the filter. | |
11502 | * This function is called without any lock held. | |
11503 | **/ | |
dea3101e | 11504 | int |
51ef4c26 JS |
11505 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
11506 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 11507 | { |
51ef4c26 | 11508 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
11509 | struct lpfc_iocbq *iocbq; |
11510 | int sum, i; | |
dea3101e | 11511 | |
31979008 | 11512 | spin_lock_irq(&phba->hbalock); |
0bd4ca25 JSEC |
11513 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
11514 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 11515 | |
51ef4c26 JS |
11516 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
11517 | ctx_cmd) == 0) | |
0bd4ca25 | 11518 | sum++; |
dea3101e | 11519 | } |
31979008 | 11520 | spin_unlock_irq(&phba->hbalock); |
0bd4ca25 | 11521 | |
dea3101e JB |
11522 | return sum; |
11523 | } | |
11524 | ||
e59058c4 | 11525 | /** |
3621a710 | 11526 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
11527 | * @phba: Pointer to HBA context object |
11528 | * @cmdiocb: Pointer to command iocb object. | |
11529 | * @rspiocb: Pointer to response iocb object. | |
11530 | * | |
11531 | * This function is called when an aborted FCP iocb completes. This | |
11532 | * function is called by the ring event handler with no lock held. | |
11533 | * This function frees the iocb. | |
11534 | **/ | |
5eb95af0 | 11535 | void |
2e0fef85 JS |
11536 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
11537 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 11538 | { |
cb69f7de | 11539 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8e668af5 | 11540 | "3096 ABORT_XRI_CN completing on rpi x%x " |
cb69f7de JS |
11541 | "original iotag x%x, abort cmd iotag x%x " |
11542 | "status 0x%x, reason 0x%x\n", | |
11543 | cmdiocb->iocb.un.acxri.abortContextTag, | |
11544 | cmdiocb->iocb.un.acxri.abortIoTag, | |
11545 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
11546 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 11547 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
11548 | return; |
11549 | } | |
11550 | ||
e59058c4 | 11551 | /** |
3621a710 | 11552 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
11553 | * @vport: Pointer to virtual port. |
11554 | * @pring: Pointer to driver SLI ring object. | |
11555 | * @tgt_id: SCSI ID of the target. | |
11556 | * @lun_id: LUN ID of the scsi device. | |
11557 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
11558 | * | |
11559 | * This function sends an abort command for every SCSI command | |
11560 | * associated with the given virtual port pending on the ring | |
11561 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
11562 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
11563 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
11564 | * parameters | |
11565 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
11566 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
11567 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
11568 | * FCP iocbs associated with virtual port. | |
11569 | * This function returns number of iocbs it failed to abort. | |
11570 | * This function is called with no locks held. | |
11571 | **/ | |
dea3101e | 11572 | int |
51ef4c26 JS |
11573 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
11574 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 11575 | { |
51ef4c26 | 11576 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
11577 | struct lpfc_iocbq *iocbq; |
11578 | struct lpfc_iocbq *abtsiocb; | |
ecbb227e | 11579 | struct lpfc_sli_ring *pring_s4; |
dea3101e | 11580 | IOCB_t *cmd = NULL; |
dea3101e | 11581 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 11582 | int i; |
dea3101e | 11583 | |
b0e83012 JS |
11584 | /* all I/Os are in process of being flushed */ |
11585 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) | |
11586 | return errcnt; | |
11587 | ||
0bd4ca25 JSEC |
11588 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
11589 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 11590 | |
51ef4c26 | 11591 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 11592 | abort_cmd) != 0) |
dea3101e JB |
11593 | continue; |
11594 | ||
afbd8d88 JS |
11595 | /* |
11596 | * If the iocbq is already being aborted, don't take a second | |
11597 | * action, but do count it. | |
11598 | */ | |
11599 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
11600 | continue; | |
11601 | ||
dea3101e | 11602 | /* issue ABTS for this IOCB based on iotag */ |
0bd4ca25 | 11603 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
11604 | if (abtsiocb == NULL) { |
11605 | errcnt++; | |
11606 | continue; | |
11607 | } | |
dea3101e | 11608 | |
afbd8d88 JS |
11609 | /* indicate the IO is being aborted by the driver. */ |
11610 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
11611 | ||
0bd4ca25 | 11612 | cmd = &iocbq->iocb; |
dea3101e JB |
11613 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
11614 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
11615 | if (phba->sli_rev == LPFC_SLI_REV4) |
11616 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
11617 | else | |
11618 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
11619 | abtsiocb->iocb.ulpLe = 1; |
11620 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
afbd8d88 | 11621 | abtsiocb->vport = vport; |
dea3101e | 11622 | |
5ffc266e | 11623 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
895427bd | 11624 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
341af102 JS |
11625 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
11626 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
11627 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
11628 | abtsiocb->iocb_flag |= LPFC_IO_FOF; | |
5ffc266e | 11629 | |
2e0fef85 | 11630 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
11631 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
11632 | else | |
11633 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
11634 | ||
5eb95af0 JSEC |
11635 | /* Setup callback routine and issue the command. */ |
11636 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
ecbb227e JS |
11637 | if (phba->sli_rev == LPFC_SLI_REV4) { |
11638 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); | |
11639 | if (!pring_s4) | |
11640 | continue; | |
11641 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, | |
11642 | abtsiocb, 0); | |
11643 | } else | |
11644 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, | |
11645 | abtsiocb, 0); | |
dea3101e | 11646 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 11647 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
11648 | errcnt++; |
11649 | continue; | |
11650 | } | |
11651 | } | |
11652 | ||
11653 | return errcnt; | |
11654 | } | |
11655 | ||
98912dda JS |
11656 | /** |
11657 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN | |
11658 | * @vport: Pointer to virtual port. | |
11659 | * @pring: Pointer to driver SLI ring object. | |
11660 | * @tgt_id: SCSI ID of the target. | |
11661 | * @lun_id: LUN ID of the scsi device. | |
11662 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
11663 | * | |
11664 | * This function sends an abort command for every SCSI command | |
11665 | * associated with the given virtual port pending on the ring | |
11666 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
11667 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
11668 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
11669 | * parameters | |
11670 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
11671 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
11672 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all | |
11673 | * FCP iocbs associated with virtual port. | |
11674 | * This function returns number of iocbs it aborted . | |
11675 | * This function is called with no locks held right after a taskmgmt | |
11676 | * command is sent. | |
11677 | **/ | |
11678 | int | |
11679 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | |
11680 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) | |
11681 | { | |
11682 | struct lpfc_hba *phba = vport->phba; | |
8c50d25c | 11683 | struct lpfc_scsi_buf *lpfc_cmd; |
98912dda | 11684 | struct lpfc_iocbq *abtsiocbq; |
8c50d25c | 11685 | struct lpfc_nodelist *ndlp; |
98912dda JS |
11686 | struct lpfc_iocbq *iocbq; |
11687 | IOCB_t *icmd; | |
11688 | int sum, i, ret_val; | |
11689 | unsigned long iflags; | |
11690 | struct lpfc_sli_ring *pring_s4; | |
98912dda | 11691 | |
59c68eaa | 11692 | spin_lock_irqsave(&phba->hbalock, iflags); |
98912dda JS |
11693 | |
11694 | /* all I/Os are in process of being flushed */ | |
11695 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { | |
59c68eaa | 11696 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
98912dda JS |
11697 | return 0; |
11698 | } | |
11699 | sum = 0; | |
11700 | ||
11701 | for (i = 1; i <= phba->sli.last_iotag; i++) { | |
11702 | iocbq = phba->sli.iocbq_lookup[i]; | |
11703 | ||
11704 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, | |
11705 | cmd) != 0) | |
11706 | continue; | |
11707 | ||
11708 | /* | |
11709 | * If the iocbq is already being aborted, don't take a second | |
11710 | * action, but do count it. | |
11711 | */ | |
11712 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
11713 | continue; | |
11714 | ||
11715 | /* issue ABTS for this IOCB based on iotag */ | |
11716 | abtsiocbq = __lpfc_sli_get_iocbq(phba); | |
11717 | if (abtsiocbq == NULL) | |
11718 | continue; | |
11719 | ||
11720 | icmd = &iocbq->iocb; | |
11721 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; | |
11722 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; | |
11723 | if (phba->sli_rev == LPFC_SLI_REV4) | |
11724 | abtsiocbq->iocb.un.acxri.abortIoTag = | |
11725 | iocbq->sli4_xritag; | |
11726 | else | |
11727 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; | |
11728 | abtsiocbq->iocb.ulpLe = 1; | |
11729 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; | |
11730 | abtsiocbq->vport = vport; | |
11731 | ||
11732 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ | |
895427bd | 11733 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
98912dda JS |
11734 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
11735 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; | |
9bd2bff5 JS |
11736 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
11737 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; | |
98912dda | 11738 | |
8c50d25c JS |
11739 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
11740 | ndlp = lpfc_cmd->rdata->pnode; | |
11741 | ||
11742 | if (lpfc_is_link_up(phba) && | |
11743 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) | |
98912dda JS |
11744 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
11745 | else | |
11746 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
11747 | ||
11748 | /* Setup callback routine and issue the command. */ | |
11749 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
11750 | ||
11751 | /* | |
11752 | * Indicate the IO is being aborted by the driver and set | |
11753 | * the caller's flag into the aborted IO. | |
11754 | */ | |
11755 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; | |
11756 | ||
11757 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
59c68eaa JS |
11758 | pring_s4 = lpfc_sli4_calc_ring(phba, abtsiocbq); |
11759 | if (!pring_s4) | |
895427bd | 11760 | continue; |
98912dda | 11761 | /* Note: both hbalock and ring_lock must be set here */ |
59c68eaa | 11762 | spin_lock(&pring_s4->ring_lock); |
98912dda JS |
11763 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
11764 | abtsiocbq, 0); | |
59c68eaa | 11765 | spin_unlock(&pring_s4->ring_lock); |
98912dda JS |
11766 | } else { |
11767 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
11768 | abtsiocbq, 0); | |
11769 | } | |
11770 | ||
11771 | ||
11772 | if (ret_val == IOCB_ERROR) | |
11773 | __lpfc_sli_release_iocbq(phba, abtsiocbq); | |
11774 | else | |
11775 | sum++; | |
11776 | } | |
59c68eaa | 11777 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
98912dda JS |
11778 | return sum; |
11779 | } | |
11780 | ||
e59058c4 | 11781 | /** |
3621a710 | 11782 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
11783 | * @phba: Pointer to HBA context object. |
11784 | * @cmdiocbq: Pointer to command iocb. | |
11785 | * @rspiocbq: Pointer to response iocb. | |
11786 | * | |
11787 | * This function is the completion handler for iocbs issued using | |
11788 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
11789 | * ring event handler function without any lock held. This function | |
11790 | * can be called from both worker thread context and interrupt | |
11791 | * context. This function also can be called from other thread which | |
11792 | * cleans up the SLI layer objects. | |
11793 | * This function copy the contents of the response iocb to the | |
11794 | * response iocb memory object provided by the caller of | |
11795 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
11796 | * sleeps for the iocb completion. | |
11797 | **/ | |
68876920 JSEC |
11798 | static void |
11799 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
11800 | struct lpfc_iocbq *cmdiocbq, | |
11801 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 11802 | { |
68876920 JSEC |
11803 | wait_queue_head_t *pdone_q; |
11804 | unsigned long iflags; | |
0f65ff68 | 11805 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 11806 | |
2e0fef85 | 11807 | spin_lock_irqsave(&phba->hbalock, iflags); |
5a0916b4 JS |
11808 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
11809 | ||
11810 | /* | |
11811 | * A time out has occurred for the iocb. If a time out | |
11812 | * completion handler has been supplied, call it. Otherwise, | |
11813 | * just free the iocbq. | |
11814 | */ | |
11815 | ||
11816 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11817 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; | |
11818 | cmdiocbq->wait_iocb_cmpl = NULL; | |
11819 | if (cmdiocbq->iocb_cmpl) | |
11820 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); | |
11821 | else | |
11822 | lpfc_sli_release_iocbq(phba, cmdiocbq); | |
11823 | return; | |
11824 | } | |
11825 | ||
68876920 JSEC |
11826 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
11827 | if (cmdiocbq->context2 && rspiocbq) | |
11828 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
11829 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
11830 | ||
0f65ff68 JS |
11831 | /* Set the exchange busy flag for task management commands */ |
11832 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
11833 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
11834 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
11835 | cur_iocbq); | |
11836 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
11837 | } | |
11838 | ||
68876920 | 11839 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
11840 | if (pdone_q) |
11841 | wake_up(pdone_q); | |
858c9f6c | 11842 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
11843 | return; |
11844 | } | |
11845 | ||
d11e31dd JS |
11846 | /** |
11847 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
11848 | * @phba: Pointer to HBA context object.. | |
11849 | * @piocbq: Pointer to command iocb. | |
11850 | * @flag: Flag to test. | |
11851 | * | |
11852 | * This routine grabs the hbalock and then test the iocb_flag to | |
11853 | * see if the passed in flag is set. | |
11854 | * Returns: | |
11855 | * 1 if flag is set. | |
11856 | * 0 if flag is not set. | |
11857 | **/ | |
11858 | static int | |
11859 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
11860 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
11861 | { | |
11862 | unsigned long iflags; | |
11863 | int ret; | |
11864 | ||
11865 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11866 | ret = piocbq->iocb_flag & flag; | |
11867 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11868 | return ret; | |
11869 | ||
11870 | } | |
11871 | ||
e59058c4 | 11872 | /** |
3621a710 | 11873 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
11874 | * @phba: Pointer to HBA context object.. |
11875 | * @pring: Pointer to sli ring. | |
11876 | * @piocb: Pointer to command iocb. | |
11877 | * @prspiocbq: Pointer to response iocb. | |
11878 | * @timeout: Timeout in number of seconds. | |
11879 | * | |
11880 | * This function issues the iocb to firmware and waits for the | |
5a0916b4 JS |
11881 | * iocb to complete. The iocb_cmpl field of the shall be used |
11882 | * to handle iocbs which time out. If the field is NULL, the | |
11883 | * function shall free the iocbq structure. If more clean up is | |
11884 | * needed, the caller is expected to provide a completion function | |
11885 | * that will provide the needed clean up. If the iocb command is | |
11886 | * not completed within timeout seconds, the function will either | |
11887 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the | |
11888 | * completion function set in the iocb_cmpl field and then return | |
11889 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb | |
11890 | * resources if this function returns IOCB_TIMEDOUT. | |
e59058c4 JS |
11891 | * The function waits for the iocb completion using an |
11892 | * non-interruptible wait. | |
11893 | * This function will sleep while waiting for iocb completion. | |
11894 | * So, this function should not be called from any context which | |
11895 | * does not allow sleeping. Due to the same reason, this function | |
11896 | * cannot be called with interrupt disabled. | |
11897 | * This function assumes that the iocb completions occur while | |
11898 | * this function sleep. So, this function cannot be called from | |
11899 | * the thread which process iocb completion for this ring. | |
11900 | * This function clears the iocb_flag of the iocb object before | |
11901 | * issuing the iocb and the iocb completion handler sets this | |
11902 | * flag and wakes this thread when the iocb completes. | |
11903 | * The contents of the response iocb will be copied to prspiocbq | |
11904 | * by the completion handler when the command completes. | |
11905 | * This function returns IOCB_SUCCESS when success. | |
11906 | * This function is called with no lock held. | |
11907 | **/ | |
dea3101e | 11908 | int |
2e0fef85 | 11909 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 11910 | uint32_t ring_number, |
2e0fef85 JS |
11911 | struct lpfc_iocbq *piocb, |
11912 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 11913 | uint32_t timeout) |
dea3101e | 11914 | { |
7259f0d0 | 11915 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
11916 | long timeleft, timeout_req = 0; |
11917 | int retval = IOCB_SUCCESS; | |
875fbdfe | 11918 | uint32_t creg_val; |
0e9bb8d7 JS |
11919 | struct lpfc_iocbq *iocb; |
11920 | int txq_cnt = 0; | |
11921 | int txcmplq_cnt = 0; | |
895427bd | 11922 | struct lpfc_sli_ring *pring; |
5a0916b4 JS |
11923 | unsigned long iflags; |
11924 | bool iocb_completed = true; | |
11925 | ||
895427bd JS |
11926 | if (phba->sli_rev >= LPFC_SLI_REV4) |
11927 | pring = lpfc_sli4_calc_ring(phba, piocb); | |
11928 | else | |
11929 | pring = &phba->sli.sli3_ring[ring_number]; | |
dea3101e | 11930 | /* |
68876920 JSEC |
11931 | * If the caller has provided a response iocbq buffer, then context2 |
11932 | * is NULL or its an error. | |
dea3101e | 11933 | */ |
68876920 JSEC |
11934 | if (prspiocbq) { |
11935 | if (piocb->context2) | |
11936 | return IOCB_ERROR; | |
11937 | piocb->context2 = prspiocbq; | |
dea3101e JB |
11938 | } |
11939 | ||
5a0916b4 | 11940 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
68876920 JSEC |
11941 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
11942 | piocb->context_un.wait_queue = &done_q; | |
5a0916b4 | 11943 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
dea3101e | 11944 | |
875fbdfe | 11945 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
11946 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
11947 | return IOCB_ERROR; | |
875fbdfe JSEC |
11948 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
11949 | writel(creg_val, phba->HCregaddr); | |
11950 | readl(phba->HCregaddr); /* flush */ | |
11951 | } | |
11952 | ||
2a9bf3d0 JS |
11953 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
11954 | SLI_IOCB_RET_IOCB); | |
68876920 | 11955 | if (retval == IOCB_SUCCESS) { |
256ec0d0 | 11956 | timeout_req = msecs_to_jiffies(timeout * 1000); |
68876920 | 11957 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 11958 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 11959 | timeout_req); |
5a0916b4 JS |
11960 | spin_lock_irqsave(&phba->hbalock, iflags); |
11961 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { | |
11962 | ||
11963 | /* | |
11964 | * IOCB timed out. Inform the wake iocb wait | |
11965 | * completion function and set local status | |
11966 | */ | |
dea3101e | 11967 | |
5a0916b4 JS |
11968 | iocb_completed = false; |
11969 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; | |
11970 | } | |
11971 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11972 | if (iocb_completed) { | |
7054a606 | 11973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 11974 | "0331 IOCB wake signaled\n"); |
53151bbb JS |
11975 | /* Note: we are not indicating if the IOCB has a success |
11976 | * status or not - that's for the caller to check. | |
11977 | * IOCB_SUCCESS means just that the command was sent and | |
11978 | * completed. Not that it completed successfully. | |
11979 | * */ | |
7054a606 | 11980 | } else if (timeleft == 0) { |
68876920 | 11981 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
11982 | "0338 IOCB wait timeout error - no " |
11983 | "wake response Data x%x\n", timeout); | |
68876920 | 11984 | retval = IOCB_TIMEDOUT; |
7054a606 | 11985 | } else { |
68876920 | 11986 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
11987 | "0330 IOCB wake NOT set, " |
11988 | "Data x%x x%lx\n", | |
68876920 JSEC |
11989 | timeout, (timeleft / jiffies)); |
11990 | retval = IOCB_TIMEDOUT; | |
dea3101e | 11991 | } |
2a9bf3d0 | 11992 | } else if (retval == IOCB_BUSY) { |
0e9bb8d7 JS |
11993 | if (phba->cfg_log_verbose & LOG_SLI) { |
11994 | list_for_each_entry(iocb, &pring->txq, list) { | |
11995 | txq_cnt++; | |
11996 | } | |
11997 | list_for_each_entry(iocb, &pring->txcmplq, list) { | |
11998 | txcmplq_cnt++; | |
11999 | } | |
12000 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
12001 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
12002 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); | |
12003 | } | |
2a9bf3d0 | 12004 | return retval; |
68876920 JSEC |
12005 | } else { |
12006 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 12007 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 12008 | retval); |
68876920 | 12009 | retval = IOCB_ERROR; |
dea3101e JB |
12010 | } |
12011 | ||
875fbdfe | 12012 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
12013 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
12014 | return IOCB_ERROR; | |
875fbdfe JSEC |
12015 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
12016 | writel(creg_val, phba->HCregaddr); | |
12017 | readl(phba->HCregaddr); /* flush */ | |
12018 | } | |
12019 | ||
68876920 JSEC |
12020 | if (prspiocbq) |
12021 | piocb->context2 = NULL; | |
12022 | ||
12023 | piocb->context_un.wait_queue = NULL; | |
12024 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
12025 | return retval; |
12026 | } | |
68876920 | 12027 | |
e59058c4 | 12028 | /** |
3621a710 | 12029 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
12030 | * @phba: Pointer to HBA context object. |
12031 | * @pmboxq: Pointer to driver mailbox object. | |
12032 | * @timeout: Timeout in number of seconds. | |
12033 | * | |
12034 | * This function issues the mailbox to firmware and waits for the | |
12035 | * mailbox command to complete. If the mailbox command is not | |
12036 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
12037 | * The function waits for the mailbox completion using an | |
12038 | * interruptible wait. If the thread is woken up due to a | |
12039 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
12040 | * should not free the mailbox resources, if this function returns | |
12041 | * MBX_TIMEOUT. | |
12042 | * This function will sleep while waiting for mailbox completion. | |
12043 | * So, this function should not be called from any context which | |
12044 | * does not allow sleeping. Due to the same reason, this function | |
12045 | * cannot be called with interrupt disabled. | |
12046 | * This function assumes that the mailbox completion occurs while | |
12047 | * this function sleep. So, this function cannot be called from | |
12048 | * the worker thread which processes mailbox completion. | |
12049 | * This function is called in the context of HBA management | |
12050 | * applications. | |
12051 | * This function returns MBX_SUCCESS when successful. | |
12052 | * This function is called with no lock held. | |
12053 | **/ | |
dea3101e | 12054 | int |
2e0fef85 | 12055 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
12056 | uint32_t timeout) |
12057 | { | |
e29d74f8 | 12058 | struct completion mbox_done; |
dea3101e | 12059 | int retval; |
858c9f6c | 12060 | unsigned long flag; |
dea3101e | 12061 | |
495a714c | 12062 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
12063 | /* setup wake call as IOCB callback */ |
12064 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
dea3101e | 12065 | |
e29d74f8 JS |
12066 | /* setup context3 field to pass wait_queue pointer to wake function */ |
12067 | init_completion(&mbox_done); | |
12068 | pmboxq->context3 = &mbox_done; | |
dea3101e JB |
12069 | /* now issue the command */ |
12070 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 12071 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
e29d74f8 JS |
12072 | wait_for_completion_timeout(&mbox_done, |
12073 | msecs_to_jiffies(timeout * 1000)); | |
7054a606 | 12074 | |
858c9f6c | 12075 | spin_lock_irqsave(&phba->hbalock, flag); |
e29d74f8 | 12076 | pmboxq->context3 = NULL; |
7054a606 JS |
12077 | /* |
12078 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
12079 | * else do not free the resources. | |
12080 | */ | |
d7c47992 | 12081 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 12082 | retval = MBX_SUCCESS; |
d7c47992 | 12083 | } else { |
7054a606 | 12084 | retval = MBX_TIMEOUT; |
858c9f6c JS |
12085 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
12086 | } | |
12087 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e | 12088 | } |
dea3101e JB |
12089 | return retval; |
12090 | } | |
12091 | ||
e59058c4 | 12092 | /** |
3772a991 | 12093 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
12094 | * @phba: Pointer to HBA context. |
12095 | * | |
3772a991 JS |
12096 | * This function is called to shutdown the driver's mailbox sub-system. |
12097 | * It first marks the mailbox sub-system is in a block state to prevent | |
12098 | * the asynchronous mailbox command from issued off the pending mailbox | |
12099 | * command queue. If the mailbox command sub-system shutdown is due to | |
12100 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
12101 | * the mailbox sub-system flush routine to forcefully bring down the | |
12102 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
12103 | * as with offline or HBA function reset), this routine will wait for the | |
12104 | * outstanding mailbox command to complete before invoking the mailbox | |
12105 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 12106 | **/ |
3772a991 | 12107 | void |
618a5230 | 12108 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
b4c02652 | 12109 | { |
3772a991 | 12110 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 12111 | unsigned long timeout; |
b4c02652 | 12112 | |
618a5230 JS |
12113 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
12114 | /* delay 100ms for port state */ | |
12115 | msleep(100); | |
12116 | lpfc_sli_mbox_sys_flush(phba); | |
12117 | return; | |
12118 | } | |
a183a15f | 12119 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
d7069f09 | 12120 | |
523128e5 JS |
12121 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
12122 | local_bh_disable(); | |
12123 | ||
3772a991 JS |
12124 | spin_lock_irq(&phba->hbalock); |
12125 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
b4c02652 | 12126 | |
3772a991 | 12127 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3772a991 JS |
12128 | /* Determine how long we might wait for the active mailbox |
12129 | * command to be gracefully completed by firmware. | |
12130 | */ | |
a183a15f JS |
12131 | if (phba->sli.mbox_active) |
12132 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
12133 | phba->sli.mbox_active) * | |
12134 | 1000) + jiffies; | |
12135 | spin_unlock_irq(&phba->hbalock); | |
12136 | ||
523128e5 JS |
12137 | /* Enable softirqs again, done with phba->hbalock */ |
12138 | local_bh_enable(); | |
12139 | ||
3772a991 JS |
12140 | while (phba->sli.mbox_active) { |
12141 | /* Check active mailbox complete status every 2ms */ | |
12142 | msleep(2); | |
12143 | if (time_after(jiffies, timeout)) | |
12144 | /* Timeout, let the mailbox flush routine to | |
12145 | * forcefully release active mailbox command | |
12146 | */ | |
12147 | break; | |
12148 | } | |
523128e5 | 12149 | } else { |
d7069f09 JS |
12150 | spin_unlock_irq(&phba->hbalock); |
12151 | ||
523128e5 JS |
12152 | /* Enable softirqs again, done with phba->hbalock */ |
12153 | local_bh_enable(); | |
12154 | } | |
12155 | ||
3772a991 JS |
12156 | lpfc_sli_mbox_sys_flush(phba); |
12157 | } | |
ed957684 | 12158 | |
3772a991 JS |
12159 | /** |
12160 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
12161 | * @phba: Pointer to HBA context. | |
12162 | * | |
12163 | * This function is called to read the SLI3 device error attention registers | |
12164 | * for possible error attention events. The caller must hold the hostlock | |
12165 | * with spin_lock_irq(). | |
12166 | * | |
25985edc | 12167 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
12168 | * Register and returns 0 otherwise. |
12169 | **/ | |
12170 | static int | |
12171 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
12172 | { | |
12173 | uint32_t ha_copy; | |
b4c02652 | 12174 | |
3772a991 | 12175 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
12176 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
12177 | goto unplug_err; | |
12178 | ||
3772a991 JS |
12179 | if (ha_copy & HA_ERATT) { |
12180 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
12181 | if (lpfc_sli_read_hs(phba)) |
12182 | goto unplug_err; | |
b4c02652 | 12183 | |
3772a991 JS |
12184 | /* Check if there is a deferred error condition is active */ |
12185 | if ((HS_FFER1 & phba->work_hs) && | |
12186 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 12187 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 12188 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
12189 | /* Clear all interrupt enable conditions */ |
12190 | writel(0, phba->HCregaddr); | |
12191 | readl(phba->HCregaddr); | |
12192 | } | |
12193 | ||
12194 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
12195 | phba->work_ha |= HA_ERATT; |
12196 | /* Indicate polling handles this ERATT */ | |
12197 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
12198 | return 1; |
12199 | } | |
12200 | return 0; | |
9940b97b JS |
12201 | |
12202 | unplug_err: | |
12203 | /* Set the driver HS work bitmap */ | |
12204 | phba->work_hs |= UNPLUG_ERR; | |
12205 | /* Set the driver HA work bitmap */ | |
12206 | phba->work_ha |= HA_ERATT; | |
12207 | /* Indicate polling handles this ERATT */ | |
12208 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12209 | return 1; | |
b4c02652 JS |
12210 | } |
12211 | ||
da0436e9 JS |
12212 | /** |
12213 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
12214 | * @phba: Pointer to HBA context. | |
12215 | * | |
12216 | * This function is called to read the SLI4 device error attention registers | |
12217 | * for possible error attention events. The caller must hold the hostlock | |
12218 | * with spin_lock_irq(). | |
12219 | * | |
25985edc | 12220 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
12221 | * Register and returns 0 otherwise. |
12222 | **/ | |
12223 | static int | |
12224 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
12225 | { | |
12226 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
12227 | uint32_t if_type, portsmphr; |
12228 | struct lpfc_register portstat_reg; | |
da0436e9 | 12229 | |
2fcee4bf JS |
12230 | /* |
12231 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
12232 | * registers for error attention. This can be changed later. |
12233 | */ | |
2fcee4bf JS |
12234 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
12235 | switch (if_type) { | |
12236 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
12237 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
12238 | &uerr_sta_lo) || | |
12239 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
12240 | &uerr_sta_hi)) { | |
12241 | phba->work_hs |= UNPLUG_ERR; | |
12242 | phba->work_ha |= HA_ERATT; | |
12243 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12244 | return 1; | |
12245 | } | |
2fcee4bf JS |
12246 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
12247 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
12248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12249 | "1423 HBA Unrecoverable error: " | |
12250 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
12251 | "ue_mask_lo_reg=0x%x, " | |
12252 | "ue_mask_hi_reg=0x%x\n", | |
12253 | uerr_sta_lo, uerr_sta_hi, | |
12254 | phba->sli4_hba.ue_mask_lo, | |
12255 | phba->sli4_hba.ue_mask_hi); | |
12256 | phba->work_status[0] = uerr_sta_lo; | |
12257 | phba->work_status[1] = uerr_sta_hi; | |
12258 | phba->work_ha |= HA_ERATT; | |
12259 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12260 | return 1; | |
12261 | } | |
12262 | break; | |
12263 | case LPFC_SLI_INTF_IF_TYPE_2: | |
27d6ac0a | 12264 | case LPFC_SLI_INTF_IF_TYPE_6: |
9940b97b JS |
12265 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
12266 | &portstat_reg.word0) || | |
12267 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
12268 | &portsmphr)){ | |
12269 | phba->work_hs |= UNPLUG_ERR; | |
12270 | phba->work_ha |= HA_ERATT; | |
12271 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12272 | return 1; | |
12273 | } | |
2fcee4bf JS |
12274 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
12275 | phba->work_status[0] = | |
12276 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
12277 | phba->work_status[1] = | |
12278 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
12279 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2e90f4b5 | 12280 | "2885 Port Status Event: " |
2fcee4bf JS |
12281 | "port status reg 0x%x, " |
12282 | "port smphr reg 0x%x, " | |
12283 | "error 1=0x%x, error 2=0x%x\n", | |
12284 | portstat_reg.word0, | |
12285 | portsmphr, | |
12286 | phba->work_status[0], | |
12287 | phba->work_status[1]); | |
12288 | phba->work_ha |= HA_ERATT; | |
12289 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12290 | return 1; | |
12291 | } | |
12292 | break; | |
12293 | case LPFC_SLI_INTF_IF_TYPE_1: | |
12294 | default: | |
a747c9ce | 12295 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
12296 | "2886 HBA Error Attention on unsupported " |
12297 | "if type %d.", if_type); | |
a747c9ce | 12298 | return 1; |
da0436e9 | 12299 | } |
2fcee4bf | 12300 | |
da0436e9 JS |
12301 | return 0; |
12302 | } | |
12303 | ||
e59058c4 | 12304 | /** |
3621a710 | 12305 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
12306 | * @phba: Pointer to HBA context. |
12307 | * | |
3772a991 | 12308 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
12309 | * error attention register bit for error attention events. |
12310 | * | |
25985edc | 12311 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
12312 | * Register and returns 0 otherwise. |
12313 | **/ | |
12314 | int | |
12315 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
12316 | { | |
12317 | uint32_t ha_copy; | |
12318 | ||
12319 | /* If somebody is waiting to handle an eratt, don't process it | |
12320 | * here. The brdkill function will do this. | |
12321 | */ | |
12322 | if (phba->link_flag & LS_IGNORE_ERATT) | |
12323 | return 0; | |
12324 | ||
12325 | /* Check if interrupt handler handles this ERATT */ | |
12326 | spin_lock_irq(&phba->hbalock); | |
12327 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
12328 | /* Interrupt handler has handled ERATT */ | |
12329 | spin_unlock_irq(&phba->hbalock); | |
12330 | return 0; | |
12331 | } | |
12332 | ||
a257bf90 JS |
12333 | /* |
12334 | * If there is deferred error attention, do not check for error | |
12335 | * attention | |
12336 | */ | |
12337 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
12338 | spin_unlock_irq(&phba->hbalock); | |
12339 | return 0; | |
12340 | } | |
12341 | ||
3772a991 JS |
12342 | /* If PCI channel is offline, don't process it */ |
12343 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 12344 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
12345 | return 0; |
12346 | } | |
12347 | ||
12348 | switch (phba->sli_rev) { | |
12349 | case LPFC_SLI_REV2: | |
12350 | case LPFC_SLI_REV3: | |
12351 | /* Read chip Host Attention (HA) register */ | |
12352 | ha_copy = lpfc_sli_eratt_read(phba); | |
12353 | break; | |
da0436e9 | 12354 | case LPFC_SLI_REV4: |
2fcee4bf | 12355 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
12356 | ha_copy = lpfc_sli4_eratt_read(phba); |
12357 | break; | |
3772a991 JS |
12358 | default: |
12359 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12360 | "0299 Invalid SLI revision (%d)\n", | |
12361 | phba->sli_rev); | |
12362 | ha_copy = 0; | |
12363 | break; | |
9399627f JS |
12364 | } |
12365 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
12366 | |
12367 | return ha_copy; | |
12368 | } | |
12369 | ||
12370 | /** | |
12371 | * lpfc_intr_state_check - Check device state for interrupt handling | |
12372 | * @phba: Pointer to HBA context. | |
12373 | * | |
12374 | * This inline routine checks whether a device or its PCI slot is in a state | |
12375 | * that the interrupt should be handled. | |
12376 | * | |
12377 | * This function returns 0 if the device or the PCI slot is in a state that | |
12378 | * interrupt should be handled, otherwise -EIO. | |
12379 | */ | |
12380 | static inline int | |
12381 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
12382 | { | |
12383 | /* If the pci channel is offline, ignore all the interrupts */ | |
12384 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
12385 | return -EIO; | |
12386 | ||
12387 | /* Update device level interrupt statistics */ | |
12388 | phba->sli.slistat.sli_intr++; | |
12389 | ||
12390 | /* Ignore all interrupts during initialization. */ | |
12391 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
12392 | return -EIO; | |
12393 | ||
9399627f JS |
12394 | return 0; |
12395 | } | |
12396 | ||
12397 | /** | |
3772a991 | 12398 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
12399 | * @irq: Interrupt number. |
12400 | * @dev_id: The device context pointer. | |
12401 | * | |
9399627f | 12402 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
12403 | * service routine when device with SLI-3 interface spec is enabled with |
12404 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
12405 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
12406 | * interrupt mode, this function is called as part of the device-level | |
12407 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
12408 | * is undergoing initialization, the interrupt handler will not process | |
12409 | * the interrupt. The link attention and ELS ring attention events are | |
12410 | * handled by the worker thread. The interrupt handler signals the worker | |
12411 | * thread and returns for these events. This function is called without | |
12412 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
12413 | * structures. |
12414 | * | |
12415 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
12416 | * returns IRQ_NONE. | |
e59058c4 | 12417 | **/ |
dea3101e | 12418 | irqreturn_t |
3772a991 | 12419 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 12420 | { |
2e0fef85 | 12421 | struct lpfc_hba *phba; |
a747c9ce | 12422 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
12423 | uint32_t work_ha_copy; |
12424 | unsigned long status; | |
5b75da2f | 12425 | unsigned long iflag; |
dea3101e JB |
12426 | uint32_t control; |
12427 | ||
92d7f7b0 | 12428 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
12429 | struct lpfc_vport *vport; |
12430 | struct lpfc_nodelist *ndlp; | |
12431 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
12432 | LPFC_MBOXQ_t *pmb; |
12433 | int rc; | |
12434 | ||
dea3101e JB |
12435 | /* |
12436 | * Get the driver's phba structure from the dev_id and | |
12437 | * assume the HBA is not interrupting. | |
12438 | */ | |
9399627f | 12439 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
12440 | |
12441 | if (unlikely(!phba)) | |
12442 | return IRQ_NONE; | |
12443 | ||
dea3101e | 12444 | /* |
9399627f JS |
12445 | * Stuff needs to be attented to when this function is invoked as an |
12446 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 12447 | */ |
9399627f | 12448 | if (phba->intr_type == MSIX) { |
3772a991 JS |
12449 | /* Check device state for handling interrupt */ |
12450 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
12451 | return IRQ_NONE; |
12452 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 12453 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
12454 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
12455 | goto unplug_error; | |
9399627f JS |
12456 | /* If somebody is waiting to handle an eratt don't process it |
12457 | * here. The brdkill function will do this. | |
12458 | */ | |
12459 | if (phba->link_flag & LS_IGNORE_ERATT) | |
12460 | ha_copy &= ~HA_ERATT; | |
12461 | /* Check the need for handling ERATT in interrupt handler */ | |
12462 | if (ha_copy & HA_ERATT) { | |
12463 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
12464 | /* ERATT polling has handled ERATT */ | |
12465 | ha_copy &= ~HA_ERATT; | |
12466 | else | |
12467 | /* Indicate interrupt handler handles ERATT */ | |
12468 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12469 | } | |
a257bf90 JS |
12470 | |
12471 | /* | |
12472 | * If there is deferred error attention, do not check for any | |
12473 | * interrupt. | |
12474 | */ | |
12475 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 12476 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
12477 | return IRQ_NONE; |
12478 | } | |
12479 | ||
9399627f | 12480 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
12481 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
12482 | goto unplug_error; | |
12483 | ||
a747c9ce JS |
12484 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
12485 | HC_LAINT_ENA | HC_ERINT_ENA), | |
12486 | phba->HCregaddr); | |
9399627f JS |
12487 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
12488 | phba->HAregaddr); | |
a747c9ce | 12489 | writel(hc_copy, phba->HCregaddr); |
9399627f | 12490 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 12491 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
12492 | } else |
12493 | ha_copy = phba->ha_copy; | |
dea3101e | 12494 | |
dea3101e JB |
12495 | work_ha_copy = ha_copy & phba->work_ha_mask; |
12496 | ||
9399627f | 12497 | if (work_ha_copy) { |
dea3101e JB |
12498 | if (work_ha_copy & HA_LATT) { |
12499 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
12500 | /* | |
12501 | * Turn off Link Attention interrupts | |
12502 | * until CLEAR_LA done | |
12503 | */ | |
5b75da2f | 12504 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 12505 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
12506 | if (lpfc_readl(phba->HCregaddr, &control)) |
12507 | goto unplug_error; | |
dea3101e JB |
12508 | control &= ~HC_LAINT_ENA; |
12509 | writel(control, phba->HCregaddr); | |
12510 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 12511 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
12512 | } |
12513 | else | |
12514 | work_ha_copy &= ~HA_LATT; | |
12515 | } | |
12516 | ||
9399627f | 12517 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
12518 | /* |
12519 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
12520 | * the only slow ring. | |
12521 | */ | |
12522 | status = (work_ha_copy & | |
12523 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
12524 | status >>= (4*LPFC_ELS_RING); | |
12525 | if (status & HA_RXMASK) { | |
5b75da2f | 12526 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
12527 | if (lpfc_readl(phba->HCregaddr, &control)) |
12528 | goto unplug_error; | |
a58cbd52 JS |
12529 | |
12530 | lpfc_debugfs_slow_ring_trc(phba, | |
12531 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
12532 | control, status, | |
12533 | (uint32_t)phba->sli.slistat.sli_intr); | |
12534 | ||
858c9f6c | 12535 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
12536 | lpfc_debugfs_slow_ring_trc(phba, |
12537 | "ISR Disable ring:" | |
12538 | "pwork:x%x hawork:x%x wait:x%x", | |
12539 | phba->work_ha, work_ha_copy, | |
12540 | (uint32_t)((unsigned long) | |
5e9d9b82 | 12541 | &phba->work_waitq)); |
a58cbd52 | 12542 | |
858c9f6c JS |
12543 | control &= |
12544 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
12545 | writel(control, phba->HCregaddr); |
12546 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 12547 | } |
a58cbd52 JS |
12548 | else { |
12549 | lpfc_debugfs_slow_ring_trc(phba, | |
12550 | "ISR slow ring: pwork:" | |
12551 | "x%x hawork:x%x wait:x%x", | |
12552 | phba->work_ha, work_ha_copy, | |
12553 | (uint32_t)((unsigned long) | |
5e9d9b82 | 12554 | &phba->work_waitq)); |
a58cbd52 | 12555 | } |
5b75da2f | 12556 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
12557 | } |
12558 | } | |
5b75da2f | 12559 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 12560 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
12561 | if (lpfc_sli_read_hs(phba)) |
12562 | goto unplug_error; | |
a257bf90 JS |
12563 | /* |
12564 | * Check if there is a deferred error condition | |
12565 | * is active | |
12566 | */ | |
12567 | if ((HS_FFER1 & phba->work_hs) && | |
12568 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
12569 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
12570 | phba->work_hs)) { | |
a257bf90 JS |
12571 | phba->hba_flag |= DEFER_ERATT; |
12572 | /* Clear all interrupt enable conditions */ | |
12573 | writel(0, phba->HCregaddr); | |
12574 | readl(phba->HCregaddr); | |
12575 | } | |
12576 | } | |
12577 | ||
9399627f | 12578 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 12579 | pmb = phba->sli.mbox_active; |
04c68496 | 12580 | pmbox = &pmb->u.mb; |
34b02dcd | 12581 | mbox = phba->mbox; |
858c9f6c | 12582 | vport = pmb->vport; |
92d7f7b0 JS |
12583 | |
12584 | /* First check out the status word */ | |
12585 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
12586 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 12587 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
12588 | /* |
12589 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
12590 | * mbxStatus <status> | |
12591 | */ | |
09372820 | 12592 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 12593 | LOG_SLI, |
e8b62011 | 12594 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
12595 | "Interrupt mbxCommand x%x " |
12596 | "mbxStatus x%x\n", | |
e8b62011 | 12597 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
12598 | pmbox->mbxCommand, |
12599 | pmbox->mbxStatus); | |
09372820 JS |
12600 | /* clear mailbox attention bit */ |
12601 | work_ha_copy &= ~HA_MBATT; | |
12602 | } else { | |
97eab634 | 12603 | phba->sli.mbox_active = NULL; |
5b75da2f | 12604 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
12605 | phba->last_completion_time = jiffies; |
12606 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
12607 | if (pmb->mbox_cmpl) { |
12608 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
12609 | MAILBOX_CMD_SIZE); | |
7a470277 | 12610 | if (pmb->out_ext_byte_len && |
3e1f0718 | 12611 | pmb->ctx_buf) |
7a470277 JS |
12612 | lpfc_sli_pcimem_bcopy( |
12613 | phba->mbox_ext, | |
3e1f0718 | 12614 | pmb->ctx_buf, |
7a470277 | 12615 | pmb->out_ext_byte_len); |
09372820 JS |
12616 | } |
12617 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
12618 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
12619 | ||
12620 | lpfc_debugfs_disc_trc(vport, | |
12621 | LPFC_DISC_TRC_MBOX_VPORT, | |
12622 | "MBOX dflt rpi: : " | |
12623 | "status:x%x rpi:x%x", | |
12624 | (uint32_t)pmbox->mbxStatus, | |
12625 | pmbox->un.varWords[0], 0); | |
12626 | ||
12627 | if (!pmbox->mbxStatus) { | |
12628 | mp = (struct lpfc_dmabuf *) | |
3e1f0718 | 12629 | (pmb->ctx_buf); |
09372820 | 12630 | ndlp = (struct lpfc_nodelist *) |
3e1f0718 | 12631 | pmb->ctx_ndlp; |
09372820 JS |
12632 | |
12633 | /* Reg_LOGIN of dflt RPI was | |
12634 | * successful. new lets get | |
12635 | * rid of the RPI using the | |
12636 | * same mbox buffer. | |
12637 | */ | |
12638 | lpfc_unreg_login(phba, | |
12639 | vport->vpi, | |
12640 | pmbox->un.varWords[0], | |
12641 | pmb); | |
12642 | pmb->mbox_cmpl = | |
12643 | lpfc_mbx_cmpl_dflt_rpi; | |
3e1f0718 JS |
12644 | pmb->ctx_buf = mp; |
12645 | pmb->ctx_ndlp = ndlp; | |
09372820 | 12646 | pmb->vport = vport; |
58da1ffb JS |
12647 | rc = lpfc_sli_issue_mbox(phba, |
12648 | pmb, | |
12649 | MBX_NOWAIT); | |
12650 | if (rc != MBX_BUSY) | |
12651 | lpfc_printf_log(phba, | |
12652 | KERN_ERR, | |
12653 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 12654 | "0350 rc should have" |
6a9c52cf | 12655 | "been MBX_BUSY\n"); |
3772a991 JS |
12656 | if (rc != MBX_NOT_FINISHED) |
12657 | goto send_current_mbox; | |
09372820 | 12658 | } |
858c9f6c | 12659 | } |
5b75da2f JS |
12660 | spin_lock_irqsave( |
12661 | &phba->pport->work_port_lock, | |
12662 | iflag); | |
09372820 JS |
12663 | phba->pport->work_port_events &= |
12664 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
12665 | spin_unlock_irqrestore( |
12666 | &phba->pport->work_port_lock, | |
12667 | iflag); | |
09372820 | 12668 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 12669 | } |
97eab634 | 12670 | } else |
5b75da2f | 12671 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 12672 | |
92d7f7b0 JS |
12673 | if ((work_ha_copy & HA_MBATT) && |
12674 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 12675 | send_current_mbox: |
92d7f7b0 | 12676 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
12677 | do { |
12678 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
12679 | MBX_NOWAIT); | |
12680 | } while (rc == MBX_NOT_FINISHED); | |
12681 | if (rc != MBX_SUCCESS) | |
12682 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
12683 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 12684 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
12685 | } |
12686 | ||
5b75da2f | 12687 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 12688 | phba->work_ha |= work_ha_copy; |
5b75da2f | 12689 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 12690 | lpfc_worker_wake_up(phba); |
dea3101e | 12691 | } |
9399627f | 12692 | return IRQ_HANDLED; |
9940b97b JS |
12693 | unplug_error: |
12694 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
12695 | return IRQ_HANDLED; | |
dea3101e | 12696 | |
3772a991 | 12697 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
12698 | |
12699 | /** | |
3772a991 | 12700 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
12701 | * @irq: Interrupt number. |
12702 | * @dev_id: The device context pointer. | |
12703 | * | |
12704 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
12705 | * service routine when device with SLI-3 interface spec is enabled with |
12706 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
12707 | * ring event in the HBA. However, when the device is enabled with either | |
12708 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
12709 | * device-level interrupt handler. When the PCI slot is in error recovery | |
12710 | * or the HBA is undergoing initialization, the interrupt handler will not | |
12711 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
12712 | * the intrrupt context. This function is called without any lock held. | |
12713 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
12714 | * |
12715 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
12716 | * returns IRQ_NONE. | |
12717 | **/ | |
12718 | irqreturn_t | |
3772a991 | 12719 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
12720 | { |
12721 | struct lpfc_hba *phba; | |
12722 | uint32_t ha_copy; | |
12723 | unsigned long status; | |
5b75da2f | 12724 | unsigned long iflag; |
895427bd | 12725 | struct lpfc_sli_ring *pring; |
9399627f JS |
12726 | |
12727 | /* Get the driver's phba structure from the dev_id and | |
12728 | * assume the HBA is not interrupting. | |
12729 | */ | |
12730 | phba = (struct lpfc_hba *) dev_id; | |
12731 | ||
12732 | if (unlikely(!phba)) | |
12733 | return IRQ_NONE; | |
12734 | ||
12735 | /* | |
12736 | * Stuff needs to be attented to when this function is invoked as an | |
12737 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
12738 | */ | |
12739 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
12740 | /* Check device state for handling interrupt */ |
12741 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
12742 | return IRQ_NONE; |
12743 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
12744 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
12745 | return IRQ_HANDLED; | |
9399627f | 12746 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 12747 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
12748 | /* |
12749 | * If there is deferred error attention, do not check for | |
12750 | * any interrupt. | |
12751 | */ | |
12752 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 12753 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
12754 | return IRQ_NONE; |
12755 | } | |
9399627f JS |
12756 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
12757 | phba->HAregaddr); | |
12758 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 12759 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
12760 | } else |
12761 | ha_copy = phba->ha_copy; | |
dea3101e JB |
12762 | |
12763 | /* | |
9399627f | 12764 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 12765 | */ |
9399627f JS |
12766 | ha_copy &= ~(phba->work_ha_mask); |
12767 | ||
12768 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 12769 | status >>= (4*LPFC_FCP_RING); |
895427bd | 12770 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
858c9f6c | 12771 | if (status & HA_RXMASK) |
895427bd | 12772 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
a4bc3379 JS |
12773 | |
12774 | if (phba->cfg_multi_ring_support == 2) { | |
12775 | /* | |
9399627f JS |
12776 | * Process all events on extra ring. Take the optimized path |
12777 | * for extra ring IO. | |
a4bc3379 | 12778 | */ |
9399627f | 12779 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 12780 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 12781 | if (status & HA_RXMASK) { |
a4bc3379 | 12782 | lpfc_sli_handle_fast_ring_event(phba, |
895427bd | 12783 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
a4bc3379 JS |
12784 | status); |
12785 | } | |
12786 | } | |
dea3101e | 12787 | return IRQ_HANDLED; |
3772a991 | 12788 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
12789 | |
12790 | /** | |
3772a991 | 12791 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
12792 | * @irq: Interrupt number. |
12793 | * @dev_id: The device context pointer. | |
12794 | * | |
3772a991 JS |
12795 | * This function is the HBA device-level interrupt handler to device with |
12796 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
12797 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
12798 | * requires driver attention. This function invokes the slow-path interrupt | |
12799 | * attention handling function and fast-path interrupt attention handling | |
12800 | * function in turn to process the relevant HBA attention events. This | |
12801 | * function is called without any lock held. It gets the hbalock to access | |
12802 | * and update SLI data structures. | |
9399627f JS |
12803 | * |
12804 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
12805 | * returns IRQ_NONE. | |
12806 | **/ | |
12807 | irqreturn_t | |
3772a991 | 12808 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
12809 | { |
12810 | struct lpfc_hba *phba; | |
12811 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
12812 | unsigned long status1, status2; | |
a747c9ce | 12813 | uint32_t hc_copy; |
9399627f JS |
12814 | |
12815 | /* | |
12816 | * Get the driver's phba structure from the dev_id and | |
12817 | * assume the HBA is not interrupting. | |
12818 | */ | |
12819 | phba = (struct lpfc_hba *) dev_id; | |
12820 | ||
12821 | if (unlikely(!phba)) | |
12822 | return IRQ_NONE; | |
12823 | ||
3772a991 JS |
12824 | /* Check device state for handling interrupt */ |
12825 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
12826 | return IRQ_NONE; |
12827 | ||
12828 | spin_lock(&phba->hbalock); | |
9940b97b JS |
12829 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
12830 | spin_unlock(&phba->hbalock); | |
12831 | return IRQ_HANDLED; | |
12832 | } | |
12833 | ||
9399627f JS |
12834 | if (unlikely(!phba->ha_copy)) { |
12835 | spin_unlock(&phba->hbalock); | |
12836 | return IRQ_NONE; | |
12837 | } else if (phba->ha_copy & HA_ERATT) { | |
12838 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
12839 | /* ERATT polling has handled ERATT */ | |
12840 | phba->ha_copy &= ~HA_ERATT; | |
12841 | else | |
12842 | /* Indicate interrupt handler handles ERATT */ | |
12843 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
12844 | } | |
12845 | ||
a257bf90 JS |
12846 | /* |
12847 | * If there is deferred error attention, do not check for any interrupt. | |
12848 | */ | |
12849 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 12850 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
12851 | return IRQ_NONE; |
12852 | } | |
12853 | ||
9399627f | 12854 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
12855 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
12856 | spin_unlock(&phba->hbalock); | |
12857 | return IRQ_HANDLED; | |
12858 | } | |
a747c9ce JS |
12859 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
12860 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
12861 | phba->HCregaddr); | |
9399627f | 12862 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 12863 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
12864 | readl(phba->HAregaddr); /* flush */ |
12865 | spin_unlock(&phba->hbalock); | |
12866 | ||
12867 | /* | |
12868 | * Invokes slow-path host attention interrupt handling as appropriate. | |
12869 | */ | |
12870 | ||
12871 | /* status of events with mailbox and link attention */ | |
12872 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
12873 | ||
12874 | /* status of events with ELS ring */ | |
12875 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
12876 | status2 >>= (4*LPFC_ELS_RING); | |
12877 | ||
12878 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 12879 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
12880 | else |
12881 | sp_irq_rc = IRQ_NONE; | |
12882 | ||
12883 | /* | |
12884 | * Invoke fast-path host attention interrupt handling as appropriate. | |
12885 | */ | |
12886 | ||
12887 | /* status of events with FCP ring */ | |
12888 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
12889 | status1 >>= (4*LPFC_FCP_RING); | |
12890 | ||
12891 | /* status of events with extra ring */ | |
12892 | if (phba->cfg_multi_ring_support == 2) { | |
12893 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
12894 | status2 >>= (4*LPFC_EXTRA_RING); | |
12895 | } else | |
12896 | status2 = 0; | |
12897 | ||
12898 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 12899 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
12900 | else |
12901 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 12902 | |
9399627f JS |
12903 | /* Return device-level interrupt handling status */ |
12904 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 12905 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
12906 | |
12907 | /** | |
12908 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
12909 | * @phba: pointer to lpfc hba data structure. | |
12910 | * | |
12911 | * This routine is invoked by the worker thread to process all the pending | |
12912 | * SLI4 FCP abort XRI events. | |
12913 | **/ | |
12914 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
12915 | { | |
12916 | struct lpfc_cq_event *cq_event; | |
12917 | ||
12918 | /* First, declare the fcp xri abort event has been handled */ | |
12919 | spin_lock_irq(&phba->hbalock); | |
12920 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
12921 | spin_unlock_irq(&phba->hbalock); | |
12922 | /* Now, handle all the fcp xri abort events */ | |
12923 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
12924 | /* Get the first event from the head of the event queue */ | |
12925 | spin_lock_irq(&phba->hbalock); | |
12926 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
12927 | cq_event, struct lpfc_cq_event, list); | |
12928 | spin_unlock_irq(&phba->hbalock); | |
12929 | /* Notify aborted XRI for FCP work queue */ | |
12930 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
12931 | /* Free the event processed back to the free pool */ | |
12932 | lpfc_sli4_cq_event_release(phba, cq_event); | |
12933 | } | |
12934 | } | |
12935 | ||
12936 | /** | |
12937 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
12938 | * @phba: pointer to lpfc hba data structure. | |
12939 | * | |
12940 | * This routine is invoked by the worker thread to process all the pending | |
12941 | * SLI4 els abort xri events. | |
12942 | **/ | |
12943 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
12944 | { | |
12945 | struct lpfc_cq_event *cq_event; | |
12946 | ||
12947 | /* First, declare the els xri abort event has been handled */ | |
12948 | spin_lock_irq(&phba->hbalock); | |
12949 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
12950 | spin_unlock_irq(&phba->hbalock); | |
12951 | /* Now, handle all the els xri abort events */ | |
12952 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
12953 | /* Get the first event from the head of the event queue */ | |
12954 | spin_lock_irq(&phba->hbalock); | |
12955 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
12956 | cq_event, struct lpfc_cq_event, list); | |
12957 | spin_unlock_irq(&phba->hbalock); | |
12958 | /* Notify aborted XRI for ELS work queue */ | |
12959 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
12960 | /* Free the event processed back to the free pool */ | |
12961 | lpfc_sli4_cq_event_release(phba, cq_event); | |
12962 | } | |
12963 | } | |
12964 | ||
341af102 JS |
12965 | /** |
12966 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
12967 | * @phba: pointer to lpfc hba data structure | |
12968 | * @pIocbIn: pointer to the rspiocbq | |
12969 | * @pIocbOut: pointer to the cmdiocbq | |
12970 | * @wcqe: pointer to the complete wcqe | |
12971 | * | |
12972 | * This routine transfers the fields of a command iocbq to a response iocbq | |
12973 | * by copying all the IOCB fields from command iocbq and transferring the | |
12974 | * completion status information from the complete wcqe. | |
12975 | **/ | |
4f774513 | 12976 | static void |
341af102 JS |
12977 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
12978 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
12979 | struct lpfc_iocbq *pIocbOut, |
12980 | struct lpfc_wcqe_complete *wcqe) | |
12981 | { | |
af22741c | 12982 | int numBdes, i; |
341af102 | 12983 | unsigned long iflags; |
af22741c JS |
12984 | uint32_t status, max_response; |
12985 | struct lpfc_dmabuf *dmabuf; | |
12986 | struct ulp_bde64 *bpl, bde; | |
4f774513 JS |
12987 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
12988 | ||
12989 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
12990 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 | 12991 | /* Map WCQE parameters into irspiocb parameters */ |
acd6859b JS |
12992 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
12993 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); | |
4f774513 JS |
12994 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
12995 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
12996 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
12997 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
12998 | wcqe->total_data_placed; | |
12999 | else | |
13000 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 13001 | else { |
4f774513 | 13002 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
af22741c JS |
13003 | switch (pIocbOut->iocb.ulpCommand) { |
13004 | case CMD_ELS_REQUEST64_CR: | |
13005 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
13006 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
13007 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); | |
13008 | max_response = bde.tus.f.bdeSize; | |
13009 | break; | |
13010 | case CMD_GEN_REQUEST64_CR: | |
13011 | max_response = 0; | |
13012 | if (!pIocbOut->context3) | |
13013 | break; | |
13014 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ | |
13015 | sizeof(struct ulp_bde64); | |
13016 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; | |
13017 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
13018 | for (i = 0; i < numBdes; i++) { | |
13019 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
13020 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
13021 | max_response += bde.tus.f.bdeSize; | |
13022 | } | |
13023 | break; | |
13024 | default: | |
13025 | max_response = wcqe->total_data_placed; | |
13026 | break; | |
13027 | } | |
13028 | if (max_response < wcqe->total_data_placed) | |
13029 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; | |
13030 | else | |
13031 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = | |
13032 | wcqe->total_data_placed; | |
695a814e | 13033 | } |
341af102 | 13034 | |
acd6859b JS |
13035 | /* Convert BG errors for completion status */ |
13036 | if (status == CQE_STATUS_DI_ERROR) { | |
13037 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
13038 | ||
13039 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) | |
13040 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; | |
13041 | else | |
13042 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; | |
13043 | ||
13044 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; | |
13045 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ | |
13046 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
13047 | BGS_GUARD_ERR_MASK; | |
13048 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ | |
13049 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
13050 | BGS_APPTAG_ERR_MASK; | |
13051 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ | |
13052 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
13053 | BGS_REFTAG_ERR_MASK; | |
13054 | ||
13055 | /* Check to see if there was any good data before the error */ | |
13056 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { | |
13057 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
13058 | BGS_HI_WATER_MARK_PRESENT_MASK; | |
13059 | pIocbIn->iocb.unsli3.sli3_bg.bghm = | |
13060 | wcqe->total_data_placed; | |
13061 | } | |
13062 | ||
13063 | /* | |
13064 | * Set ALL the error bits to indicate we don't know what | |
13065 | * type of error it is. | |
13066 | */ | |
13067 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) | |
13068 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
13069 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | | |
13070 | BGS_GUARD_ERR_MASK); | |
13071 | } | |
13072 | ||
341af102 JS |
13073 | /* Pick up HBA exchange busy condition */ |
13074 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
13075 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13076 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
13077 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13078 | } | |
4f774513 JS |
13079 | } |
13080 | ||
45ed1190 JS |
13081 | /** |
13082 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
13083 | * @phba: Pointer to HBA context object. | |
13084 | * @wcqe: Pointer to work-queue completion queue entry. | |
13085 | * | |
13086 | * This routine handles an ELS work-queue completion event and construct | |
13087 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
13088 | * discovery engine to handle. | |
13089 | * | |
13090 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
13091 | **/ | |
13092 | static struct lpfc_iocbq * | |
13093 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
13094 | struct lpfc_iocbq *irspiocbq) | |
13095 | { | |
895427bd | 13096 | struct lpfc_sli_ring *pring; |
45ed1190 JS |
13097 | struct lpfc_iocbq *cmdiocbq; |
13098 | struct lpfc_wcqe_complete *wcqe; | |
13099 | unsigned long iflags; | |
13100 | ||
895427bd | 13101 | pring = lpfc_phba_elsring(phba); |
1234a6d5 DK |
13102 | if (unlikely(!pring)) |
13103 | return NULL; | |
895427bd | 13104 | |
45ed1190 | 13105 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
7e56aa25 | 13106 | spin_lock_irqsave(&pring->ring_lock, iflags); |
45ed1190 JS |
13107 | pring->stats.iocb_event++; |
13108 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
13109 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
13110 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
45ed1190 | 13111 | if (unlikely(!cmdiocbq)) { |
401bb416 | 13112 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
45ed1190 JS |
13113 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
13114 | "0386 ELS complete with no corresponding " | |
401bb416 DK |
13115 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
13116 | wcqe->word0, wcqe->total_data_placed, | |
13117 | wcqe->parameter, wcqe->word3); | |
45ed1190 JS |
13118 | lpfc_sli_release_iocbq(phba, irspiocbq); |
13119 | return NULL; | |
13120 | } | |
13121 | ||
401bb416 DK |
13122 | /* Put the iocb back on the txcmplq */ |
13123 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); | |
13124 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
13125 | ||
45ed1190 | 13126 | /* Fake the irspiocbq and copy necessary response information */ |
341af102 | 13127 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
13128 | |
13129 | return irspiocbq; | |
13130 | } | |
13131 | ||
8a5ca109 JS |
13132 | inline struct lpfc_cq_event * |
13133 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) | |
13134 | { | |
13135 | struct lpfc_cq_event *cq_event; | |
13136 | ||
13137 | /* Allocate a new internal CQ_EVENT entry */ | |
13138 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
13139 | if (!cq_event) { | |
13140 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13141 | "0602 Failed to alloc CQ_EVENT entry\n"); | |
13142 | return NULL; | |
13143 | } | |
13144 | ||
13145 | /* Move the CQE into the event */ | |
13146 | memcpy(&cq_event->cqe, entry, size); | |
13147 | return cq_event; | |
13148 | } | |
13149 | ||
04c68496 JS |
13150 | /** |
13151 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
13152 | * @phba: Pointer to HBA context object. | |
13153 | * @cqe: Pointer to mailbox completion queue entry. | |
13154 | * | |
13155 | * This routine process a mailbox completion queue entry with asynchrous | |
13156 | * event. | |
13157 | * | |
13158 | * Return: true if work posted to worker thread, otherwise false. | |
13159 | **/ | |
13160 | static bool | |
13161 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
13162 | { | |
13163 | struct lpfc_cq_event *cq_event; | |
13164 | unsigned long iflags; | |
13165 | ||
13166 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
13167 | "0392 Async Event: word0:x%x, word1:x%x, " | |
13168 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
13169 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
13170 | ||
8a5ca109 JS |
13171 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
13172 | if (!cq_event) | |
04c68496 | 13173 | return false; |
04c68496 JS |
13174 | spin_lock_irqsave(&phba->hbalock, iflags); |
13175 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
13176 | /* Set the async event flag */ | |
13177 | phba->hba_flag |= ASYNC_EVENT; | |
13178 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13179 | ||
13180 | return true; | |
13181 | } | |
13182 | ||
13183 | /** | |
13184 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
13185 | * @phba: Pointer to HBA context object. | |
13186 | * @cqe: Pointer to mailbox completion queue entry. | |
13187 | * | |
13188 | * This routine process a mailbox completion queue entry with mailbox | |
13189 | * completion event. | |
13190 | * | |
13191 | * Return: true if work posted to worker thread, otherwise false. | |
13192 | **/ | |
13193 | static bool | |
13194 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
13195 | { | |
13196 | uint32_t mcqe_status; | |
13197 | MAILBOX_t *mbox, *pmbox; | |
13198 | struct lpfc_mqe *mqe; | |
13199 | struct lpfc_vport *vport; | |
13200 | struct lpfc_nodelist *ndlp; | |
13201 | struct lpfc_dmabuf *mp; | |
13202 | unsigned long iflags; | |
13203 | LPFC_MBOXQ_t *pmb; | |
13204 | bool workposted = false; | |
13205 | int rc; | |
13206 | ||
13207 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
13208 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
13209 | goto out_no_mqe_complete; | |
13210 | ||
13211 | /* Get the reference to the active mbox command */ | |
13212 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13213 | pmb = phba->sli.mbox_active; | |
13214 | if (unlikely(!pmb)) { | |
13215 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
13216 | "1832 No pending MBOX command to handle\n"); | |
13217 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13218 | goto out_no_mqe_complete; | |
13219 | } | |
13220 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13221 | mqe = &pmb->u.mqe; | |
13222 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
13223 | mbox = phba->mbox; | |
13224 | vport = pmb->vport; | |
13225 | ||
13226 | /* Reset heartbeat timer */ | |
13227 | phba->last_completion_time = jiffies; | |
13228 | del_timer(&phba->sli.mbox_tmo); | |
13229 | ||
13230 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
13231 | if (pmb->mbox_cmpl && mbox) | |
48f8fdb4 | 13232 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
04c68496 | 13233 | |
73d91e50 JS |
13234 | /* |
13235 | * For mcqe errors, conditionally move a modified error code to | |
13236 | * the mbox so that the error will not be missed. | |
13237 | */ | |
13238 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
13239 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
13240 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
13241 | bf_set(lpfc_mqe_status, mqe, | |
13242 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
13243 | } | |
04c68496 JS |
13244 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
13245 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
13246 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
13247 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
13248 | mcqe_status, | |
13249 | pmbox->un.varWords[0], 0); | |
13250 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
3e1f0718 JS |
13251 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
13252 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; | |
04c68496 JS |
13253 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
13254 | * RID of the PPI using the same mbox buffer. | |
13255 | */ | |
13256 | lpfc_unreg_login(phba, vport->vpi, | |
13257 | pmbox->un.varWords[0], pmb); | |
13258 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
3e1f0718 JS |
13259 | pmb->ctx_buf = mp; |
13260 | pmb->ctx_ndlp = ndlp; | |
04c68496 JS |
13261 | pmb->vport = vport; |
13262 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
13263 | if (rc != MBX_BUSY) | |
13264 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
13265 | LOG_SLI, "0385 rc should " | |
13266 | "have been MBX_BUSY\n"); | |
13267 | if (rc != MBX_NOT_FINISHED) | |
13268 | goto send_current_mbox; | |
13269 | } | |
13270 | } | |
13271 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
13272 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
13273 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
13274 | ||
13275 | /* There is mailbox completion work to do */ | |
13276 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13277 | __lpfc_mbox_cmpl_put(phba, pmb); | |
13278 | phba->work_ha |= HA_MBATT; | |
13279 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13280 | workposted = true; | |
13281 | ||
13282 | send_current_mbox: | |
13283 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13284 | /* Release the mailbox command posting token */ | |
13285 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
13286 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
13287 | phba->sli.mbox_active = NULL; | |
13288 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13289 | /* Wake up worker thread to post the next pending mailbox command */ | |
13290 | lpfc_worker_wake_up(phba); | |
13291 | out_no_mqe_complete: | |
13292 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
13293 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
13294 | return workposted; | |
13295 | } | |
13296 | ||
13297 | /** | |
13298 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
13299 | * @phba: Pointer to HBA context object. | |
13300 | * @cqe: Pointer to mailbox completion queue entry. | |
13301 | * | |
13302 | * This routine process a mailbox completion queue entry, it invokes the | |
13303 | * proper mailbox complete handling or asynchrous event handling routine | |
13304 | * according to the MCQE's async bit. | |
13305 | * | |
13306 | * Return: true if work posted to worker thread, otherwise false. | |
13307 | **/ | |
13308 | static bool | |
13309 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
13310 | { | |
13311 | struct lpfc_mcqe mcqe; | |
13312 | bool workposted; | |
13313 | ||
13314 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
48f8fdb4 | 13315 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
04c68496 JS |
13316 | |
13317 | /* Invoke the proper event handling routine */ | |
13318 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
13319 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
13320 | else | |
13321 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
13322 | return workposted; | |
13323 | } | |
13324 | ||
4f774513 JS |
13325 | /** |
13326 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
13327 | * @phba: Pointer to HBA context object. | |
2a76a283 | 13328 | * @cq: Pointer to associated CQ |
4f774513 JS |
13329 | * @wcqe: Pointer to work-queue completion queue entry. |
13330 | * | |
13331 | * This routine handles an ELS work-queue completion event. | |
13332 | * | |
13333 | * Return: true if work posted to worker thread, otherwise false. | |
13334 | **/ | |
13335 | static bool | |
2a76a283 | 13336 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
13337 | struct lpfc_wcqe_complete *wcqe) |
13338 | { | |
4f774513 JS |
13339 | struct lpfc_iocbq *irspiocbq; |
13340 | unsigned long iflags; | |
2a76a283 | 13341 | struct lpfc_sli_ring *pring = cq->pring; |
0e9bb8d7 JS |
13342 | int txq_cnt = 0; |
13343 | int txcmplq_cnt = 0; | |
13344 | int fcp_txcmplq_cnt = 0; | |
4f774513 | 13345 | |
11f0e34f JS |
13346 | /* Check for response status */ |
13347 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
13348 | /* Log the error status */ | |
13349 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
13350 | "0357 ELS CQE error: status=x%x: " | |
13351 | "CQE: %08x %08x %08x %08x\n", | |
13352 | bf_get(lpfc_wcqe_c_status, wcqe), | |
13353 | wcqe->word0, wcqe->total_data_placed, | |
13354 | wcqe->parameter, wcqe->word3); | |
13355 | } | |
13356 | ||
45ed1190 | 13357 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
13358 | irspiocbq = lpfc_sli_get_iocbq(phba); |
13359 | if (!irspiocbq) { | |
0e9bb8d7 JS |
13360 | if (!list_empty(&pring->txq)) |
13361 | txq_cnt++; | |
13362 | if (!list_empty(&pring->txcmplq)) | |
13363 | txcmplq_cnt++; | |
4f774513 | 13364 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2a9bf3d0 JS |
13365 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
13366 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
0e9bb8d7 JS |
13367 | txq_cnt, phba->iocb_cnt, |
13368 | fcp_txcmplq_cnt, | |
13369 | txcmplq_cnt); | |
45ed1190 | 13370 | return false; |
4f774513 | 13371 | } |
4f774513 | 13372 | |
45ed1190 JS |
13373 | /* Save off the slow-path queue event for work thread to process */ |
13374 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 13375 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 13376 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
13377 | &phba->sli4_hba.sp_queue_event); |
13378 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 13379 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 13380 | |
45ed1190 | 13381 | return true; |
4f774513 JS |
13382 | } |
13383 | ||
13384 | /** | |
13385 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
13386 | * @phba: Pointer to HBA context object. | |
13387 | * @wcqe: Pointer to work-queue completion queue entry. | |
13388 | * | |
3f8b6fb7 | 13389 | * This routine handles slow-path WQ entry consumed event by invoking the |
4f774513 JS |
13390 | * proper WQ release routine to the slow-path WQ. |
13391 | **/ | |
13392 | static void | |
13393 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
13394 | struct lpfc_wcqe_release *wcqe) | |
13395 | { | |
2e90f4b5 JS |
13396 | /* sanity check on queue memory */ |
13397 | if (unlikely(!phba->sli4_hba.els_wq)) | |
13398 | return; | |
4f774513 JS |
13399 | /* Check for the slow-path ELS work queue */ |
13400 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
13401 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
13402 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
13403 | else | |
13404 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
13405 | "2579 Slow-path wqe consume event carries " | |
13406 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
13407 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
13408 | phba->sli4_hba.els_wq->queue_id); | |
13409 | } | |
13410 | ||
13411 | /** | |
13412 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
13413 | * @phba: Pointer to HBA context object. | |
13414 | * @cq: Pointer to a WQ completion queue. | |
13415 | * @wcqe: Pointer to work-queue completion queue entry. | |
13416 | * | |
13417 | * This routine handles an XRI abort event. | |
13418 | * | |
13419 | * Return: true if work posted to worker thread, otherwise false. | |
13420 | **/ | |
13421 | static bool | |
13422 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
13423 | struct lpfc_queue *cq, | |
13424 | struct sli4_wcqe_xri_aborted *wcqe) | |
13425 | { | |
13426 | bool workposted = false; | |
13427 | struct lpfc_cq_event *cq_event; | |
13428 | unsigned long iflags; | |
13429 | ||
4f774513 JS |
13430 | switch (cq->subtype) { |
13431 | case LPFC_FCP: | |
8a5ca109 JS |
13432 | cq_event = lpfc_cq_event_setup( |
13433 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
13434 | if (!cq_event) | |
13435 | return false; | |
4f774513 JS |
13436 | spin_lock_irqsave(&phba->hbalock, iflags); |
13437 | list_add_tail(&cq_event->list, | |
13438 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
13439 | /* Set the fcp xri abort event flag */ | |
13440 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
13441 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13442 | workposted = true; | |
13443 | break; | |
422c4cb7 | 13444 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
4f774513 | 13445 | case LPFC_ELS: |
8a5ca109 JS |
13446 | cq_event = lpfc_cq_event_setup( |
13447 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
13448 | if (!cq_event) | |
13449 | return false; | |
4f774513 JS |
13450 | spin_lock_irqsave(&phba->hbalock, iflags); |
13451 | list_add_tail(&cq_event->list, | |
13452 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
13453 | /* Set the els xri abort event flag */ | |
13454 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
13455 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13456 | workposted = true; | |
13457 | break; | |
318083ad | 13458 | case LPFC_NVME: |
8a5ca109 JS |
13459 | /* Notify aborted XRI for NVME work queue */ |
13460 | if (phba->nvmet_support) | |
13461 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); | |
13462 | else | |
13463 | lpfc_sli4_nvme_xri_aborted(phba, wcqe); | |
13464 | ||
13465 | workposted = false; | |
318083ad | 13466 | break; |
4f774513 JS |
13467 | default: |
13468 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
318083ad JS |
13469 | "0603 Invalid CQ subtype %d: " |
13470 | "%08x %08x %08x %08x\n", | |
13471 | cq->subtype, wcqe->word0, wcqe->parameter, | |
13472 | wcqe->word2, wcqe->word3); | |
4f774513 JS |
13473 | workposted = false; |
13474 | break; | |
13475 | } | |
13476 | return workposted; | |
13477 | } | |
13478 | ||
4f774513 JS |
13479 | /** |
13480 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
13481 | * @phba: Pointer to HBA context object. | |
13482 | * @rcqe: Pointer to receive-queue completion queue entry. | |
13483 | * | |
13484 | * This routine process a receive-queue completion queue entry. | |
13485 | * | |
13486 | * Return: true if work posted to worker thread, otherwise false. | |
13487 | **/ | |
13488 | static bool | |
4d9ab994 | 13489 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 13490 | { |
4f774513 JS |
13491 | bool workposted = false; |
13492 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
13493 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
547077a4 | 13494 | struct lpfc_nvmet_tgtport *tgtp; |
4f774513 | 13495 | struct hbq_dmabuf *dma_buf; |
7851fe2c | 13496 | uint32_t status, rq_id; |
4f774513 JS |
13497 | unsigned long iflags; |
13498 | ||
2e90f4b5 JS |
13499 | /* sanity check on queue memory */ |
13500 | if (unlikely(!hrq) || unlikely(!drq)) | |
13501 | return workposted; | |
13502 | ||
7851fe2c JS |
13503 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
13504 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
13505 | else | |
13506 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
13507 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
13508 | goto out; |
13509 | ||
4d9ab994 | 13510 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
13511 | switch (status) { |
13512 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
13513 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13514 | "2537 Receive Frame Truncated!!\n"); | |
13515 | case FC_STATUS_RQ_SUCCESS: | |
13516 | spin_lock_irqsave(&phba->hbalock, iflags); | |
cbc5de1b | 13517 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
13518 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
13519 | if (!dma_buf) { | |
b84daac9 | 13520 | hrq->RQ_no_buf_found++; |
4f774513 JS |
13521 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
13522 | goto out; | |
13523 | } | |
b84daac9 | 13524 | hrq->RQ_rcv_buf++; |
547077a4 | 13525 | hrq->RQ_buf_posted--; |
4d9ab994 | 13526 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
895427bd | 13527 | |
4f774513 | 13528 | /* save off the frame for the word thread to process */ |
4d9ab994 | 13529 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 13530 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 13531 | /* Frame received */ |
45ed1190 | 13532 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
13533 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
13534 | workposted = true; | |
13535 | break; | |
4f774513 | 13536 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
547077a4 JS |
13537 | if (phba->nvmet_support) { |
13538 | tgtp = phba->targetport->private; | |
13539 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, | |
13540 | "6402 RQE Error x%x, posted %d err_cnt " | |
13541 | "%d: %x %x %x\n", | |
13542 | status, hrq->RQ_buf_posted, | |
13543 | hrq->RQ_no_posted_buf, | |
13544 | atomic_read(&tgtp->rcv_fcp_cmd_in), | |
13545 | atomic_read(&tgtp->rcv_fcp_cmd_out), | |
13546 | atomic_read(&tgtp->xmt_fcp_release)); | |
13547 | } | |
13548 | /* fallthrough */ | |
13549 | ||
13550 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
b84daac9 | 13551 | hrq->RQ_no_posted_buf++; |
4f774513 JS |
13552 | /* Post more buffers if possible */ |
13553 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13554 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
13555 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13556 | workposted = true; | |
13557 | break; | |
13558 | } | |
13559 | out: | |
13560 | return workposted; | |
4f774513 JS |
13561 | } |
13562 | ||
4d9ab994 JS |
13563 | /** |
13564 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
13565 | * @phba: Pointer to HBA context object. | |
13566 | * @cq: Pointer to the completion queue. | |
13567 | * @wcqe: Pointer to a completion queue entry. | |
13568 | * | |
25985edc | 13569 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
13570 | * entry. |
13571 | * | |
13572 | * Return: true if work posted to worker thread, otherwise false. | |
13573 | **/ | |
13574 | static bool | |
13575 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
13576 | struct lpfc_cqe *cqe) | |
13577 | { | |
45ed1190 | 13578 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
13579 | bool workposted = false; |
13580 | ||
13581 | /* Copy the work queue CQE and convert endian order if needed */ | |
48f8fdb4 | 13582 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
13583 | |
13584 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 13585 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 13586 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 13587 | /* Process the WQ/RQ complete event */ |
bc73905a | 13588 | phba->last_completion_time = jiffies; |
2a76a283 | 13589 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
45ed1190 | 13590 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
13591 | break; |
13592 | case CQE_CODE_RELEASE_WQE: | |
13593 | /* Process the WQ release event */ | |
13594 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 13595 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
13596 | break; |
13597 | case CQE_CODE_XRI_ABORTED: | |
13598 | /* Process the WQ XRI abort event */ | |
bc73905a | 13599 | phba->last_completion_time = jiffies; |
4d9ab994 | 13600 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 13601 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
13602 | break; |
13603 | case CQE_CODE_RECEIVE: | |
7851fe2c | 13604 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 13605 | /* Process the RQ event */ |
bc73905a | 13606 | phba->last_completion_time = jiffies; |
4d9ab994 | 13607 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 13608 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
13609 | break; |
13610 | default: | |
13611 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13612 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 13613 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
13614 | break; |
13615 | } | |
13616 | return workposted; | |
13617 | } | |
13618 | ||
4f774513 JS |
13619 | /** |
13620 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
13621 | * @phba: Pointer to HBA context object. | |
13622 | * @eqe: Pointer to fast-path event queue entry. | |
13623 | * | |
13624 | * This routine process a event queue entry from the slow-path event queue. | |
13625 | * It will check the MajorCode and MinorCode to determine this is for a | |
13626 | * completion event on a completion queue, if not, an error shall be logged | |
13627 | * and just return. Otherwise, it will get to the corresponding completion | |
13628 | * queue and process all the entries on that completion queue, rearm the | |
13629 | * completion queue, and then return. | |
13630 | * | |
13631 | **/ | |
f485c18d | 13632 | static void |
67d12733 JS |
13633 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
13634 | struct lpfc_queue *speq) | |
4f774513 | 13635 | { |
67d12733 | 13636 | struct lpfc_queue *cq = NULL, *childq; |
4f774513 JS |
13637 | uint16_t cqid; |
13638 | ||
4f774513 | 13639 | /* Get the reference to the corresponding CQ */ |
cb5172ea | 13640 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 | 13641 | |
4f774513 JS |
13642 | list_for_each_entry(childq, &speq->child_list, list) { |
13643 | if (childq->queue_id == cqid) { | |
13644 | cq = childq; | |
13645 | break; | |
13646 | } | |
13647 | } | |
13648 | if (unlikely(!cq)) { | |
75baf696 JS |
13649 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
13650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13651 | "0365 Slow-path CQ identifier " | |
13652 | "(%d) does not exist\n", cqid); | |
f485c18d | 13653 | return; |
4f774513 JS |
13654 | } |
13655 | ||
895427bd JS |
13656 | /* Save EQ associated with this CQ */ |
13657 | cq->assoc_qp = speq; | |
13658 | ||
f485c18d DK |
13659 | if (!queue_work(phba->wq, &cq->spwork)) |
13660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13661 | "0390 Cannot schedule soft IRQ " | |
13662 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", | |
13663 | cqid, cq->queue_id, smp_processor_id()); | |
13664 | } | |
13665 | ||
13666 | /** | |
13667 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry | |
13668 | * @phba: Pointer to HBA context object. | |
13669 | * | |
13670 | * This routine process a event queue entry from the slow-path event queue. | |
13671 | * It will check the MajorCode and MinorCode to determine this is for a | |
13672 | * completion event on a completion queue, if not, an error shall be logged | |
13673 | * and just return. Otherwise, it will get to the corresponding completion | |
13674 | * queue and process all the entries on that completion queue, rearm the | |
13675 | * completion queue, and then return. | |
13676 | * | |
13677 | **/ | |
13678 | static void | |
13679 | lpfc_sli4_sp_process_cq(struct work_struct *work) | |
13680 | { | |
13681 | struct lpfc_queue *cq = | |
13682 | container_of(work, struct lpfc_queue, spwork); | |
13683 | struct lpfc_hba *phba = cq->phba; | |
13684 | struct lpfc_cqe *cqe; | |
13685 | bool workposted = false; | |
13686 | int ccount = 0; | |
13687 | ||
4f774513 JS |
13688 | /* Process all the entries to the CQ */ |
13689 | switch (cq->type) { | |
13690 | case LPFC_MCQ: | |
13691 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
13692 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
f485c18d | 13693 | if (!(++ccount % cq->entry_repost)) |
7869da18 | 13694 | break; |
b84daac9 | 13695 | cq->CQ_mbox++; |
4f774513 JS |
13696 | } |
13697 | break; | |
13698 | case LPFC_WCQ: | |
13699 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
c8a4ce0b DK |
13700 | if (cq->subtype == LPFC_FCP || |
13701 | cq->subtype == LPFC_NVME) { | |
13702 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS | |
13703 | if (phba->ktime_on) | |
13704 | cq->isr_timestamp = ktime_get_ns(); | |
13705 | else | |
13706 | cq->isr_timestamp = 0; | |
13707 | #endif | |
895427bd | 13708 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
0558056c | 13709 | cqe); |
c8a4ce0b | 13710 | } else { |
0558056c JS |
13711 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
13712 | cqe); | |
c8a4ce0b | 13713 | } |
f485c18d | 13714 | if (!(++ccount % cq->entry_repost)) |
7869da18 | 13715 | break; |
4f774513 | 13716 | } |
b84daac9 JS |
13717 | |
13718 | /* Track the max number of CQEs processed in 1 EQ */ | |
f485c18d DK |
13719 | if (ccount > cq->CQ_max_cqe) |
13720 | cq->CQ_max_cqe = ccount; | |
4f774513 JS |
13721 | break; |
13722 | default: | |
13723 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13724 | "0370 Invalid completion queue type (%d)\n", | |
13725 | cq->type); | |
f485c18d | 13726 | return; |
4f774513 JS |
13727 | } |
13728 | ||
13729 | /* Catch the no cq entry condition, log an error */ | |
f485c18d | 13730 | if (unlikely(ccount == 0)) |
4f774513 JS |
13731 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
13732 | "0371 No entry from the CQ: identifier " | |
13733 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
13734 | ||
13735 | /* In any case, flash and re-arm the RCQ */ | |
b71413dd | 13736 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
4f774513 JS |
13737 | |
13738 | /* wake up worker thread if there are works to be done */ | |
13739 | if (workposted) | |
13740 | lpfc_worker_wake_up(phba); | |
13741 | } | |
13742 | ||
13743 | /** | |
13744 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
2a76a283 JS |
13745 | * @phba: Pointer to HBA context object. |
13746 | * @cq: Pointer to associated CQ | |
13747 | * @wcqe: Pointer to work-queue completion queue entry. | |
4f774513 JS |
13748 | * |
13749 | * This routine process a fast-path work queue completion entry from fast-path | |
13750 | * event queue for FCP command response completion. | |
13751 | **/ | |
13752 | static void | |
2a76a283 | 13753 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
13754 | struct lpfc_wcqe_complete *wcqe) |
13755 | { | |
2a76a283 | 13756 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 JS |
13757 | struct lpfc_iocbq *cmdiocbq; |
13758 | struct lpfc_iocbq irspiocbq; | |
13759 | unsigned long iflags; | |
13760 | ||
4f774513 JS |
13761 | /* Check for response status */ |
13762 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
13763 | /* If resource errors reported from HBA, reduce queue | |
13764 | * depth of the SCSI device. | |
13765 | */ | |
e3d2b802 JS |
13766 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
13767 | IOSTAT_LOCAL_REJECT)) && | |
13768 | ((wcqe->parameter & IOERR_PARAM_MASK) == | |
13769 | IOERR_NO_RESOURCES)) | |
4f774513 | 13770 | phba->lpfc_rampdown_queue_depth(phba); |
e3d2b802 | 13771 | |
4f774513 | 13772 | /* Log the error status */ |
11f0e34f JS |
13773 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
13774 | "0373 FCP CQE error: status=x%x: " | |
13775 | "CQE: %08x %08x %08x %08x\n", | |
4f774513 | 13776 | bf_get(lpfc_wcqe_c_status, wcqe), |
11f0e34f JS |
13777 | wcqe->word0, wcqe->total_data_placed, |
13778 | wcqe->parameter, wcqe->word3); | |
4f774513 JS |
13779 | } |
13780 | ||
13781 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
7e56aa25 JS |
13782 | spin_lock_irqsave(&pring->ring_lock, iflags); |
13783 | pring->stats.iocb_event++; | |
4f774513 JS |
13784 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
13785 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 13786 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
4f774513 JS |
13787 | if (unlikely(!cmdiocbq)) { |
13788 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
13789 | "0374 FCP complete with no corresponding " | |
13790 | "cmdiocb: iotag (%d)\n", | |
13791 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
13792 | return; | |
13793 | } | |
c8a4ce0b DK |
13794 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
13795 | cmdiocbq->isr_timestamp = cq->isr_timestamp; | |
13796 | #endif | |
895427bd JS |
13797 | if (cmdiocbq->iocb_cmpl == NULL) { |
13798 | if (cmdiocbq->wqe_cmpl) { | |
13799 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { | |
13800 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13801 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
13802 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13803 | } | |
13804 | ||
13805 | /* Pass the cmd_iocb and the wcqe to the upper layer */ | |
13806 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); | |
13807 | return; | |
13808 | } | |
4f774513 JS |
13809 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
13810 | "0375 FCP cmdiocb not callback function " | |
13811 | "iotag: (%d)\n", | |
13812 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
13813 | return; | |
13814 | } | |
13815 | ||
13816 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 13817 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 13818 | |
0f65ff68 JS |
13819 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
13820 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13821 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
13822 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13823 | } | |
13824 | ||
4f774513 JS |
13825 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
13826 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
13827 | } | |
13828 | ||
13829 | /** | |
13830 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
13831 | * @phba: Pointer to HBA context object. | |
13832 | * @cq: Pointer to completion queue. | |
13833 | * @wcqe: Pointer to work-queue completion queue entry. | |
13834 | * | |
3f8b6fb7 | 13835 | * This routine handles an fast-path WQ entry consumed event by invoking the |
4f774513 JS |
13836 | * proper WQ release routine to the slow-path WQ. |
13837 | **/ | |
13838 | static void | |
13839 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
13840 | struct lpfc_wcqe_release *wcqe) | |
13841 | { | |
13842 | struct lpfc_queue *childwq; | |
13843 | bool wqid_matched = false; | |
895427bd | 13844 | uint16_t hba_wqid; |
4f774513 JS |
13845 | |
13846 | /* Check for fast-path FCP work queue release */ | |
895427bd | 13847 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
4f774513 | 13848 | list_for_each_entry(childwq, &cq->child_list, list) { |
895427bd | 13849 | if (childwq->queue_id == hba_wqid) { |
4f774513 JS |
13850 | lpfc_sli4_wq_release(childwq, |
13851 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
6e8e1c14 JS |
13852 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
13853 | lpfc_nvmet_wqfull_process(phba, childwq); | |
4f774513 JS |
13854 | wqid_matched = true; |
13855 | break; | |
13856 | } | |
13857 | } | |
13858 | /* Report warning log message if no match found */ | |
13859 | if (wqid_matched != true) | |
13860 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
13861 | "2580 Fast-path wqe consume event carries " | |
895427bd | 13862 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
4f774513 JS |
13863 | } |
13864 | ||
13865 | /** | |
2d7dbc4c JS |
13866 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
13867 | * @phba: Pointer to HBA context object. | |
13868 | * @rcqe: Pointer to receive-queue completion queue entry. | |
4f774513 | 13869 | * |
2d7dbc4c JS |
13870 | * This routine process a receive-queue completion queue entry. |
13871 | * | |
13872 | * Return: true if work posted to worker thread, otherwise false. | |
13873 | **/ | |
13874 | static bool | |
13875 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
13876 | struct lpfc_rcqe *rcqe) | |
13877 | { | |
13878 | bool workposted = false; | |
13879 | struct lpfc_queue *hrq; | |
13880 | struct lpfc_queue *drq; | |
13881 | struct rqb_dmabuf *dma_buf; | |
13882 | struct fc_frame_header *fc_hdr; | |
547077a4 | 13883 | struct lpfc_nvmet_tgtport *tgtp; |
2d7dbc4c JS |
13884 | uint32_t status, rq_id; |
13885 | unsigned long iflags; | |
13886 | uint32_t fctl, idx; | |
13887 | ||
13888 | if ((phba->nvmet_support == 0) || | |
13889 | (phba->sli4_hba.nvmet_cqset == NULL)) | |
13890 | return workposted; | |
13891 | ||
13892 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; | |
13893 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; | |
13894 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; | |
13895 | ||
13896 | /* sanity check on queue memory */ | |
13897 | if (unlikely(!hrq) || unlikely(!drq)) | |
13898 | return workposted; | |
13899 | ||
13900 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) | |
13901 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
13902 | else | |
13903 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
13904 | ||
13905 | if ((phba->nvmet_support == 0) || | |
13906 | (rq_id != hrq->queue_id)) | |
13907 | return workposted; | |
13908 | ||
13909 | status = bf_get(lpfc_rcqe_status, rcqe); | |
13910 | switch (status) { | |
13911 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
13912 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13913 | "6126 Receive Frame Truncated!!\n"); | |
78e1d200 | 13914 | /* Drop thru */ |
2d7dbc4c | 13915 | case FC_STATUS_RQ_SUCCESS: |
2d7dbc4c | 13916 | spin_lock_irqsave(&phba->hbalock, iflags); |
cbc5de1b | 13917 | lpfc_sli4_rq_release(hrq, drq); |
2d7dbc4c JS |
13918 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
13919 | if (!dma_buf) { | |
13920 | hrq->RQ_no_buf_found++; | |
13921 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13922 | goto out; | |
13923 | } | |
13924 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13925 | hrq->RQ_rcv_buf++; | |
547077a4 | 13926 | hrq->RQ_buf_posted--; |
2d7dbc4c JS |
13927 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
13928 | ||
13929 | /* Just some basic sanity checks on FCP Command frame */ | |
13930 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | | |
13931 | fc_hdr->fh_f_ctl[1] << 8 | | |
13932 | fc_hdr->fh_f_ctl[2]); | |
13933 | if (((fctl & | |
13934 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != | |
13935 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || | |
13936 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ | |
13937 | goto drop; | |
13938 | ||
13939 | if (fc_hdr->fh_type == FC_TYPE_FCP) { | |
13940 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); | |
d613b6a7 | 13941 | lpfc_nvmet_unsol_fcp_event( |
66d7ce93 | 13942 | phba, idx, dma_buf, |
c8a4ce0b | 13943 | cq->isr_timestamp); |
2d7dbc4c JS |
13944 | return false; |
13945 | } | |
13946 | drop: | |
13947 | lpfc_in_buf_free(phba, &dma_buf->dbuf); | |
13948 | break; | |
2d7dbc4c | 13949 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
547077a4 JS |
13950 | if (phba->nvmet_support) { |
13951 | tgtp = phba->targetport->private; | |
13952 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, | |
13953 | "6401 RQE Error x%x, posted %d err_cnt " | |
13954 | "%d: %x %x %x\n", | |
13955 | status, hrq->RQ_buf_posted, | |
13956 | hrq->RQ_no_posted_buf, | |
13957 | atomic_read(&tgtp->rcv_fcp_cmd_in), | |
13958 | atomic_read(&tgtp->rcv_fcp_cmd_out), | |
13959 | atomic_read(&tgtp->xmt_fcp_release)); | |
13960 | } | |
13961 | /* fallthrough */ | |
13962 | ||
13963 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
2d7dbc4c JS |
13964 | hrq->RQ_no_posted_buf++; |
13965 | /* Post more buffers if possible */ | |
2d7dbc4c JS |
13966 | break; |
13967 | } | |
13968 | out: | |
13969 | return workposted; | |
13970 | } | |
13971 | ||
4f774513 | 13972 | /** |
895427bd | 13973 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
4f774513 JS |
13974 | * @cq: Pointer to the completion queue. |
13975 | * @eqe: Pointer to fast-path completion queue entry. | |
13976 | * | |
13977 | * This routine process a fast-path work queue completion entry from fast-path | |
13978 | * event queue for FCP command response completion. | |
13979 | **/ | |
13980 | static int | |
895427bd | 13981 | lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
13982 | struct lpfc_cqe *cqe) |
13983 | { | |
13984 | struct lpfc_wcqe_release wcqe; | |
13985 | bool workposted = false; | |
13986 | ||
13987 | /* Copy the work queue CQE and convert endian order if needed */ | |
48f8fdb4 | 13988 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
4f774513 JS |
13989 | |
13990 | /* Check and process for different type of WCQE and dispatch */ | |
13991 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
13992 | case CQE_CODE_COMPL_WQE: | |
895427bd | 13993 | case CQE_CODE_NVME_ERSP: |
b84daac9 | 13994 | cq->CQ_wq++; |
4f774513 | 13995 | /* Process the WQ complete event */ |
98fc5dd9 | 13996 | phba->last_completion_time = jiffies; |
895427bd JS |
13997 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
13998 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, | |
13999 | (struct lpfc_wcqe_complete *)&wcqe); | |
14000 | if (cq->subtype == LPFC_NVME_LS) | |
14001 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, | |
4f774513 JS |
14002 | (struct lpfc_wcqe_complete *)&wcqe); |
14003 | break; | |
14004 | case CQE_CODE_RELEASE_WQE: | |
b84daac9 | 14005 | cq->CQ_release_wqe++; |
4f774513 JS |
14006 | /* Process the WQ release event */ |
14007 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
14008 | (struct lpfc_wcqe_release *)&wcqe); | |
14009 | break; | |
14010 | case CQE_CODE_XRI_ABORTED: | |
b84daac9 | 14011 | cq->CQ_xri_aborted++; |
4f774513 | 14012 | /* Process the WQ XRI abort event */ |
bc73905a | 14013 | phba->last_completion_time = jiffies; |
4f774513 JS |
14014 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
14015 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
14016 | break; | |
895427bd JS |
14017 | case CQE_CODE_RECEIVE_V1: |
14018 | case CQE_CODE_RECEIVE: | |
14019 | phba->last_completion_time = jiffies; | |
2d7dbc4c JS |
14020 | if (cq->subtype == LPFC_NVMET) { |
14021 | workposted = lpfc_sli4_nvmet_handle_rcqe( | |
14022 | phba, cq, (struct lpfc_rcqe *)&wcqe); | |
14023 | } | |
895427bd | 14024 | break; |
4f774513 JS |
14025 | default: |
14026 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
895427bd | 14027 | "0144 Not a valid CQE code: x%x\n", |
4f774513 JS |
14028 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
14029 | break; | |
14030 | } | |
14031 | return workposted; | |
14032 | } | |
14033 | ||
14034 | /** | |
67d12733 | 14035 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
4f774513 JS |
14036 | * @phba: Pointer to HBA context object. |
14037 | * @eqe: Pointer to fast-path event queue entry. | |
14038 | * | |
14039 | * This routine process a event queue entry from the fast-path event queue. | |
14040 | * It will check the MajorCode and MinorCode to determine this is for a | |
14041 | * completion event on a completion queue, if not, an error shall be logged | |
14042 | * and just return. Otherwise, it will get to the corresponding completion | |
14043 | * queue and process all the entries on the completion queue, rearm the | |
14044 | * completion queue, and then return. | |
14045 | **/ | |
f485c18d | 14046 | static void |
67d12733 JS |
14047 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
14048 | uint32_t qidx) | |
4f774513 | 14049 | { |
895427bd | 14050 | struct lpfc_queue *cq = NULL; |
2d7dbc4c | 14051 | uint16_t cqid, id; |
4f774513 | 14052 | |
cb5172ea | 14053 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 | 14054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
67d12733 | 14055 | "0366 Not a valid completion " |
4f774513 | 14056 | "event: majorcode=x%x, minorcode=x%x\n", |
cb5172ea JS |
14057 | bf_get_le32(lpfc_eqe_major_code, eqe), |
14058 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
f485c18d | 14059 | return; |
4f774513 JS |
14060 | } |
14061 | ||
67d12733 JS |
14062 | /* Get the reference to the corresponding CQ */ |
14063 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
14064 | ||
2d7dbc4c JS |
14065 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
14066 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; | |
14067 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { | |
14068 | /* Process NVMET unsol rcv */ | |
14069 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; | |
14070 | goto process_cq; | |
14071 | } | |
67d12733 JS |
14072 | } |
14073 | ||
895427bd JS |
14074 | if (phba->sli4_hba.nvme_cq_map && |
14075 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { | |
f358dd0c | 14076 | /* Process NVME / NVMET command completion */ |
895427bd JS |
14077 | cq = phba->sli4_hba.nvme_cq[qidx]; |
14078 | goto process_cq; | |
2e90f4b5 | 14079 | } |
67d12733 | 14080 | |
895427bd JS |
14081 | if (phba->sli4_hba.fcp_cq_map && |
14082 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { | |
14083 | /* Process FCP command completion */ | |
14084 | cq = phba->sli4_hba.fcp_cq[qidx]; | |
14085 | goto process_cq; | |
2e90f4b5 | 14086 | } |
895427bd JS |
14087 | |
14088 | if (phba->sli4_hba.nvmels_cq && | |
14089 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { | |
14090 | /* Process NVME unsol rcv */ | |
14091 | cq = phba->sli4_hba.nvmels_cq; | |
14092 | } | |
14093 | ||
14094 | /* Otherwise this is a Slow path event */ | |
14095 | if (cq == NULL) { | |
f485c18d DK |
14096 | lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]); |
14097 | return; | |
4f774513 JS |
14098 | } |
14099 | ||
895427bd | 14100 | process_cq: |
4f774513 JS |
14101 | if (unlikely(cqid != cq->queue_id)) { |
14102 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14103 | "0368 Miss-matched fast-path completion " | |
14104 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
14105 | cqid, cq->queue_id); | |
f485c18d | 14106 | return; |
4f774513 JS |
14107 | } |
14108 | ||
895427bd JS |
14109 | /* Save EQ associated with this CQ */ |
14110 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; | |
14111 | ||
f485c18d DK |
14112 | if (!queue_work(phba->wq, &cq->irqwork)) |
14113 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14114 | "0363 Cannot schedule soft IRQ " | |
14115 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", | |
14116 | cqid, cq->queue_id, smp_processor_id()); | |
14117 | } | |
14118 | ||
14119 | /** | |
14120 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry | |
14121 | * @phba: Pointer to HBA context object. | |
14122 | * @eqe: Pointer to fast-path event queue entry. | |
14123 | * | |
14124 | * This routine process a event queue entry from the fast-path event queue. | |
14125 | * It will check the MajorCode and MinorCode to determine this is for a | |
14126 | * completion event on a completion queue, if not, an error shall be logged | |
14127 | * and just return. Otherwise, it will get to the corresponding completion | |
14128 | * queue and process all the entries on the completion queue, rearm the | |
14129 | * completion queue, and then return. | |
14130 | **/ | |
14131 | static void | |
14132 | lpfc_sli4_hba_process_cq(struct work_struct *work) | |
14133 | { | |
14134 | struct lpfc_queue *cq = | |
14135 | container_of(work, struct lpfc_queue, irqwork); | |
14136 | struct lpfc_hba *phba = cq->phba; | |
14137 | struct lpfc_cqe *cqe; | |
14138 | bool workposted = false; | |
14139 | int ccount = 0; | |
14140 | ||
4f774513 JS |
14141 | /* Process all the entries to the CQ */ |
14142 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
c8a4ce0b DK |
14143 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
14144 | if (phba->ktime_on) | |
14145 | cq->isr_timestamp = ktime_get_ns(); | |
14146 | else | |
14147 | cq->isr_timestamp = 0; | |
14148 | #endif | |
895427bd | 14149 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
f485c18d | 14150 | if (!(++ccount % cq->entry_repost)) |
7869da18 | 14151 | break; |
4f774513 JS |
14152 | } |
14153 | ||
b84daac9 | 14154 | /* Track the max number of CQEs processed in 1 EQ */ |
f485c18d DK |
14155 | if (ccount > cq->CQ_max_cqe) |
14156 | cq->CQ_max_cqe = ccount; | |
14157 | cq->assoc_qp->EQ_cqe_cnt += ccount; | |
b84daac9 | 14158 | |
4f774513 | 14159 | /* Catch the no cq entry condition */ |
f485c18d | 14160 | if (unlikely(ccount == 0)) |
4f774513 JS |
14161 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
14162 | "0369 No entry from fast-path completion " | |
14163 | "queue fcpcqid=%d\n", cq->queue_id); | |
14164 | ||
14165 | /* In any case, flash and re-arm the CQ */ | |
b71413dd | 14166 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
4f774513 JS |
14167 | |
14168 | /* wake up worker thread if there are works to be done */ | |
14169 | if (workposted) | |
14170 | lpfc_worker_wake_up(phba); | |
14171 | } | |
14172 | ||
14173 | static void | |
14174 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
14175 | { | |
14176 | struct lpfc_eqe *eqe; | |
14177 | ||
14178 | /* walk all the EQ entries and drop on the floor */ | |
14179 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
14180 | ; | |
14181 | ||
14182 | /* Clear and re-arm the EQ */ | |
b71413dd | 14183 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
4f774513 JS |
14184 | } |
14185 | ||
1ba981fd JS |
14186 | |
14187 | /** | |
14188 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue | |
14189 | * entry | |
14190 | * @phba: Pointer to HBA context object. | |
14191 | * @eqe: Pointer to fast-path event queue entry. | |
14192 | * | |
14193 | * This routine process a event queue entry from the Flash Optimized Fabric | |
14194 | * event queue. It will check the MajorCode and MinorCode to determine this | |
14195 | * is for a completion event on a completion queue, if not, an error shall be | |
14196 | * logged and just return. Otherwise, it will get to the corresponding | |
14197 | * completion queue and process all the entries on the completion queue, rearm | |
14198 | * the completion queue, and then return. | |
14199 | **/ | |
14200 | static void | |
14201 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
14202 | { | |
14203 | struct lpfc_queue *cq; | |
1ba981fd | 14204 | uint16_t cqid; |
1ba981fd JS |
14205 | |
14206 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { | |
14207 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14208 | "9147 Not a valid completion " | |
14209 | "event: majorcode=x%x, minorcode=x%x\n", | |
14210 | bf_get_le32(lpfc_eqe_major_code, eqe), | |
14211 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
14212 | return; | |
14213 | } | |
14214 | ||
14215 | /* Get the reference to the corresponding CQ */ | |
14216 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
14217 | ||
14218 | /* Next check for OAS */ | |
14219 | cq = phba->sli4_hba.oas_cq; | |
14220 | if (unlikely(!cq)) { | |
14221 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) | |
14222 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14223 | "9148 OAS completion queue " | |
14224 | "does not exist\n"); | |
14225 | return; | |
14226 | } | |
14227 | ||
14228 | if (unlikely(cqid != cq->queue_id)) { | |
14229 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14230 | "9149 Miss-matched fast-path compl " | |
14231 | "queue id: eqcqid=%d, fcpcqid=%d\n", | |
14232 | cqid, cq->queue_id); | |
14233 | return; | |
14234 | } | |
14235 | ||
d41b65bc JS |
14236 | /* Save EQ associated with this CQ */ |
14237 | cq->assoc_qp = phba->sli4_hba.fof_eq; | |
14238 | ||
f485c18d DK |
14239 | /* CQ work will be processed on CPU affinitized to this IRQ */ |
14240 | if (!queue_work(phba->wq, &cq->irqwork)) | |
1ba981fd | 14241 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
f485c18d DK |
14242 | "0367 Cannot schedule soft IRQ " |
14243 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", | |
14244 | cqid, cq->queue_id, smp_processor_id()); | |
1ba981fd JS |
14245 | } |
14246 | ||
14247 | /** | |
14248 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device | |
14249 | * @irq: Interrupt number. | |
14250 | * @dev_id: The device context pointer. | |
14251 | * | |
14252 | * This function is directly called from the PCI layer as an interrupt | |
14253 | * service routine when device with SLI-4 interface spec is enabled with | |
14254 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric | |
14255 | * IOCB ring event in the HBA. However, when the device is enabled with either | |
14256 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
14257 | * device-level interrupt handler. When the PCI slot is in error recovery | |
14258 | * or the HBA is undergoing initialization, the interrupt handler will not | |
14259 | * process the interrupt. The Flash Optimized Fabric ring event are handled in | |
14260 | * the intrrupt context. This function is called without any lock held. | |
14261 | * It gets the hbalock to access and update SLI data structures. Note that, | |
14262 | * the EQ to CQ are one-to-one map such that the EQ index is | |
14263 | * equal to that of CQ index. | |
14264 | * | |
14265 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
14266 | * returns IRQ_NONE. | |
14267 | **/ | |
14268 | irqreturn_t | |
14269 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) | |
14270 | { | |
14271 | struct lpfc_hba *phba; | |
895427bd | 14272 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
1ba981fd JS |
14273 | struct lpfc_queue *eq; |
14274 | struct lpfc_eqe *eqe; | |
14275 | unsigned long iflag; | |
14276 | int ecount = 0; | |
1ba981fd JS |
14277 | |
14278 | /* Get the driver's phba structure from the dev_id */ | |
895427bd JS |
14279 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
14280 | phba = hba_eq_hdl->phba; | |
1ba981fd JS |
14281 | |
14282 | if (unlikely(!phba)) | |
14283 | return IRQ_NONE; | |
14284 | ||
14285 | /* Get to the EQ struct associated with this vector */ | |
14286 | eq = phba->sli4_hba.fof_eq; | |
14287 | if (unlikely(!eq)) | |
14288 | return IRQ_NONE; | |
14289 | ||
14290 | /* Check device state for handling interrupt */ | |
14291 | if (unlikely(lpfc_intr_state_check(phba))) { | |
1ba981fd JS |
14292 | /* Check again for link_state with lock held */ |
14293 | spin_lock_irqsave(&phba->hbalock, iflag); | |
14294 | if (phba->link_state < LPFC_LINK_DOWN) | |
14295 | /* Flush, clear interrupt, and rearm the EQ */ | |
14296 | lpfc_sli4_eq_flush(phba, eq); | |
14297 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
14298 | return IRQ_NONE; | |
14299 | } | |
14300 | ||
14301 | /* | |
14302 | * Process all the event on FCP fast-path EQ | |
14303 | */ | |
14304 | while ((eqe = lpfc_sli4_eq_get(eq))) { | |
14305 | lpfc_sli4_fof_handle_eqe(phba, eqe); | |
14306 | if (!(++ecount % eq->entry_repost)) | |
7869da18 | 14307 | break; |
1ba981fd JS |
14308 | eq->EQ_processed++; |
14309 | } | |
14310 | ||
14311 | /* Track the max number of EQEs processed in 1 intr */ | |
14312 | if (ecount > eq->EQ_max_eqe) | |
14313 | eq->EQ_max_eqe = ecount; | |
14314 | ||
14315 | ||
14316 | if (unlikely(ecount == 0)) { | |
14317 | eq->EQ_no_entry++; | |
14318 | ||
14319 | if (phba->intr_type == MSIX) | |
14320 | /* MSI-X treated interrupt served as no EQ share INT */ | |
14321 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
14322 | "9145 MSI-X interrupt with no EQE\n"); | |
14323 | else { | |
14324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14325 | "9146 ISR interrupt with no EQE\n"); | |
14326 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
14327 | return IRQ_NONE; | |
14328 | } | |
14329 | } | |
14330 | /* Always clear and re-arm the fast-path EQ */ | |
b71413dd | 14331 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
1ba981fd JS |
14332 | return IRQ_HANDLED; |
14333 | } | |
14334 | ||
4f774513 | 14335 | /** |
67d12733 | 14336 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
4f774513 JS |
14337 | * @irq: Interrupt number. |
14338 | * @dev_id: The device context pointer. | |
14339 | * | |
14340 | * This function is directly called from the PCI layer as an interrupt | |
14341 | * service routine when device with SLI-4 interface spec is enabled with | |
14342 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
14343 | * ring event in the HBA. However, when the device is enabled with either | |
14344 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
14345 | * device-level interrupt handler. When the PCI slot is in error recovery | |
14346 | * or the HBA is undergoing initialization, the interrupt handler will not | |
14347 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
14348 | * the intrrupt context. This function is called without any lock held. | |
14349 | * It gets the hbalock to access and update SLI data structures. Note that, | |
14350 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
14351 | * equal to that of FCP CQ index. | |
14352 | * | |
67d12733 JS |
14353 | * The link attention and ELS ring attention events are handled |
14354 | * by the worker thread. The interrupt handler signals the worker thread | |
14355 | * and returns for these events. This function is called without any lock | |
14356 | * held. It gets the hbalock to access and update SLI data structures. | |
14357 | * | |
4f774513 JS |
14358 | * This function returns IRQ_HANDLED when interrupt is handled else it |
14359 | * returns IRQ_NONE. | |
14360 | **/ | |
14361 | irqreturn_t | |
67d12733 | 14362 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
4f774513 JS |
14363 | { |
14364 | struct lpfc_hba *phba; | |
895427bd | 14365 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
4f774513 JS |
14366 | struct lpfc_queue *fpeq; |
14367 | struct lpfc_eqe *eqe; | |
14368 | unsigned long iflag; | |
14369 | int ecount = 0; | |
895427bd | 14370 | int hba_eqidx; |
4f774513 JS |
14371 | |
14372 | /* Get the driver's phba structure from the dev_id */ | |
895427bd JS |
14373 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
14374 | phba = hba_eq_hdl->phba; | |
14375 | hba_eqidx = hba_eq_hdl->idx; | |
4f774513 JS |
14376 | |
14377 | if (unlikely(!phba)) | |
14378 | return IRQ_NONE; | |
67d12733 | 14379 | if (unlikely(!phba->sli4_hba.hba_eq)) |
5350d872 | 14380 | return IRQ_NONE; |
4f774513 JS |
14381 | |
14382 | /* Get to the EQ struct associated with this vector */ | |
895427bd | 14383 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
2e90f4b5 JS |
14384 | if (unlikely(!fpeq)) |
14385 | return IRQ_NONE; | |
4f774513 | 14386 | |
ba20c853 | 14387 | if (lpfc_fcp_look_ahead) { |
895427bd | 14388 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
b71413dd | 14389 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
ba20c853 | 14390 | else { |
895427bd | 14391 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
ba20c853 JS |
14392 | return IRQ_NONE; |
14393 | } | |
14394 | } | |
14395 | ||
4f774513 JS |
14396 | /* Check device state for handling interrupt */ |
14397 | if (unlikely(lpfc_intr_state_check(phba))) { | |
14398 | /* Check again for link_state with lock held */ | |
14399 | spin_lock_irqsave(&phba->hbalock, iflag); | |
14400 | if (phba->link_state < LPFC_LINK_DOWN) | |
14401 | /* Flush, clear interrupt, and rearm the EQ */ | |
14402 | lpfc_sli4_eq_flush(phba, fpeq); | |
14403 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
ba20c853 | 14404 | if (lpfc_fcp_look_ahead) |
895427bd | 14405 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
4f774513 JS |
14406 | return IRQ_NONE; |
14407 | } | |
14408 | ||
14409 | /* | |
14410 | * Process all the event on FCP fast-path EQ | |
14411 | */ | |
14412 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
f485c18d DK |
14413 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
14414 | if (!(++ecount % fpeq->entry_repost)) | |
7869da18 | 14415 | break; |
b84daac9 | 14416 | fpeq->EQ_processed++; |
4f774513 JS |
14417 | } |
14418 | ||
b84daac9 JS |
14419 | /* Track the max number of EQEs processed in 1 intr */ |
14420 | if (ecount > fpeq->EQ_max_eqe) | |
14421 | fpeq->EQ_max_eqe = ecount; | |
14422 | ||
4f774513 | 14423 | /* Always clear and re-arm the fast-path EQ */ |
b71413dd | 14424 | phba->sli4_hba.sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
4f774513 JS |
14425 | |
14426 | if (unlikely(ecount == 0)) { | |
b84daac9 | 14427 | fpeq->EQ_no_entry++; |
ba20c853 JS |
14428 | |
14429 | if (lpfc_fcp_look_ahead) { | |
895427bd | 14430 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
ba20c853 JS |
14431 | return IRQ_NONE; |
14432 | } | |
14433 | ||
4f774513 JS |
14434 | if (phba->intr_type == MSIX) |
14435 | /* MSI-X treated interrupt served as no EQ share INT */ | |
14436 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
14437 | "0358 MSI-X interrupt with no EQE\n"); | |
14438 | else | |
14439 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
14440 | return IRQ_NONE; | |
14441 | } | |
14442 | ||
ba20c853 | 14443 | if (lpfc_fcp_look_ahead) |
895427bd JS |
14444 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
14445 | ||
4f774513 JS |
14446 | return IRQ_HANDLED; |
14447 | } /* lpfc_sli4_fp_intr_handler */ | |
14448 | ||
14449 | /** | |
14450 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
14451 | * @irq: Interrupt number. | |
14452 | * @dev_id: The device context pointer. | |
14453 | * | |
14454 | * This function is the device-level interrupt handler to device with SLI-4 | |
14455 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
14456 | * interrupt mode is enabled and there is an event in the HBA which requires | |
14457 | * driver attention. This function invokes the slow-path interrupt attention | |
14458 | * handling function and fast-path interrupt attention handling function in | |
14459 | * turn to process the relevant HBA attention events. This function is called | |
14460 | * without any lock held. It gets the hbalock to access and update SLI data | |
14461 | * structures. | |
14462 | * | |
14463 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
14464 | * returns IRQ_NONE. | |
14465 | **/ | |
14466 | irqreturn_t | |
14467 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
14468 | { | |
14469 | struct lpfc_hba *phba; | |
67d12733 JS |
14470 | irqreturn_t hba_irq_rc; |
14471 | bool hba_handled = false; | |
895427bd | 14472 | int qidx; |
4f774513 JS |
14473 | |
14474 | /* Get the driver's phba structure from the dev_id */ | |
14475 | phba = (struct lpfc_hba *)dev_id; | |
14476 | ||
14477 | if (unlikely(!phba)) | |
14478 | return IRQ_NONE; | |
14479 | ||
4f774513 JS |
14480 | /* |
14481 | * Invoke fast-path host attention interrupt handling as appropriate. | |
14482 | */ | |
895427bd | 14483 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
67d12733 | 14484 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
895427bd | 14485 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
67d12733 JS |
14486 | if (hba_irq_rc == IRQ_HANDLED) |
14487 | hba_handled |= true; | |
4f774513 JS |
14488 | } |
14489 | ||
1ba981fd JS |
14490 | if (phba->cfg_fof) { |
14491 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, | |
895427bd | 14492 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
1ba981fd JS |
14493 | if (hba_irq_rc == IRQ_HANDLED) |
14494 | hba_handled |= true; | |
14495 | } | |
14496 | ||
67d12733 | 14497 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
4f774513 JS |
14498 | } /* lpfc_sli4_intr_handler */ |
14499 | ||
14500 | /** | |
14501 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
14502 | * @queue: The queue structure to free. | |
14503 | * | |
b595076a | 14504 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
14505 | * the host resident queue. This function must be called after destroying the |
14506 | * queue on the HBA. | |
14507 | **/ | |
14508 | void | |
14509 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
14510 | { | |
14511 | struct lpfc_dmabuf *dmabuf; | |
14512 | ||
14513 | if (!queue) | |
14514 | return; | |
14515 | ||
14516 | while (!list_empty(&queue->page_list)) { | |
14517 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
14518 | list); | |
81b96eda | 14519 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
4f774513 JS |
14520 | dmabuf->virt, dmabuf->phys); |
14521 | kfree(dmabuf); | |
14522 | } | |
895427bd JS |
14523 | if (queue->rqbp) { |
14524 | lpfc_free_rq_buffer(queue->phba, queue); | |
14525 | kfree(queue->rqbp); | |
14526 | } | |
d1f525aa JS |
14527 | |
14528 | if (!list_empty(&queue->wq_list)) | |
14529 | list_del(&queue->wq_list); | |
14530 | ||
4f774513 JS |
14531 | kfree(queue); |
14532 | return; | |
14533 | } | |
14534 | ||
14535 | /** | |
14536 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
14537 | * @phba: The HBA that this queue is being created on. | |
81b96eda | 14538 | * @page_size: The size of a queue page |
4f774513 JS |
14539 | * @entry_size: The size of each queue entry for this queue. |
14540 | * @entry count: The number of entries that this queue will handle. | |
14541 | * | |
14542 | * This function allocates a queue structure and the DMAable memory used for | |
14543 | * the host resident queue. This function must be called before creating the | |
14544 | * queue on the HBA. | |
14545 | **/ | |
14546 | struct lpfc_queue * | |
81b96eda JS |
14547 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
14548 | uint32_t entry_size, uint32_t entry_count) | |
4f774513 JS |
14549 | { |
14550 | struct lpfc_queue *queue; | |
14551 | struct lpfc_dmabuf *dmabuf; | |
14552 | int x, total_qe_count; | |
14553 | void *dma_pointer; | |
cb5172ea | 14554 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 14555 | |
cb5172ea | 14556 | if (!phba->sli4_hba.pc_sli4_params.supported) |
81b96eda | 14557 | hw_page_size = page_size; |
cb5172ea | 14558 | |
4f774513 JS |
14559 | queue = kzalloc(sizeof(struct lpfc_queue) + |
14560 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
14561 | if (!queue) | |
14562 | return NULL; | |
cb5172ea JS |
14563 | queue->page_count = (ALIGN(entry_size * entry_count, |
14564 | hw_page_size))/hw_page_size; | |
895427bd JS |
14565 | |
14566 | /* If needed, Adjust page count to match the max the adapter supports */ | |
14567 | if (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt) | |
14568 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; | |
14569 | ||
4f774513 | 14570 | INIT_LIST_HEAD(&queue->list); |
895427bd | 14571 | INIT_LIST_HEAD(&queue->wq_list); |
6e8e1c14 | 14572 | INIT_LIST_HEAD(&queue->wqfull_list); |
4f774513 JS |
14573 | INIT_LIST_HEAD(&queue->page_list); |
14574 | INIT_LIST_HEAD(&queue->child_list); | |
81b96eda JS |
14575 | |
14576 | /* Set queue parameters now. If the system cannot provide memory | |
14577 | * resources, the free routine needs to know what was allocated. | |
14578 | */ | |
14579 | queue->entry_size = entry_size; | |
14580 | queue->entry_count = entry_count; | |
14581 | queue->page_size = hw_page_size; | |
14582 | queue->phba = phba; | |
14583 | ||
4f774513 JS |
14584 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
14585 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
14586 | if (!dmabuf) | |
14587 | goto out_fail; | |
1aee383d JP |
14588 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
14589 | hw_page_size, &dmabuf->phys, | |
14590 | GFP_KERNEL); | |
4f774513 JS |
14591 | if (!dmabuf->virt) { |
14592 | kfree(dmabuf); | |
14593 | goto out_fail; | |
14594 | } | |
14595 | dmabuf->buffer_tag = x; | |
14596 | list_add_tail(&dmabuf->list, &queue->page_list); | |
14597 | /* initialize queue's entry array */ | |
14598 | dma_pointer = dmabuf->virt; | |
14599 | for (; total_qe_count < entry_count && | |
cb5172ea | 14600 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
14601 | total_qe_count++, dma_pointer += entry_size) { |
14602 | queue->qe[total_qe_count].address = dma_pointer; | |
14603 | } | |
14604 | } | |
f485c18d DK |
14605 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
14606 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); | |
4f774513 | 14607 | |
64eb4dcb JS |
14608 | /* entry_repost will be set during q creation */ |
14609 | ||
4f774513 JS |
14610 | return queue; |
14611 | out_fail: | |
14612 | lpfc_sli4_queue_free(queue); | |
14613 | return NULL; | |
14614 | } | |
14615 | ||
962bc51b JS |
14616 | /** |
14617 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory | |
14618 | * @phba: HBA structure that indicates port to create a queue on. | |
14619 | * @pci_barset: PCI BAR set flag. | |
14620 | * | |
14621 | * This function shall perform iomap of the specified PCI BAR address to host | |
14622 | * memory address if not already done so and return it. The returned host | |
14623 | * memory address can be NULL. | |
14624 | */ | |
14625 | static void __iomem * | |
14626 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) | |
14627 | { | |
962bc51b JS |
14628 | if (!phba->pcidev) |
14629 | return NULL; | |
962bc51b JS |
14630 | |
14631 | switch (pci_barset) { | |
14632 | case WQ_PCI_BAR_0_AND_1: | |
962bc51b JS |
14633 | return phba->pci_bar0_memmap_p; |
14634 | case WQ_PCI_BAR_2_AND_3: | |
962bc51b JS |
14635 | return phba->pci_bar2_memmap_p; |
14636 | case WQ_PCI_BAR_4_AND_5: | |
962bc51b JS |
14637 | return phba->pci_bar4_memmap_p; |
14638 | default: | |
14639 | break; | |
14640 | } | |
14641 | return NULL; | |
14642 | } | |
14643 | ||
173edbb2 | 14644 | /** |
895427bd | 14645 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
173edbb2 JS |
14646 | * @phba: HBA structure that indicates port to create a queue on. |
14647 | * @startq: The starting FCP EQ to modify | |
14648 | * | |
14649 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. | |
43140ca6 JS |
14650 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
14651 | * updated in one mailbox command. | |
173edbb2 JS |
14652 | * |
14653 | * The @phba struct is used to send mailbox command to HBA. The @startq | |
14654 | * is used to get the starting FCP EQ to change. | |
14655 | * This function is asynchronous and will wait for the mailbox | |
14656 | * command to finish before continuing. | |
14657 | * | |
14658 | * On success this function will return a zero. If unable to allocate enough | |
14659 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
14660 | * fails this function will return -ENXIO. | |
14661 | **/ | |
a2fc4aef | 14662 | int |
0cf07f84 JS |
14663 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
14664 | uint32_t numq, uint32_t imax) | |
173edbb2 JS |
14665 | { |
14666 | struct lpfc_mbx_modify_eq_delay *eq_delay; | |
14667 | LPFC_MBOXQ_t *mbox; | |
14668 | struct lpfc_queue *eq; | |
14669 | int cnt, rc, length, status = 0; | |
14670 | uint32_t shdr_status, shdr_add_status; | |
0cf07f84 | 14671 | uint32_t result, val; |
895427bd | 14672 | int qidx; |
173edbb2 JS |
14673 | union lpfc_sli4_cfg_shdr *shdr; |
14674 | uint16_t dmult; | |
14675 | ||
895427bd | 14676 | if (startq >= phba->io_channel_irqs) |
173edbb2 JS |
14677 | return 0; |
14678 | ||
14679 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14680 | if (!mbox) | |
14681 | return -ENOMEM; | |
14682 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - | |
14683 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14684 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14685 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, | |
14686 | length, LPFC_SLI4_MBX_EMBED); | |
14687 | eq_delay = &mbox->u.mqe.un.eq_delay; | |
14688 | ||
14689 | /* Calculate delay multiper from maximum interrupt per second */ | |
0cf07f84 | 14690 | result = imax / phba->io_channel_irqs; |
895427bd | 14691 | if (result > LPFC_DMULT_CONST || result == 0) |
ee02006b JS |
14692 | dmult = 0; |
14693 | else | |
14694 | dmult = LPFC_DMULT_CONST/result - 1; | |
0cf07f84 JS |
14695 | if (dmult > LPFC_DMULT_MAX) |
14696 | dmult = LPFC_DMULT_MAX; | |
173edbb2 JS |
14697 | |
14698 | cnt = 0; | |
895427bd JS |
14699 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
14700 | eq = phba->sli4_hba.hba_eq[qidx]; | |
173edbb2 JS |
14701 | if (!eq) |
14702 | continue; | |
0cf07f84 | 14703 | eq->q_mode = imax; |
173edbb2 JS |
14704 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
14705 | eq_delay->u.request.eq[cnt].phase = 0; | |
14706 | eq_delay->u.request.eq[cnt].delay_multi = dmult; | |
14707 | cnt++; | |
0cf07f84 JS |
14708 | |
14709 | /* q_mode is only used for auto_imax */ | |
14710 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { | |
14711 | /* Use EQ Delay Register method for q_mode */ | |
14712 | ||
14713 | /* Convert for EQ Delay register */ | |
14714 | val = phba->cfg_fcp_imax; | |
14715 | if (val) { | |
14716 | /* First, interrupts per sec per EQ */ | |
14717 | val = phba->cfg_fcp_imax / | |
14718 | phba->io_channel_irqs; | |
14719 | ||
14720 | /* us delay between each interrupt */ | |
14721 | val = LPFC_SEC_TO_USEC / val; | |
14722 | } | |
14723 | eq->q_mode = val; | |
14724 | } else { | |
14725 | eq->q_mode = imax; | |
14726 | } | |
14727 | ||
14728 | if (cnt >= numq) | |
173edbb2 JS |
14729 | break; |
14730 | } | |
14731 | eq_delay->u.request.num_eq = cnt; | |
14732 | ||
14733 | mbox->vport = phba->pport; | |
14734 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3e1f0718 JS |
14735 | mbox->ctx_buf = NULL; |
14736 | mbox->ctx_ndlp = NULL; | |
173edbb2 JS |
14737 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
14738 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; | |
14739 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14740 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14741 | if (shdr_status || shdr_add_status || rc) { | |
14742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14743 | "2512 MODIFY_EQ_DELAY mailbox failed with " | |
14744 | "status x%x add_status x%x, mbx status x%x\n", | |
14745 | shdr_status, shdr_add_status, rc); | |
14746 | status = -ENXIO; | |
14747 | } | |
14748 | mempool_free(mbox, phba->mbox_mem_pool); | |
14749 | return status; | |
14750 | } | |
14751 | ||
4f774513 JS |
14752 | /** |
14753 | * lpfc_eq_create - Create an Event Queue on the HBA | |
14754 | * @phba: HBA structure that indicates port to create a queue on. | |
14755 | * @eq: The queue structure to use to create the event queue. | |
14756 | * @imax: The maximum interrupt per second limit. | |
14757 | * | |
14758 | * This function creates an event queue, as detailed in @eq, on a port, | |
14759 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
14760 | * | |
14761 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
14762 | * is used to get the entry count and entry size that are necessary to | |
14763 | * determine the number of pages to allocate and use for this queue. This | |
14764 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
14765 | * event queue. This function is asynchronous and will wait for the mailbox | |
14766 | * command to finish before continuing. | |
14767 | * | |
14768 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
14769 | * memory this function will return -ENOMEM. If the queue create mailbox command |
14770 | * fails this function will return -ENXIO. | |
4f774513 | 14771 | **/ |
a2fc4aef | 14772 | int |
ee02006b | 14773 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax) |
4f774513 JS |
14774 | { |
14775 | struct lpfc_mbx_eq_create *eq_create; | |
14776 | LPFC_MBOXQ_t *mbox; | |
14777 | int rc, length, status = 0; | |
14778 | struct lpfc_dmabuf *dmabuf; | |
14779 | uint32_t shdr_status, shdr_add_status; | |
14780 | union lpfc_sli4_cfg_shdr *shdr; | |
14781 | uint16_t dmult; | |
49198b37 JS |
14782 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
14783 | ||
2e90f4b5 JS |
14784 | /* sanity check on queue memory */ |
14785 | if (!eq) | |
14786 | return -ENODEV; | |
49198b37 JS |
14787 | if (!phba->sli4_hba.pc_sli4_params.supported) |
14788 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
14789 | |
14790 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14791 | if (!mbox) | |
14792 | return -ENOMEM; | |
14793 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
14794 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14795 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14796 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
14797 | length, LPFC_SLI4_MBX_EMBED); | |
14798 | eq_create = &mbox->u.mqe.un.eq_create; | |
7365f6fd | 14799 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
4f774513 JS |
14800 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
14801 | eq->page_count); | |
14802 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
14803 | LPFC_EQE_SIZE); | |
14804 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
7365f6fd JS |
14805 | |
14806 | /* Use version 2 of CREATE_EQ if eqav is set */ | |
14807 | if (phba->sli4_hba.pc_sli4_params.eqav) { | |
14808 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
14809 | LPFC_Q_CREATE_VERSION_2); | |
14810 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, | |
14811 | phba->sli4_hba.pc_sli4_params.eqav); | |
14812 | } | |
14813 | ||
2c9c5a00 JS |
14814 | /* don't setup delay multiplier using EQ_CREATE */ |
14815 | dmult = 0; | |
4f774513 JS |
14816 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
14817 | dmult); | |
14818 | switch (eq->entry_count) { | |
14819 | default: | |
14820 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14821 | "0360 Unsupported EQ count. (%d)\n", | |
14822 | eq->entry_count); | |
14823 | if (eq->entry_count < 256) | |
14824 | return -EINVAL; | |
14825 | /* otherwise default to smallest count (drop through) */ | |
14826 | case 256: | |
14827 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
14828 | LPFC_EQ_CNT_256); | |
14829 | break; | |
14830 | case 512: | |
14831 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
14832 | LPFC_EQ_CNT_512); | |
14833 | break; | |
14834 | case 1024: | |
14835 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
14836 | LPFC_EQ_CNT_1024); | |
14837 | break; | |
14838 | case 2048: | |
14839 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
14840 | LPFC_EQ_CNT_2048); | |
14841 | break; | |
14842 | case 4096: | |
14843 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
14844 | LPFC_EQ_CNT_4096); | |
14845 | break; | |
14846 | } | |
14847 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 14848 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
14849 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
14850 | putPaddrLow(dmabuf->phys); | |
14851 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
14852 | putPaddrHigh(dmabuf->phys); | |
14853 | } | |
14854 | mbox->vport = phba->pport; | |
14855 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3e1f0718 JS |
14856 | mbox->ctx_buf = NULL; |
14857 | mbox->ctx_ndlp = NULL; | |
4f774513 | 14858 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
4f774513 JS |
14859 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
14860 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14861 | if (shdr_status || shdr_add_status || rc) { | |
14862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14863 | "2500 EQ_CREATE mailbox failed with " | |
14864 | "status x%x add_status x%x, mbx status x%x\n", | |
14865 | shdr_status, shdr_add_status, rc); | |
14866 | status = -ENXIO; | |
14867 | } | |
14868 | eq->type = LPFC_EQ; | |
14869 | eq->subtype = LPFC_NONE; | |
14870 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
14871 | if (eq->queue_id == 0xFFFF) | |
14872 | status = -ENXIO; | |
14873 | eq->host_index = 0; | |
14874 | eq->hba_index = 0; | |
64eb4dcb | 14875 | eq->entry_repost = LPFC_EQ_REPOST; |
4f774513 | 14876 | |
8fa38513 | 14877 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
14878 | return status; |
14879 | } | |
14880 | ||
14881 | /** | |
14882 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
14883 | * @phba: HBA structure that indicates port to create a queue on. | |
14884 | * @cq: The queue structure to use to create the completion queue. | |
14885 | * @eq: The event queue to bind this completion queue to. | |
14886 | * | |
14887 | * This function creates a completion queue, as detailed in @wq, on a port, | |
14888 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
14889 | * | |
14890 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
14891 | * is used to get the entry count and entry size that are necessary to | |
14892 | * determine the number of pages to allocate and use for this queue. The @eq | |
14893 | * is used to indicate which event queue to bind this completion queue to. This | |
14894 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
14895 | * completion queue. This function is asynchronous and will wait for the mailbox | |
14896 | * command to finish before continuing. | |
14897 | * | |
14898 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
14899 | * memory this function will return -ENOMEM. If the queue create mailbox command |
14900 | * fails this function will return -ENXIO. | |
4f774513 | 14901 | **/ |
a2fc4aef | 14902 | int |
4f774513 JS |
14903 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
14904 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
14905 | { | |
14906 | struct lpfc_mbx_cq_create *cq_create; | |
14907 | struct lpfc_dmabuf *dmabuf; | |
14908 | LPFC_MBOXQ_t *mbox; | |
14909 | int rc, length, status = 0; | |
14910 | uint32_t shdr_status, shdr_add_status; | |
14911 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 14912 | |
2e90f4b5 JS |
14913 | /* sanity check on queue memory */ |
14914 | if (!cq || !eq) | |
14915 | return -ENODEV; | |
49198b37 | 14916 | |
4f774513 JS |
14917 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14918 | if (!mbox) | |
14919 | return -ENOMEM; | |
14920 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
14921 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14922 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14923 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
14924 | length, LPFC_SLI4_MBX_EMBED); | |
14925 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 14926 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
14927 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
14928 | cq->page_count); | |
14929 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
14930 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
14931 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
14932 | phba->sli4_hba.pc_sli4_params.cqv); | |
14933 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
81b96eda JS |
14934 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
14935 | (cq->page_size / SLI4_PAGE_SIZE)); | |
5a6f133e JS |
14936 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
14937 | eq->queue_id); | |
7365f6fd JS |
14938 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
14939 | phba->sli4_hba.pc_sli4_params.cqav); | |
5a6f133e JS |
14940 | } else { |
14941 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
14942 | eq->queue_id); | |
14943 | } | |
4f774513 | 14944 | switch (cq->entry_count) { |
81b96eda JS |
14945 | case 2048: |
14946 | case 4096: | |
14947 | if (phba->sli4_hba.pc_sli4_params.cqv == | |
14948 | LPFC_Q_CREATE_VERSION_2) { | |
14949 | cq_create->u.request.context.lpfc_cq_context_count = | |
14950 | cq->entry_count; | |
14951 | bf_set(lpfc_cq_context_count, | |
14952 | &cq_create->u.request.context, | |
14953 | LPFC_CQ_CNT_WORD7); | |
14954 | break; | |
14955 | } | |
14956 | /* Fall Thru */ | |
4f774513 JS |
14957 | default: |
14958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2ea259ee | 14959 | "0361 Unsupported CQ count: " |
64eb4dcb | 14960 | "entry cnt %d sz %d pg cnt %d\n", |
2ea259ee | 14961 | cq->entry_count, cq->entry_size, |
64eb4dcb | 14962 | cq->page_count); |
4f4c1863 JS |
14963 | if (cq->entry_count < 256) { |
14964 | status = -EINVAL; | |
14965 | goto out; | |
14966 | } | |
4f774513 JS |
14967 | /* otherwise default to smallest count (drop through) */ |
14968 | case 256: | |
14969 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
14970 | LPFC_CQ_CNT_256); | |
14971 | break; | |
14972 | case 512: | |
14973 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
14974 | LPFC_CQ_CNT_512); | |
14975 | break; | |
14976 | case 1024: | |
14977 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
14978 | LPFC_CQ_CNT_1024); | |
14979 | break; | |
14980 | } | |
14981 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
81b96eda | 14982 | memset(dmabuf->virt, 0, cq->page_size); |
4f774513 JS |
14983 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
14984 | putPaddrLow(dmabuf->phys); | |
14985 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
14986 | putPaddrHigh(dmabuf->phys); | |
14987 | } | |
14988 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14989 | ||
14990 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
14991 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
14992 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14993 | if (shdr_status || shdr_add_status || rc) { | |
14994 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14995 | "2501 CQ_CREATE mailbox failed with " | |
14996 | "status x%x add_status x%x, mbx status x%x\n", | |
14997 | shdr_status, shdr_add_status, rc); | |
14998 | status = -ENXIO; | |
14999 | goto out; | |
15000 | } | |
15001 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
15002 | if (cq->queue_id == 0xFFFF) { | |
15003 | status = -ENXIO; | |
15004 | goto out; | |
15005 | } | |
15006 | /* link the cq onto the parent eq child list */ | |
15007 | list_add_tail(&cq->list, &eq->child_list); | |
15008 | /* Set up completion queue's type and subtype */ | |
15009 | cq->type = type; | |
15010 | cq->subtype = subtype; | |
15011 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 15012 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
15013 | cq->host_index = 0; |
15014 | cq->hba_index = 0; | |
64eb4dcb | 15015 | cq->entry_repost = LPFC_CQ_REPOST; |
4f774513 | 15016 | |
8fa38513 JS |
15017 | out: |
15018 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
15019 | return status; |
15020 | } | |
15021 | ||
2d7dbc4c JS |
15022 | /** |
15023 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ | |
15024 | * @phba: HBA structure that indicates port to create a queue on. | |
15025 | * @cqp: The queue structure array to use to create the completion queues. | |
15026 | * @eqp: The event queue array to bind these completion queues to. | |
15027 | * | |
15028 | * This function creates a set of completion queue, s to support MRQ | |
15029 | * as detailed in @cqp, on a port, | |
15030 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. | |
15031 | * | |
15032 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
15033 | * is used to get the entry count and entry size that are necessary to | |
15034 | * determine the number of pages to allocate and use for this queue. The @eq | |
15035 | * is used to indicate which event queue to bind this completion queue to. This | |
15036 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the | |
15037 | * completion queue. This function is asynchronous and will wait for the mailbox | |
15038 | * command to finish before continuing. | |
15039 | * | |
15040 | * On success this function will return a zero. If unable to allocate enough | |
15041 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
15042 | * fails this function will return -ENXIO. | |
15043 | **/ | |
15044 | int | |
15045 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, | |
15046 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) | |
15047 | { | |
15048 | struct lpfc_queue *cq; | |
15049 | struct lpfc_queue *eq; | |
15050 | struct lpfc_mbx_cq_create_set *cq_set; | |
15051 | struct lpfc_dmabuf *dmabuf; | |
15052 | LPFC_MBOXQ_t *mbox; | |
15053 | int rc, length, alloclen, status = 0; | |
15054 | int cnt, idx, numcq, page_idx = 0; | |
15055 | uint32_t shdr_status, shdr_add_status; | |
15056 | union lpfc_sli4_cfg_shdr *shdr; | |
15057 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; | |
15058 | ||
15059 | /* sanity check on queue memory */ | |
15060 | numcq = phba->cfg_nvmet_mrq; | |
15061 | if (!cqp || !eqp || !numcq) | |
15062 | return -ENODEV; | |
2d7dbc4c JS |
15063 | |
15064 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15065 | if (!mbox) | |
15066 | return -ENOMEM; | |
15067 | ||
15068 | length = sizeof(struct lpfc_mbx_cq_create_set); | |
15069 | length += ((numcq * cqp[0]->page_count) * | |
15070 | sizeof(struct dma_address)); | |
15071 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15072 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, | |
15073 | LPFC_SLI4_MBX_NEMBED); | |
15074 | if (alloclen < length) { | |
15075 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15076 | "3098 Allocated DMA memory size (%d) is " | |
15077 | "less than the requested DMA memory size " | |
15078 | "(%d)\n", alloclen, length); | |
15079 | status = -ENOMEM; | |
15080 | goto out; | |
15081 | } | |
15082 | cq_set = mbox->sge_array->addr[0]; | |
15083 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; | |
15084 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); | |
15085 | ||
15086 | for (idx = 0; idx < numcq; idx++) { | |
15087 | cq = cqp[idx]; | |
15088 | eq = eqp[idx]; | |
15089 | if (!cq || !eq) { | |
15090 | status = -ENOMEM; | |
15091 | goto out; | |
15092 | } | |
81b96eda JS |
15093 | if (!phba->sli4_hba.pc_sli4_params.supported) |
15094 | hw_page_size = cq->page_size; | |
2d7dbc4c JS |
15095 | |
15096 | switch (idx) { | |
15097 | case 0: | |
15098 | bf_set(lpfc_mbx_cq_create_set_page_size, | |
15099 | &cq_set->u.request, | |
15100 | (hw_page_size / SLI4_PAGE_SIZE)); | |
15101 | bf_set(lpfc_mbx_cq_create_set_num_pages, | |
15102 | &cq_set->u.request, cq->page_count); | |
15103 | bf_set(lpfc_mbx_cq_create_set_evt, | |
15104 | &cq_set->u.request, 1); | |
15105 | bf_set(lpfc_mbx_cq_create_set_valid, | |
15106 | &cq_set->u.request, 1); | |
15107 | bf_set(lpfc_mbx_cq_create_set_cqe_size, | |
15108 | &cq_set->u.request, 0); | |
15109 | bf_set(lpfc_mbx_cq_create_set_num_cq, | |
15110 | &cq_set->u.request, numcq); | |
7365f6fd JS |
15111 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
15112 | &cq_set->u.request, | |
15113 | phba->sli4_hba.pc_sli4_params.cqav); | |
2d7dbc4c | 15114 | switch (cq->entry_count) { |
81b96eda JS |
15115 | case 2048: |
15116 | case 4096: | |
15117 | if (phba->sli4_hba.pc_sli4_params.cqv == | |
15118 | LPFC_Q_CREATE_VERSION_2) { | |
15119 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, | |
15120 | &cq_set->u.request, | |
15121 | cq->entry_count); | |
15122 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, | |
15123 | &cq_set->u.request, | |
15124 | LPFC_CQ_CNT_WORD7); | |
15125 | break; | |
15126 | } | |
15127 | /* Fall Thru */ | |
2d7dbc4c JS |
15128 | default: |
15129 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15130 | "3118 Bad CQ count. (%d)\n", | |
15131 | cq->entry_count); | |
15132 | if (cq->entry_count < 256) { | |
15133 | status = -EINVAL; | |
15134 | goto out; | |
15135 | } | |
15136 | /* otherwise default to smallest (drop thru) */ | |
15137 | case 256: | |
15138 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, | |
15139 | &cq_set->u.request, LPFC_CQ_CNT_256); | |
15140 | break; | |
15141 | case 512: | |
15142 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, | |
15143 | &cq_set->u.request, LPFC_CQ_CNT_512); | |
15144 | break; | |
15145 | case 1024: | |
15146 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, | |
15147 | &cq_set->u.request, LPFC_CQ_CNT_1024); | |
15148 | break; | |
15149 | } | |
15150 | bf_set(lpfc_mbx_cq_create_set_eq_id0, | |
15151 | &cq_set->u.request, eq->queue_id); | |
15152 | break; | |
15153 | case 1: | |
15154 | bf_set(lpfc_mbx_cq_create_set_eq_id1, | |
15155 | &cq_set->u.request, eq->queue_id); | |
15156 | break; | |
15157 | case 2: | |
15158 | bf_set(lpfc_mbx_cq_create_set_eq_id2, | |
15159 | &cq_set->u.request, eq->queue_id); | |
15160 | break; | |
15161 | case 3: | |
15162 | bf_set(lpfc_mbx_cq_create_set_eq_id3, | |
15163 | &cq_set->u.request, eq->queue_id); | |
15164 | break; | |
15165 | case 4: | |
15166 | bf_set(lpfc_mbx_cq_create_set_eq_id4, | |
15167 | &cq_set->u.request, eq->queue_id); | |
15168 | break; | |
15169 | case 5: | |
15170 | bf_set(lpfc_mbx_cq_create_set_eq_id5, | |
15171 | &cq_set->u.request, eq->queue_id); | |
15172 | break; | |
15173 | case 6: | |
15174 | bf_set(lpfc_mbx_cq_create_set_eq_id6, | |
15175 | &cq_set->u.request, eq->queue_id); | |
15176 | break; | |
15177 | case 7: | |
15178 | bf_set(lpfc_mbx_cq_create_set_eq_id7, | |
15179 | &cq_set->u.request, eq->queue_id); | |
15180 | break; | |
15181 | case 8: | |
15182 | bf_set(lpfc_mbx_cq_create_set_eq_id8, | |
15183 | &cq_set->u.request, eq->queue_id); | |
15184 | break; | |
15185 | case 9: | |
15186 | bf_set(lpfc_mbx_cq_create_set_eq_id9, | |
15187 | &cq_set->u.request, eq->queue_id); | |
15188 | break; | |
15189 | case 10: | |
15190 | bf_set(lpfc_mbx_cq_create_set_eq_id10, | |
15191 | &cq_set->u.request, eq->queue_id); | |
15192 | break; | |
15193 | case 11: | |
15194 | bf_set(lpfc_mbx_cq_create_set_eq_id11, | |
15195 | &cq_set->u.request, eq->queue_id); | |
15196 | break; | |
15197 | case 12: | |
15198 | bf_set(lpfc_mbx_cq_create_set_eq_id12, | |
15199 | &cq_set->u.request, eq->queue_id); | |
15200 | break; | |
15201 | case 13: | |
15202 | bf_set(lpfc_mbx_cq_create_set_eq_id13, | |
15203 | &cq_set->u.request, eq->queue_id); | |
15204 | break; | |
15205 | case 14: | |
15206 | bf_set(lpfc_mbx_cq_create_set_eq_id14, | |
15207 | &cq_set->u.request, eq->queue_id); | |
15208 | break; | |
15209 | case 15: | |
15210 | bf_set(lpfc_mbx_cq_create_set_eq_id15, | |
15211 | &cq_set->u.request, eq->queue_id); | |
15212 | break; | |
15213 | } | |
15214 | ||
15215 | /* link the cq onto the parent eq child list */ | |
15216 | list_add_tail(&cq->list, &eq->child_list); | |
15217 | /* Set up completion queue's type and subtype */ | |
15218 | cq->type = type; | |
15219 | cq->subtype = subtype; | |
15220 | cq->assoc_qid = eq->queue_id; | |
15221 | cq->host_index = 0; | |
15222 | cq->hba_index = 0; | |
64eb4dcb | 15223 | cq->entry_repost = LPFC_CQ_REPOST; |
81b96eda | 15224 | cq->chann = idx; |
2d7dbc4c JS |
15225 | |
15226 | rc = 0; | |
15227 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
15228 | memset(dmabuf->virt, 0, hw_page_size); | |
15229 | cnt = page_idx + dmabuf->buffer_tag; | |
15230 | cq_set->u.request.page[cnt].addr_lo = | |
15231 | putPaddrLow(dmabuf->phys); | |
15232 | cq_set->u.request.page[cnt].addr_hi = | |
15233 | putPaddrHigh(dmabuf->phys); | |
15234 | rc++; | |
15235 | } | |
15236 | page_idx += rc; | |
15237 | } | |
15238 | ||
15239 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
15240 | ||
15241 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
15242 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15243 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15244 | if (shdr_status || shdr_add_status || rc) { | |
15245 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15246 | "3119 CQ_CREATE_SET mailbox failed with " | |
15247 | "status x%x add_status x%x, mbx status x%x\n", | |
15248 | shdr_status, shdr_add_status, rc); | |
15249 | status = -ENXIO; | |
15250 | goto out; | |
15251 | } | |
15252 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); | |
15253 | if (rc == 0xFFFF) { | |
15254 | status = -ENXIO; | |
15255 | goto out; | |
15256 | } | |
15257 | ||
15258 | for (idx = 0; idx < numcq; idx++) { | |
15259 | cq = cqp[idx]; | |
15260 | cq->queue_id = rc + idx; | |
15261 | } | |
15262 | ||
15263 | out: | |
15264 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
15265 | return status; | |
15266 | } | |
15267 | ||
b19a061a JS |
15268 | /** |
15269 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
15270 | * @phba: HBA structure that indicates port to create a queue on. | |
15271 | * @mq: The queue structure to use to create the mailbox queue. | |
15272 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
15273 | * @cq: The completion queue to associate with this cq. | |
15274 | * | |
15275 | * This function provides failback (fb) functionality when the | |
15276 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
15277 | * to mq_create_ext otherwise. | |
15278 | * | |
15279 | * This routine cannot fail as all attributes were previously accessed and | |
15280 | * initialized in mq_create_ext. | |
15281 | **/ | |
15282 | static void | |
15283 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
15284 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
15285 | { | |
15286 | struct lpfc_mbx_mq_create *mq_create; | |
15287 | struct lpfc_dmabuf *dmabuf; | |
15288 | int length; | |
15289 | ||
15290 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
15291 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15292 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
15293 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
15294 | length, LPFC_SLI4_MBX_EMBED); | |
15295 | mq_create = &mbox->u.mqe.un.mq_create; | |
15296 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
15297 | mq->page_count); | |
15298 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
15299 | cq->queue_id); | |
15300 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
15301 | switch (mq->entry_count) { | |
15302 | case 16: | |
5a6f133e JS |
15303 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
15304 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
15305 | break; |
15306 | case 32: | |
5a6f133e JS |
15307 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
15308 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
15309 | break; |
15310 | case 64: | |
5a6f133e JS |
15311 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
15312 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
15313 | break; |
15314 | case 128: | |
5a6f133e JS |
15315 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
15316 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
15317 | break; |
15318 | } | |
15319 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
15320 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
15321 | putPaddrLow(dmabuf->phys); | |
15322 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
15323 | putPaddrHigh(dmabuf->phys); | |
15324 | } | |
15325 | } | |
15326 | ||
04c68496 JS |
15327 | /** |
15328 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
15329 | * @phba: HBA structure that indicates port to create a queue on. | |
15330 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
15331 | * @cq: The completion queue to associate with this cq. |
15332 | * @subtype: The queue's subtype. | |
04c68496 JS |
15333 | * |
15334 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
15335 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
15336 | * | |
15337 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
15338 | * is used to get the entry count and entry size that are necessary to | |
15339 | * determine the number of pages to allocate and use for this queue. This | |
15340 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
15341 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
15342 | * command to finish before continuing. | |
15343 | * | |
15344 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
15345 | * memory this function will return -ENOMEM. If the queue create mailbox command |
15346 | * fails this function will return -ENXIO. | |
04c68496 | 15347 | **/ |
b19a061a | 15348 | int32_t |
04c68496 JS |
15349 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
15350 | struct lpfc_queue *cq, uint32_t subtype) | |
15351 | { | |
15352 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 15353 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
15354 | struct lpfc_dmabuf *dmabuf; |
15355 | LPFC_MBOXQ_t *mbox; | |
15356 | int rc, length, status = 0; | |
15357 | uint32_t shdr_status, shdr_add_status; | |
15358 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 15359 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 15360 | |
2e90f4b5 JS |
15361 | /* sanity check on queue memory */ |
15362 | if (!mq || !cq) | |
15363 | return -ENODEV; | |
49198b37 JS |
15364 | if (!phba->sli4_hba.pc_sli4_params.supported) |
15365 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 15366 | |
04c68496 JS |
15367 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15368 | if (!mbox) | |
15369 | return -ENOMEM; | |
b19a061a | 15370 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
15371 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
15372 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 15373 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 15374 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
15375 | |
15376 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 15377 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
15378 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
15379 | &mq_create_ext->u.request, mq->page_count); | |
15380 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
15381 | &mq_create_ext->u.request, 1); | |
15382 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
15383 | &mq_create_ext->u.request, 1); |
15384 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
15385 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
15386 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
15387 | &mq_create_ext->u.request, 1); | |
15388 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
15389 | &mq_create_ext->u.request, 1); | |
b19a061a | 15390 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
15391 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
15392 | phba->sli4_hba.pc_sli4_params.mqv); | |
15393 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
15394 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
15395 | cq->queue_id); | |
15396 | else | |
15397 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
15398 | cq->queue_id); | |
04c68496 JS |
15399 | switch (mq->entry_count) { |
15400 | default: | |
15401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15402 | "0362 Unsupported MQ count. (%d)\n", | |
15403 | mq->entry_count); | |
4f4c1863 JS |
15404 | if (mq->entry_count < 16) { |
15405 | status = -EINVAL; | |
15406 | goto out; | |
15407 | } | |
04c68496 JS |
15408 | /* otherwise default to smallest count (drop through) */ |
15409 | case 16: | |
5a6f133e JS |
15410 | bf_set(lpfc_mq_context_ring_size, |
15411 | &mq_create_ext->u.request.context, | |
15412 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
15413 | break; |
15414 | case 32: | |
5a6f133e JS |
15415 | bf_set(lpfc_mq_context_ring_size, |
15416 | &mq_create_ext->u.request.context, | |
15417 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
15418 | break; |
15419 | case 64: | |
5a6f133e JS |
15420 | bf_set(lpfc_mq_context_ring_size, |
15421 | &mq_create_ext->u.request.context, | |
15422 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
15423 | break; |
15424 | case 128: | |
5a6f133e JS |
15425 | bf_set(lpfc_mq_context_ring_size, |
15426 | &mq_create_ext->u.request.context, | |
15427 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
15428 | break; |
15429 | } | |
15430 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 15431 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 15432 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 15433 | putPaddrLow(dmabuf->phys); |
b19a061a | 15434 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
15435 | putPaddrHigh(dmabuf->phys); |
15436 | } | |
15437 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
15438 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
15439 | &mq_create_ext->u.response); | |
15440 | if (rc != MBX_SUCCESS) { | |
15441 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
15442 | "2795 MQ_CREATE_EXT failed with " | |
15443 | "status x%x. Failback to MQ_CREATE.\n", | |
15444 | rc); | |
15445 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
15446 | mq_create = &mbox->u.mqe.un.mq_create; | |
15447 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
15448 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
15449 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
15450 | &mq_create->u.response); | |
15451 | } | |
15452 | ||
04c68496 | 15453 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
15454 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
15455 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15456 | if (shdr_status || shdr_add_status || rc) { | |
15457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15458 | "2502 MQ_CREATE mailbox failed with " | |
15459 | "status x%x add_status x%x, mbx status x%x\n", | |
15460 | shdr_status, shdr_add_status, rc); | |
15461 | status = -ENXIO; | |
15462 | goto out; | |
15463 | } | |
04c68496 JS |
15464 | if (mq->queue_id == 0xFFFF) { |
15465 | status = -ENXIO; | |
15466 | goto out; | |
15467 | } | |
15468 | mq->type = LPFC_MQ; | |
2a622bfb | 15469 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
15470 | mq->subtype = subtype; |
15471 | mq->host_index = 0; | |
15472 | mq->hba_index = 0; | |
64eb4dcb | 15473 | mq->entry_repost = LPFC_MQ_REPOST; |
04c68496 JS |
15474 | |
15475 | /* link the mq onto the parent cq child list */ | |
15476 | list_add_tail(&mq->list, &cq->child_list); | |
15477 | out: | |
8fa38513 | 15478 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
15479 | return status; |
15480 | } | |
15481 | ||
4f774513 JS |
15482 | /** |
15483 | * lpfc_wq_create - Create a Work Queue on the HBA | |
15484 | * @phba: HBA structure that indicates port to create a queue on. | |
15485 | * @wq: The queue structure to use to create the work queue. | |
15486 | * @cq: The completion queue to bind this work queue to. | |
15487 | * @subtype: The subtype of the work queue indicating its functionality. | |
15488 | * | |
15489 | * This function creates a work queue, as detailed in @wq, on a port, described | |
15490 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
15491 | * | |
15492 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
15493 | * is used to get the entry count and entry size that are necessary to | |
15494 | * determine the number of pages to allocate and use for this queue. The @cq | |
15495 | * is used to indicate which completion queue to bind this work queue to. This | |
15496 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
15497 | * work queue. This function is asynchronous and will wait for the mailbox | |
15498 | * command to finish before continuing. | |
15499 | * | |
15500 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
15501 | * memory this function will return -ENOMEM. If the queue create mailbox command |
15502 | * fails this function will return -ENXIO. | |
4f774513 | 15503 | **/ |
a2fc4aef | 15504 | int |
4f774513 JS |
15505 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
15506 | struct lpfc_queue *cq, uint32_t subtype) | |
15507 | { | |
15508 | struct lpfc_mbx_wq_create *wq_create; | |
15509 | struct lpfc_dmabuf *dmabuf; | |
15510 | LPFC_MBOXQ_t *mbox; | |
15511 | int rc, length, status = 0; | |
15512 | uint32_t shdr_status, shdr_add_status; | |
15513 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 15514 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 15515 | struct dma_address *page; |
962bc51b JS |
15516 | void __iomem *bar_memmap_p; |
15517 | uint32_t db_offset; | |
15518 | uint16_t pci_barset; | |
1351e69f JS |
15519 | uint8_t dpp_barset; |
15520 | uint32_t dpp_offset; | |
15521 | unsigned long pg_addr; | |
81b96eda | 15522 | uint8_t wq_create_version; |
49198b37 | 15523 | |
2e90f4b5 JS |
15524 | /* sanity check on queue memory */ |
15525 | if (!wq || !cq) | |
15526 | return -ENODEV; | |
49198b37 | 15527 | if (!phba->sli4_hba.pc_sli4_params.supported) |
81b96eda | 15528 | hw_page_size = wq->page_size; |
4f774513 JS |
15529 | |
15530 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15531 | if (!mbox) | |
15532 | return -ENOMEM; | |
15533 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
15534 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15535 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15536 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
15537 | length, LPFC_SLI4_MBX_EMBED); | |
15538 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 15539 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
15540 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
15541 | wq->page_count); | |
15542 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
15543 | cq->queue_id); | |
0c651878 JS |
15544 | |
15545 | /* wqv is the earliest version supported, NOT the latest */ | |
5a6f133e JS |
15546 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
15547 | phba->sli4_hba.pc_sli4_params.wqv); | |
962bc51b | 15548 | |
c176ffa0 JS |
15549 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
15550 | (wq->page_size > SLI4_PAGE_SIZE)) | |
81b96eda JS |
15551 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
15552 | else | |
15553 | wq_create_version = LPFC_Q_CREATE_VERSION_0; | |
15554 | ||
0c651878 | 15555 | |
1351e69f JS |
15556 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
15557 | wq_create_version = LPFC_Q_CREATE_VERSION_1; | |
15558 | else | |
15559 | wq_create_version = LPFC_Q_CREATE_VERSION_0; | |
15560 | ||
15561 | switch (wq_create_version) { | |
0c651878 | 15562 | case LPFC_Q_CREATE_VERSION_1: |
5a6f133e JS |
15563 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
15564 | wq->entry_count); | |
3f247de7 JS |
15565 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
15566 | LPFC_Q_CREATE_VERSION_1); | |
15567 | ||
5a6f133e JS |
15568 | switch (wq->entry_size) { |
15569 | default: | |
15570 | case 64: | |
15571 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
15572 | &wq_create->u.request_1, | |
15573 | LPFC_WQ_WQE_SIZE_64); | |
15574 | break; | |
15575 | case 128: | |
15576 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
15577 | &wq_create->u.request_1, | |
15578 | LPFC_WQ_WQE_SIZE_128); | |
15579 | break; | |
15580 | } | |
1351e69f JS |
15581 | /* Request DPP by default */ |
15582 | bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1); | |
8ea73db4 JS |
15583 | bf_set(lpfc_mbx_wq_create_page_size, |
15584 | &wq_create->u.request_1, | |
81b96eda | 15585 | (wq->page_size / SLI4_PAGE_SIZE)); |
5a6f133e | 15586 | page = wq_create->u.request_1.page; |
0c651878 JS |
15587 | break; |
15588 | default: | |
1351e69f JS |
15589 | page = wq_create->u.request.page; |
15590 | break; | |
5a6f133e | 15591 | } |
0c651878 | 15592 | |
4f774513 | 15593 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 15594 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
15595 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
15596 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 | 15597 | } |
962bc51b JS |
15598 | |
15599 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) | |
15600 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); | |
15601 | ||
4f774513 JS |
15602 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
15603 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
15604 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
15605 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15606 | if (shdr_status || shdr_add_status || rc) { | |
15607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15608 | "2503 WQ_CREATE mailbox failed with " | |
15609 | "status x%x add_status x%x, mbx status x%x\n", | |
15610 | shdr_status, shdr_add_status, rc); | |
15611 | status = -ENXIO; | |
15612 | goto out; | |
15613 | } | |
1351e69f JS |
15614 | |
15615 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) | |
15616 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, | |
15617 | &wq_create->u.response); | |
15618 | else | |
15619 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, | |
15620 | &wq_create->u.response_1); | |
15621 | ||
4f774513 JS |
15622 | if (wq->queue_id == 0xFFFF) { |
15623 | status = -ENXIO; | |
15624 | goto out; | |
15625 | } | |
1351e69f JS |
15626 | |
15627 | wq->db_format = LPFC_DB_LIST_FORMAT; | |
15628 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { | |
15629 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { | |
15630 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, | |
15631 | &wq_create->u.response); | |
15632 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && | |
15633 | (wq->db_format != LPFC_DB_RING_FORMAT)) { | |
15634 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15635 | "3265 WQ[%d] doorbell format " | |
15636 | "not supported: x%x\n", | |
15637 | wq->queue_id, wq->db_format); | |
15638 | status = -EINVAL; | |
15639 | goto out; | |
15640 | } | |
15641 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, | |
15642 | &wq_create->u.response); | |
15643 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, | |
15644 | pci_barset); | |
15645 | if (!bar_memmap_p) { | |
15646 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15647 | "3263 WQ[%d] failed to memmap " | |
15648 | "pci barset:x%x\n", | |
15649 | wq->queue_id, pci_barset); | |
15650 | status = -ENOMEM; | |
15651 | goto out; | |
15652 | } | |
15653 | db_offset = wq_create->u.response.doorbell_offset; | |
15654 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && | |
15655 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { | |
15656 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15657 | "3252 WQ[%d] doorbell offset " | |
15658 | "not supported: x%x\n", | |
15659 | wq->queue_id, db_offset); | |
15660 | status = -EINVAL; | |
15661 | goto out; | |
15662 | } | |
15663 | wq->db_regaddr = bar_memmap_p + db_offset; | |
15664 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
15665 | "3264 WQ[%d]: barset:x%x, offset:x%x, " | |
15666 | "format:x%x\n", wq->queue_id, | |
15667 | pci_barset, db_offset, wq->db_format); | |
15668 | } else | |
15669 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; | |
962bc51b | 15670 | } else { |
1351e69f JS |
15671 | /* Check if DPP was honored by the firmware */ |
15672 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, | |
15673 | &wq_create->u.response_1); | |
15674 | if (wq->dpp_enable) { | |
15675 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, | |
15676 | &wq_create->u.response_1); | |
15677 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, | |
15678 | pci_barset); | |
15679 | if (!bar_memmap_p) { | |
15680 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15681 | "3267 WQ[%d] failed to memmap " | |
15682 | "pci barset:x%x\n", | |
15683 | wq->queue_id, pci_barset); | |
15684 | status = -ENOMEM; | |
15685 | goto out; | |
15686 | } | |
15687 | db_offset = wq_create->u.response_1.doorbell_offset; | |
15688 | wq->db_regaddr = bar_memmap_p + db_offset; | |
15689 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, | |
15690 | &wq_create->u.response_1); | |
15691 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, | |
15692 | &wq_create->u.response_1); | |
15693 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, | |
15694 | dpp_barset); | |
15695 | if (!bar_memmap_p) { | |
15696 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15697 | "3268 WQ[%d] failed to memmap " | |
15698 | "pci barset:x%x\n", | |
15699 | wq->queue_id, dpp_barset); | |
15700 | status = -ENOMEM; | |
15701 | goto out; | |
15702 | } | |
15703 | dpp_offset = wq_create->u.response_1.dpp_offset; | |
15704 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; | |
15705 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
15706 | "3271 WQ[%d]: barset:x%x, offset:x%x, " | |
15707 | "dpp_id:x%x dpp_barset:x%x " | |
15708 | "dpp_offset:x%x\n", | |
15709 | wq->queue_id, pci_barset, db_offset, | |
15710 | wq->dpp_id, dpp_barset, dpp_offset); | |
15711 | ||
15712 | /* Enable combined writes for DPP aperture */ | |
15713 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; | |
15714 | #ifdef CONFIG_X86 | |
15715 | rc = set_memory_wc(pg_addr, 1); | |
15716 | if (rc) { | |
15717 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15718 | "3272 Cannot setup Combined " | |
15719 | "Write on WQ[%d] - disable DPP\n", | |
15720 | wq->queue_id); | |
15721 | phba->cfg_enable_dpp = 0; | |
15722 | } | |
15723 | #else | |
15724 | phba->cfg_enable_dpp = 0; | |
15725 | #endif | |
15726 | } else | |
15727 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; | |
962bc51b | 15728 | } |
895427bd JS |
15729 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
15730 | if (wq->pring == NULL) { | |
15731 | status = -ENOMEM; | |
15732 | goto out; | |
15733 | } | |
4f774513 | 15734 | wq->type = LPFC_WQ; |
2a622bfb | 15735 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
15736 | wq->subtype = subtype; |
15737 | wq->host_index = 0; | |
15738 | wq->hba_index = 0; | |
ff78d8f9 | 15739 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
15740 | |
15741 | /* link the wq onto the parent cq child list */ | |
15742 | list_add_tail(&wq->list, &cq->child_list); | |
15743 | out: | |
8fa38513 | 15744 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
15745 | return status; |
15746 | } | |
15747 | ||
15748 | /** | |
15749 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
15750 | * @phba: HBA structure that indicates port to create a queue on. | |
15751 | * @hrq: The queue structure to use to create the header receive queue. | |
15752 | * @drq: The queue structure to use to create the data receive queue. | |
15753 | * @cq: The completion queue to bind this work queue to. | |
15754 | * | |
15755 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
15756 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
15757 | * to the HBA. | |
15758 | * | |
15759 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
15760 | * struct is used to get the entry count that is necessary to determine the | |
15761 | * number of pages to use for this queue. The @cq is used to indicate which | |
15762 | * completion queue to bind received buffers that are posted to these queues to. | |
15763 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
15764 | * receive queue pair. This function is asynchronous and will wait for the | |
15765 | * mailbox command to finish before continuing. | |
15766 | * | |
15767 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
15768 | * memory this function will return -ENOMEM. If the queue create mailbox command |
15769 | * fails this function will return -ENXIO. | |
4f774513 | 15770 | **/ |
a2fc4aef | 15771 | int |
4f774513 JS |
15772 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
15773 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
15774 | { | |
15775 | struct lpfc_mbx_rq_create *rq_create; | |
15776 | struct lpfc_dmabuf *dmabuf; | |
15777 | LPFC_MBOXQ_t *mbox; | |
15778 | int rc, length, status = 0; | |
15779 | uint32_t shdr_status, shdr_add_status; | |
15780 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 15781 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
962bc51b JS |
15782 | void __iomem *bar_memmap_p; |
15783 | uint32_t db_offset; | |
15784 | uint16_t pci_barset; | |
49198b37 | 15785 | |
2e90f4b5 JS |
15786 | /* sanity check on queue memory */ |
15787 | if (!hrq || !drq || !cq) | |
15788 | return -ENODEV; | |
49198b37 JS |
15789 | if (!phba->sli4_hba.pc_sli4_params.supported) |
15790 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
15791 | |
15792 | if (hrq->entry_count != drq->entry_count) | |
15793 | return -EINVAL; | |
15794 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15795 | if (!mbox) | |
15796 | return -ENOMEM; | |
15797 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
15798 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15799 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15800 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
15801 | length, LPFC_SLI4_MBX_EMBED); | |
15802 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
15803 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
15804 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
15805 | phba->sli4_hba.pc_sli4_params.rqv); | |
15806 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
15807 | bf_set(lpfc_rq_context_rqe_count_1, | |
15808 | &rq_create->u.request.context, | |
15809 | hrq->entry_count); | |
15810 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
15811 | bf_set(lpfc_rq_context_rqe_size, |
15812 | &rq_create->u.request.context, | |
15813 | LPFC_RQE_SIZE_8); | |
15814 | bf_set(lpfc_rq_context_page_size, | |
15815 | &rq_create->u.request.context, | |
8ea73db4 | 15816 | LPFC_RQ_PAGE_SIZE_4096); |
5a6f133e JS |
15817 | } else { |
15818 | switch (hrq->entry_count) { | |
15819 | default: | |
15820 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15821 | "2535 Unsupported RQ count. (%d)\n", | |
15822 | hrq->entry_count); | |
4f4c1863 JS |
15823 | if (hrq->entry_count < 512) { |
15824 | status = -EINVAL; | |
15825 | goto out; | |
15826 | } | |
5a6f133e JS |
15827 | /* otherwise default to smallest count (drop through) */ |
15828 | case 512: | |
15829 | bf_set(lpfc_rq_context_rqe_count, | |
15830 | &rq_create->u.request.context, | |
15831 | LPFC_RQ_RING_SIZE_512); | |
15832 | break; | |
15833 | case 1024: | |
15834 | bf_set(lpfc_rq_context_rqe_count, | |
15835 | &rq_create->u.request.context, | |
15836 | LPFC_RQ_RING_SIZE_1024); | |
15837 | break; | |
15838 | case 2048: | |
15839 | bf_set(lpfc_rq_context_rqe_count, | |
15840 | &rq_create->u.request.context, | |
15841 | LPFC_RQ_RING_SIZE_2048); | |
15842 | break; | |
15843 | case 4096: | |
15844 | bf_set(lpfc_rq_context_rqe_count, | |
15845 | &rq_create->u.request.context, | |
15846 | LPFC_RQ_RING_SIZE_4096); | |
15847 | break; | |
15848 | } | |
15849 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
15850 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
15851 | } |
15852 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
15853 | cq->queue_id); | |
15854 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
15855 | hrq->page_count); | |
4f774513 | 15856 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 15857 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
15858 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
15859 | putPaddrLow(dmabuf->phys); | |
15860 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
15861 | putPaddrHigh(dmabuf->phys); | |
15862 | } | |
962bc51b JS |
15863 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
15864 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
15865 | ||
4f774513 JS |
15866 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
15867 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
15868 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
15869 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15870 | if (shdr_status || shdr_add_status || rc) { | |
15871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15872 | "2504 RQ_CREATE mailbox failed with " | |
15873 | "status x%x add_status x%x, mbx status x%x\n", | |
15874 | shdr_status, shdr_add_status, rc); | |
15875 | status = -ENXIO; | |
15876 | goto out; | |
15877 | } | |
15878 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
15879 | if (hrq->queue_id == 0xFFFF) { | |
15880 | status = -ENXIO; | |
15881 | goto out; | |
15882 | } | |
962bc51b JS |
15883 | |
15884 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { | |
15885 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, | |
15886 | &rq_create->u.response); | |
15887 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && | |
15888 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { | |
15889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15890 | "3262 RQ [%d] doorbell format not " | |
15891 | "supported: x%x\n", hrq->queue_id, | |
15892 | hrq->db_format); | |
15893 | status = -EINVAL; | |
15894 | goto out; | |
15895 | } | |
15896 | ||
15897 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, | |
15898 | &rq_create->u.response); | |
15899 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); | |
15900 | if (!bar_memmap_p) { | |
15901 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15902 | "3269 RQ[%d] failed to memmap pci " | |
15903 | "barset:x%x\n", hrq->queue_id, | |
15904 | pci_barset); | |
15905 | status = -ENOMEM; | |
15906 | goto out; | |
15907 | } | |
15908 | ||
15909 | db_offset = rq_create->u.response.doorbell_offset; | |
15910 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && | |
15911 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { | |
15912 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15913 | "3270 RQ[%d] doorbell offset not " | |
15914 | "supported: x%x\n", hrq->queue_id, | |
15915 | db_offset); | |
15916 | status = -EINVAL; | |
15917 | goto out; | |
15918 | } | |
15919 | hrq->db_regaddr = bar_memmap_p + db_offset; | |
15920 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
a22e7db3 JS |
15921 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
15922 | "format:x%x\n", hrq->queue_id, pci_barset, | |
15923 | db_offset, hrq->db_format); | |
962bc51b JS |
15924 | } else { |
15925 | hrq->db_format = LPFC_DB_RING_FORMAT; | |
15926 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; | |
15927 | } | |
4f774513 | 15928 | hrq->type = LPFC_HRQ; |
2a622bfb | 15929 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
15930 | hrq->subtype = subtype; |
15931 | hrq->host_index = 0; | |
15932 | hrq->hba_index = 0; | |
61f3d4bf | 15933 | hrq->entry_repost = LPFC_RQ_REPOST; |
4f774513 JS |
15934 | |
15935 | /* now create the data queue */ | |
15936 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15937 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
15938 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
15939 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
15940 | phba->sli4_hba.pc_sli4_params.rqv); | |
15941 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
15942 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 15943 | &rq_create->u.request.context, hrq->entry_count); |
3c603be9 JS |
15944 | if (subtype == LPFC_NVMET) |
15945 | rq_create->u.request.context.buffer_size = | |
15946 | LPFC_NVMET_DATA_BUF_SIZE; | |
15947 | else | |
15948 | rq_create->u.request.context.buffer_size = | |
15949 | LPFC_DATA_BUF_SIZE; | |
c31098ce JS |
15950 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
15951 | LPFC_RQE_SIZE_8); | |
15952 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
15953 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
15954 | } else { |
15955 | switch (drq->entry_count) { | |
15956 | default: | |
15957 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15958 | "2536 Unsupported RQ count. (%d)\n", | |
15959 | drq->entry_count); | |
4f4c1863 JS |
15960 | if (drq->entry_count < 512) { |
15961 | status = -EINVAL; | |
15962 | goto out; | |
15963 | } | |
5a6f133e JS |
15964 | /* otherwise default to smallest count (drop through) */ |
15965 | case 512: | |
15966 | bf_set(lpfc_rq_context_rqe_count, | |
15967 | &rq_create->u.request.context, | |
15968 | LPFC_RQ_RING_SIZE_512); | |
15969 | break; | |
15970 | case 1024: | |
15971 | bf_set(lpfc_rq_context_rqe_count, | |
15972 | &rq_create->u.request.context, | |
15973 | LPFC_RQ_RING_SIZE_1024); | |
15974 | break; | |
15975 | case 2048: | |
15976 | bf_set(lpfc_rq_context_rqe_count, | |
15977 | &rq_create->u.request.context, | |
15978 | LPFC_RQ_RING_SIZE_2048); | |
15979 | break; | |
15980 | case 4096: | |
15981 | bf_set(lpfc_rq_context_rqe_count, | |
15982 | &rq_create->u.request.context, | |
15983 | LPFC_RQ_RING_SIZE_4096); | |
15984 | break; | |
15985 | } | |
3c603be9 JS |
15986 | if (subtype == LPFC_NVMET) |
15987 | bf_set(lpfc_rq_context_buf_size, | |
15988 | &rq_create->u.request.context, | |
15989 | LPFC_NVMET_DATA_BUF_SIZE); | |
15990 | else | |
15991 | bf_set(lpfc_rq_context_buf_size, | |
15992 | &rq_create->u.request.context, | |
15993 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
15994 | } |
15995 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
15996 | cq->queue_id); | |
15997 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
15998 | drq->page_count); | |
4f774513 JS |
15999 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
16000 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
16001 | putPaddrLow(dmabuf->phys); | |
16002 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
16003 | putPaddrHigh(dmabuf->phys); | |
16004 | } | |
962bc51b JS |
16005 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
16006 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); | |
4f774513 JS |
16007 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
16008 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16009 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
16010 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16011 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16012 | if (shdr_status || shdr_add_status || rc) { | |
16013 | status = -ENXIO; | |
16014 | goto out; | |
16015 | } | |
16016 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
16017 | if (drq->queue_id == 0xFFFF) { | |
16018 | status = -ENXIO; | |
16019 | goto out; | |
16020 | } | |
16021 | drq->type = LPFC_DRQ; | |
2a622bfb | 16022 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
16023 | drq->subtype = subtype; |
16024 | drq->host_index = 0; | |
16025 | drq->hba_index = 0; | |
61f3d4bf | 16026 | drq->entry_repost = LPFC_RQ_REPOST; |
4f774513 JS |
16027 | |
16028 | /* link the header and data RQs onto the parent cq child list */ | |
16029 | list_add_tail(&hrq->list, &cq->child_list); | |
16030 | list_add_tail(&drq->list, &cq->child_list); | |
16031 | ||
16032 | out: | |
8fa38513 | 16033 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
16034 | return status; |
16035 | } | |
16036 | ||
2d7dbc4c JS |
16037 | /** |
16038 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA | |
16039 | * @phba: HBA structure that indicates port to create a queue on. | |
16040 | * @hrqp: The queue structure array to use to create the header receive queues. | |
16041 | * @drqp: The queue structure array to use to create the data receive queues. | |
16042 | * @cqp: The completion queue array to bind these receive queues to. | |
16043 | * | |
16044 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
16045 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
16046 | * to the HBA. | |
16047 | * | |
16048 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
16049 | * struct is used to get the entry count that is necessary to determine the | |
16050 | * number of pages to use for this queue. The @cq is used to indicate which | |
16051 | * completion queue to bind received buffers that are posted to these queues to. | |
16052 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
16053 | * receive queue pair. This function is asynchronous and will wait for the | |
16054 | * mailbox command to finish before continuing. | |
16055 | * | |
16056 | * On success this function will return a zero. If unable to allocate enough | |
16057 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
16058 | * fails this function will return -ENXIO. | |
16059 | **/ | |
16060 | int | |
16061 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, | |
16062 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, | |
16063 | uint32_t subtype) | |
16064 | { | |
16065 | struct lpfc_queue *hrq, *drq, *cq; | |
16066 | struct lpfc_mbx_rq_create_v2 *rq_create; | |
16067 | struct lpfc_dmabuf *dmabuf; | |
16068 | LPFC_MBOXQ_t *mbox; | |
16069 | int rc, length, alloclen, status = 0; | |
16070 | int cnt, idx, numrq, page_idx = 0; | |
16071 | uint32_t shdr_status, shdr_add_status; | |
16072 | union lpfc_sli4_cfg_shdr *shdr; | |
16073 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; | |
16074 | ||
16075 | numrq = phba->cfg_nvmet_mrq; | |
16076 | /* sanity check on array memory */ | |
16077 | if (!hrqp || !drqp || !cqp || !numrq) | |
16078 | return -ENODEV; | |
16079 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
16080 | hw_page_size = SLI4_PAGE_SIZE; | |
16081 | ||
16082 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16083 | if (!mbox) | |
16084 | return -ENOMEM; | |
16085 | ||
16086 | length = sizeof(struct lpfc_mbx_rq_create_v2); | |
16087 | length += ((2 * numrq * hrqp[0]->page_count) * | |
16088 | sizeof(struct dma_address)); | |
16089 | ||
16090 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16091 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, | |
16092 | LPFC_SLI4_MBX_NEMBED); | |
16093 | if (alloclen < length) { | |
16094 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16095 | "3099 Allocated DMA memory size (%d) is " | |
16096 | "less than the requested DMA memory size " | |
16097 | "(%d)\n", alloclen, length); | |
16098 | status = -ENOMEM; | |
16099 | goto out; | |
16100 | } | |
16101 | ||
16102 | ||
16103 | ||
16104 | rq_create = mbox->sge_array->addr[0]; | |
16105 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; | |
16106 | ||
16107 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); | |
16108 | cnt = 0; | |
16109 | ||
16110 | for (idx = 0; idx < numrq; idx++) { | |
16111 | hrq = hrqp[idx]; | |
16112 | drq = drqp[idx]; | |
16113 | cq = cqp[idx]; | |
16114 | ||
2d7dbc4c JS |
16115 | /* sanity check on queue memory */ |
16116 | if (!hrq || !drq || !cq) { | |
16117 | status = -ENODEV; | |
16118 | goto out; | |
16119 | } | |
16120 | ||
7aabe84b JS |
16121 | if (hrq->entry_count != drq->entry_count) { |
16122 | status = -EINVAL; | |
16123 | goto out; | |
16124 | } | |
16125 | ||
2d7dbc4c JS |
16126 | if (idx == 0) { |
16127 | bf_set(lpfc_mbx_rq_create_num_pages, | |
16128 | &rq_create->u.request, | |
16129 | hrq->page_count); | |
16130 | bf_set(lpfc_mbx_rq_create_rq_cnt, | |
16131 | &rq_create->u.request, (numrq * 2)); | |
16132 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, | |
16133 | 1); | |
16134 | bf_set(lpfc_rq_context_base_cq, | |
16135 | &rq_create->u.request.context, | |
16136 | cq->queue_id); | |
16137 | bf_set(lpfc_rq_context_data_size, | |
16138 | &rq_create->u.request.context, | |
3c603be9 | 16139 | LPFC_NVMET_DATA_BUF_SIZE); |
2d7dbc4c JS |
16140 | bf_set(lpfc_rq_context_hdr_size, |
16141 | &rq_create->u.request.context, | |
16142 | LPFC_HDR_BUF_SIZE); | |
16143 | bf_set(lpfc_rq_context_rqe_count_1, | |
16144 | &rq_create->u.request.context, | |
16145 | hrq->entry_count); | |
16146 | bf_set(lpfc_rq_context_rqe_size, | |
16147 | &rq_create->u.request.context, | |
16148 | LPFC_RQE_SIZE_8); | |
16149 | bf_set(lpfc_rq_context_page_size, | |
16150 | &rq_create->u.request.context, | |
16151 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
16152 | } | |
16153 | rc = 0; | |
16154 | list_for_each_entry(dmabuf, &hrq->page_list, list) { | |
16155 | memset(dmabuf->virt, 0, hw_page_size); | |
16156 | cnt = page_idx + dmabuf->buffer_tag; | |
16157 | rq_create->u.request.page[cnt].addr_lo = | |
16158 | putPaddrLow(dmabuf->phys); | |
16159 | rq_create->u.request.page[cnt].addr_hi = | |
16160 | putPaddrHigh(dmabuf->phys); | |
16161 | rc++; | |
16162 | } | |
16163 | page_idx += rc; | |
16164 | ||
16165 | rc = 0; | |
16166 | list_for_each_entry(dmabuf, &drq->page_list, list) { | |
16167 | memset(dmabuf->virt, 0, hw_page_size); | |
16168 | cnt = page_idx + dmabuf->buffer_tag; | |
16169 | rq_create->u.request.page[cnt].addr_lo = | |
16170 | putPaddrLow(dmabuf->phys); | |
16171 | rq_create->u.request.page[cnt].addr_hi = | |
16172 | putPaddrHigh(dmabuf->phys); | |
16173 | rc++; | |
16174 | } | |
16175 | page_idx += rc; | |
16176 | ||
16177 | hrq->db_format = LPFC_DB_RING_FORMAT; | |
16178 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; | |
16179 | hrq->type = LPFC_HRQ; | |
16180 | hrq->assoc_qid = cq->queue_id; | |
16181 | hrq->subtype = subtype; | |
16182 | hrq->host_index = 0; | |
16183 | hrq->hba_index = 0; | |
61f3d4bf | 16184 | hrq->entry_repost = LPFC_RQ_REPOST; |
2d7dbc4c JS |
16185 | |
16186 | drq->db_format = LPFC_DB_RING_FORMAT; | |
16187 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; | |
16188 | drq->type = LPFC_DRQ; | |
16189 | drq->assoc_qid = cq->queue_id; | |
16190 | drq->subtype = subtype; | |
16191 | drq->host_index = 0; | |
16192 | drq->hba_index = 0; | |
61f3d4bf | 16193 | drq->entry_repost = LPFC_RQ_REPOST; |
2d7dbc4c JS |
16194 | |
16195 | list_add_tail(&hrq->list, &cq->child_list); | |
16196 | list_add_tail(&drq->list, &cq->child_list); | |
16197 | } | |
16198 | ||
16199 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
16200 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16201 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16202 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16203 | if (shdr_status || shdr_add_status || rc) { | |
16204 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16205 | "3120 RQ_CREATE mailbox failed with " | |
16206 | "status x%x add_status x%x, mbx status x%x\n", | |
16207 | shdr_status, shdr_add_status, rc); | |
16208 | status = -ENXIO; | |
16209 | goto out; | |
16210 | } | |
16211 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
16212 | if (rc == 0xFFFF) { | |
16213 | status = -ENXIO; | |
16214 | goto out; | |
16215 | } | |
16216 | ||
16217 | /* Initialize all RQs with associated queue id */ | |
16218 | for (idx = 0; idx < numrq; idx++) { | |
16219 | hrq = hrqp[idx]; | |
16220 | hrq->queue_id = rc + (2 * idx); | |
16221 | drq = drqp[idx]; | |
16222 | drq->queue_id = rc + (2 * idx) + 1; | |
16223 | } | |
16224 | ||
16225 | out: | |
16226 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
16227 | return status; | |
16228 | } | |
16229 | ||
4f774513 JS |
16230 | /** |
16231 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
16232 | * @eq: The queue structure associated with the queue to destroy. | |
16233 | * | |
16234 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
16235 | * command, specific to the type of queue, to the HBA. | |
16236 | * | |
16237 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
16238 | * | |
16239 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 16240 | * command fails this function will return -ENXIO. |
4f774513 | 16241 | **/ |
a2fc4aef | 16242 | int |
4f774513 JS |
16243 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
16244 | { | |
16245 | LPFC_MBOXQ_t *mbox; | |
16246 | int rc, length, status = 0; | |
16247 | uint32_t shdr_status, shdr_add_status; | |
16248 | union lpfc_sli4_cfg_shdr *shdr; | |
16249 | ||
2e90f4b5 | 16250 | /* sanity check on queue memory */ |
4f774513 JS |
16251 | if (!eq) |
16252 | return -ENODEV; | |
16253 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
16254 | if (!mbox) | |
16255 | return -ENOMEM; | |
16256 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
16257 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16258 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
16259 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
16260 | length, LPFC_SLI4_MBX_EMBED); | |
16261 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
16262 | eq->queue_id); | |
16263 | mbox->vport = eq->phba->pport; | |
16264 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16265 | ||
16266 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
16267 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16268 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16269 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
16270 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16271 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16272 | if (shdr_status || shdr_add_status || rc) { | |
16273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16274 | "2505 EQ_DESTROY mailbox failed with " | |
16275 | "status x%x add_status x%x, mbx status x%x\n", | |
16276 | shdr_status, shdr_add_status, rc); | |
16277 | status = -ENXIO; | |
16278 | } | |
16279 | ||
16280 | /* Remove eq from any list */ | |
16281 | list_del_init(&eq->list); | |
8fa38513 | 16282 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
16283 | return status; |
16284 | } | |
16285 | ||
16286 | /** | |
16287 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
16288 | * @cq: The queue structure associated with the queue to destroy. | |
16289 | * | |
16290 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
16291 | * command, specific to the type of queue, to the HBA. | |
16292 | * | |
16293 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
16294 | * | |
16295 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 16296 | * command fails this function will return -ENXIO. |
4f774513 | 16297 | **/ |
a2fc4aef | 16298 | int |
4f774513 JS |
16299 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
16300 | { | |
16301 | LPFC_MBOXQ_t *mbox; | |
16302 | int rc, length, status = 0; | |
16303 | uint32_t shdr_status, shdr_add_status; | |
16304 | union lpfc_sli4_cfg_shdr *shdr; | |
16305 | ||
2e90f4b5 | 16306 | /* sanity check on queue memory */ |
4f774513 JS |
16307 | if (!cq) |
16308 | return -ENODEV; | |
16309 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
16310 | if (!mbox) | |
16311 | return -ENOMEM; | |
16312 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
16313 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16314 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
16315 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
16316 | length, LPFC_SLI4_MBX_EMBED); | |
16317 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
16318 | cq->queue_id); | |
16319 | mbox->vport = cq->phba->pport; | |
16320 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16321 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
16322 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16323 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16324 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
16325 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16326 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16327 | if (shdr_status || shdr_add_status || rc) { | |
16328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16329 | "2506 CQ_DESTROY mailbox failed with " | |
16330 | "status x%x add_status x%x, mbx status x%x\n", | |
16331 | shdr_status, shdr_add_status, rc); | |
16332 | status = -ENXIO; | |
16333 | } | |
16334 | /* Remove cq from any list */ | |
16335 | list_del_init(&cq->list); | |
8fa38513 | 16336 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
16337 | return status; |
16338 | } | |
16339 | ||
04c68496 JS |
16340 | /** |
16341 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
16342 | * @qm: The queue structure associated with the queue to destroy. | |
16343 | * | |
16344 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
16345 | * command, specific to the type of queue, to the HBA. | |
16346 | * | |
16347 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
16348 | * | |
16349 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 16350 | * command fails this function will return -ENXIO. |
04c68496 | 16351 | **/ |
a2fc4aef | 16352 | int |
04c68496 JS |
16353 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
16354 | { | |
16355 | LPFC_MBOXQ_t *mbox; | |
16356 | int rc, length, status = 0; | |
16357 | uint32_t shdr_status, shdr_add_status; | |
16358 | union lpfc_sli4_cfg_shdr *shdr; | |
16359 | ||
2e90f4b5 | 16360 | /* sanity check on queue memory */ |
04c68496 JS |
16361 | if (!mq) |
16362 | return -ENODEV; | |
16363 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
16364 | if (!mbox) | |
16365 | return -ENOMEM; | |
16366 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
16367 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16368 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
16369 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
16370 | length, LPFC_SLI4_MBX_EMBED); | |
16371 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
16372 | mq->queue_id); | |
16373 | mbox->vport = mq->phba->pport; | |
16374 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16375 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
16376 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16377 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16378 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
16379 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16380 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16381 | if (shdr_status || shdr_add_status || rc) { | |
16382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16383 | "2507 MQ_DESTROY mailbox failed with " | |
16384 | "status x%x add_status x%x, mbx status x%x\n", | |
16385 | shdr_status, shdr_add_status, rc); | |
16386 | status = -ENXIO; | |
16387 | } | |
16388 | /* Remove mq from any list */ | |
16389 | list_del_init(&mq->list); | |
8fa38513 | 16390 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
16391 | return status; |
16392 | } | |
16393 | ||
4f774513 JS |
16394 | /** |
16395 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
16396 | * @wq: The queue structure associated with the queue to destroy. | |
16397 | * | |
16398 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
16399 | * command, specific to the type of queue, to the HBA. | |
16400 | * | |
16401 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
16402 | * | |
16403 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 16404 | * command fails this function will return -ENXIO. |
4f774513 | 16405 | **/ |
a2fc4aef | 16406 | int |
4f774513 JS |
16407 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
16408 | { | |
16409 | LPFC_MBOXQ_t *mbox; | |
16410 | int rc, length, status = 0; | |
16411 | uint32_t shdr_status, shdr_add_status; | |
16412 | union lpfc_sli4_cfg_shdr *shdr; | |
16413 | ||
2e90f4b5 | 16414 | /* sanity check on queue memory */ |
4f774513 JS |
16415 | if (!wq) |
16416 | return -ENODEV; | |
16417 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
16418 | if (!mbox) | |
16419 | return -ENOMEM; | |
16420 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
16421 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
16422 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16423 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
16424 | length, LPFC_SLI4_MBX_EMBED); | |
16425 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
16426 | wq->queue_id); | |
16427 | mbox->vport = wq->phba->pport; | |
16428 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16429 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
16430 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16431 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
16432 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16433 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16434 | if (shdr_status || shdr_add_status || rc) { | |
16435 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16436 | "2508 WQ_DESTROY mailbox failed with " | |
16437 | "status x%x add_status x%x, mbx status x%x\n", | |
16438 | shdr_status, shdr_add_status, rc); | |
16439 | status = -ENXIO; | |
16440 | } | |
16441 | /* Remove wq from any list */ | |
16442 | list_del_init(&wq->list); | |
d1f525aa JS |
16443 | kfree(wq->pring); |
16444 | wq->pring = NULL; | |
8fa38513 | 16445 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
16446 | return status; |
16447 | } | |
16448 | ||
16449 | /** | |
16450 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
16451 | * @rq: The queue structure associated with the queue to destroy. | |
16452 | * | |
16453 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
16454 | * command, specific to the type of queue, to the HBA. | |
16455 | * | |
16456 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
16457 | * | |
16458 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 16459 | * command fails this function will return -ENXIO. |
4f774513 | 16460 | **/ |
a2fc4aef | 16461 | int |
4f774513 JS |
16462 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
16463 | struct lpfc_queue *drq) | |
16464 | { | |
16465 | LPFC_MBOXQ_t *mbox; | |
16466 | int rc, length, status = 0; | |
16467 | uint32_t shdr_status, shdr_add_status; | |
16468 | union lpfc_sli4_cfg_shdr *shdr; | |
16469 | ||
2e90f4b5 | 16470 | /* sanity check on queue memory */ |
4f774513 JS |
16471 | if (!hrq || !drq) |
16472 | return -ENODEV; | |
16473 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
16474 | if (!mbox) | |
16475 | return -ENOMEM; | |
16476 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 16477 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
16478 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
16479 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
16480 | length, LPFC_SLI4_MBX_EMBED); | |
16481 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
16482 | hrq->queue_id); | |
16483 | mbox->vport = hrq->phba->pport; | |
16484 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
16485 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
16486 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
16487 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16488 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
16489 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16490 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16491 | if (shdr_status || shdr_add_status || rc) { | |
16492 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16493 | "2509 RQ_DESTROY mailbox failed with " | |
16494 | "status x%x add_status x%x, mbx status x%x\n", | |
16495 | shdr_status, shdr_add_status, rc); | |
16496 | if (rc != MBX_TIMEOUT) | |
16497 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
16498 | return -ENXIO; | |
16499 | } | |
16500 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
16501 | drq->queue_id); | |
16502 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
16503 | shdr = (union lpfc_sli4_cfg_shdr *) | |
16504 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
16505 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16506 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16507 | if (shdr_status || shdr_add_status || rc) { | |
16508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16509 | "2510 RQ_DESTROY mailbox failed with " | |
16510 | "status x%x add_status x%x, mbx status x%x\n", | |
16511 | shdr_status, shdr_add_status, rc); | |
16512 | status = -ENXIO; | |
16513 | } | |
16514 | list_del_init(&hrq->list); | |
16515 | list_del_init(&drq->list); | |
8fa38513 | 16516 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
16517 | return status; |
16518 | } | |
16519 | ||
16520 | /** | |
16521 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
16522 | * @phba: The virtual port for which this call being executed. | |
16523 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
16524 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
16525 | * @xritag: the xritag that ties this io to the SGL pages. | |
16526 | * | |
16527 | * This routine will post the sgl pages for the IO that has the xritag | |
16528 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
16529 | * creation and persists for as long as the driver is loaded. | |
16530 | * if the caller has fewer than 256 scatter gather segments to map then | |
16531 | * pdma_phys_addr1 should be 0. | |
16532 | * If the caller needs to map more than 256 scatter gather segment then | |
16533 | * pdma_phys_addr1 should be a valid physical address. | |
16534 | * physical address for SGLs must be 64 byte aligned. | |
16535 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
16536 | * the second sgl can have between 1 and 256 entries. | |
16537 | * | |
16538 | * Return codes: | |
16539 | * 0 - Success | |
16540 | * -ENXIO, -ENOMEM - Failure | |
16541 | **/ | |
16542 | int | |
16543 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
16544 | dma_addr_t pdma_phys_addr0, | |
16545 | dma_addr_t pdma_phys_addr1, | |
16546 | uint16_t xritag) | |
16547 | { | |
16548 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
16549 | LPFC_MBOXQ_t *mbox; | |
16550 | int rc; | |
16551 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 16552 | uint32_t mbox_tmo; |
4f774513 JS |
16553 | union lpfc_sli4_cfg_shdr *shdr; |
16554 | ||
16555 | if (xritag == NO_XRI) { | |
16556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16557 | "0364 Invalid param:\n"); | |
16558 | return -EINVAL; | |
16559 | } | |
16560 | ||
16561 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16562 | if (!mbox) | |
16563 | return -ENOMEM; | |
16564 | ||
16565 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16566 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
16567 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 16568 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
16569 | |
16570 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
16571 | &mbox->u.mqe.un.post_sgl_pages; | |
16572 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
16573 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
16574 | ||
16575 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
16576 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
16577 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
16578 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
16579 | ||
16580 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
16581 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
16582 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
16583 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
16584 | if (!phba->sli4_hba.intr_enable) | |
16585 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 16586 | else { |
a183a15f | 16587 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
16588 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
16589 | } | |
4f774513 JS |
16590 | /* The IOCTL status is embedded in the mailbox subheader. */ |
16591 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
16592 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16593 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16594 | if (rc != MBX_TIMEOUT) | |
16595 | mempool_free(mbox, phba->mbox_mem_pool); | |
16596 | if (shdr_status || shdr_add_status || rc) { | |
16597 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16598 | "2511 POST_SGL mailbox failed with " | |
16599 | "status x%x add_status x%x, mbx status x%x\n", | |
16600 | shdr_status, shdr_add_status, rc); | |
4f774513 JS |
16601 | } |
16602 | return 0; | |
16603 | } | |
4f774513 | 16604 | |
6d368e53 | 16605 | /** |
88a2cfbb | 16606 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
16607 | * @phba: pointer to lpfc hba data structure. |
16608 | * | |
16609 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
16610 | * HBA consistent with the SLI-4 interface spec. This routine |
16611 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
16612 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 16613 | * |
88a2cfbb JS |
16614 | * Returns |
16615 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
16616 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
16617 | **/ | |
5d8b8167 | 16618 | static uint16_t |
6d368e53 JS |
16619 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
16620 | { | |
16621 | unsigned long xri; | |
16622 | ||
16623 | /* | |
16624 | * Fetch the next logical xri. Because this index is logical, | |
16625 | * the driver starts at 0 each time. | |
16626 | */ | |
16627 | spin_lock_irq(&phba->hbalock); | |
16628 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
16629 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
16630 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
16631 | spin_unlock_irq(&phba->hbalock); | |
16632 | return NO_XRI; | |
16633 | } else { | |
16634 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
16635 | phba->sli4_hba.max_cfg_param.xri_used++; | |
6d368e53 | 16636 | } |
6d368e53 JS |
16637 | spin_unlock_irq(&phba->hbalock); |
16638 | return xri; | |
16639 | } | |
16640 | ||
16641 | /** | |
16642 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
16643 | * @phba: pointer to lpfc hba data structure. | |
16644 | * | |
16645 | * This routine is invoked to release an xri to the pool of | |
16646 | * available rpis maintained by the driver. | |
16647 | **/ | |
5d8b8167 | 16648 | static void |
6d368e53 JS |
16649 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
16650 | { | |
16651 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
6d368e53 JS |
16652 | phba->sli4_hba.max_cfg_param.xri_used--; |
16653 | } | |
16654 | } | |
16655 | ||
16656 | /** | |
16657 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
16658 | * @phba: pointer to lpfc hba data structure. | |
16659 | * | |
16660 | * This routine is invoked to release an xri to the pool of | |
16661 | * available rpis maintained by the driver. | |
16662 | **/ | |
16663 | void | |
16664 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
16665 | { | |
16666 | spin_lock_irq(&phba->hbalock); | |
16667 | __lpfc_sli4_free_xri(phba, xri); | |
16668 | spin_unlock_irq(&phba->hbalock); | |
16669 | } | |
16670 | ||
4f774513 JS |
16671 | /** |
16672 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
16673 | * @phba: Pointer to HBA context object. | |
16674 | * | |
16675 | * This function gets an xritag for the iocb. If there is no unused xritag | |
16676 | * it will return 0xffff. | |
16677 | * The function returns the allocated xritag if successful, else returns zero. | |
16678 | * Zero is not a valid xritag. | |
16679 | * The caller is not required to hold any lock. | |
16680 | **/ | |
16681 | uint16_t | |
16682 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
16683 | { | |
6d368e53 | 16684 | uint16_t xri_index; |
4f774513 | 16685 | |
6d368e53 | 16686 | xri_index = lpfc_sli4_alloc_xri(phba); |
81378052 JS |
16687 | if (xri_index == NO_XRI) |
16688 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
16689 | "2004 Failed to allocate XRI.last XRITAG is %d" | |
16690 | " Max XRI is %d, Used XRI is %d\n", | |
16691 | xri_index, | |
16692 | phba->sli4_hba.max_cfg_param.max_xri, | |
16693 | phba->sli4_hba.max_cfg_param.xri_used); | |
16694 | return xri_index; | |
4f774513 JS |
16695 | } |
16696 | ||
16697 | /** | |
895427bd | 16698 | * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port. |
4f774513 | 16699 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 JS |
16700 | * @post_sgl_list: pointer to els sgl entry list. |
16701 | * @count: number of els sgl entries on the list. | |
4f774513 JS |
16702 | * |
16703 | * This routine is invoked to post a block of driver's sgl pages to the | |
16704 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
16705 | * is only called when the driver is loading and after all IO has been | |
16706 | * stopped. | |
16707 | **/ | |
8a9d2e80 | 16708 | static int |
895427bd | 16709 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
8a9d2e80 JS |
16710 | struct list_head *post_sgl_list, |
16711 | int post_cnt) | |
4f774513 | 16712 | { |
8a9d2e80 | 16713 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4f774513 JS |
16714 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
16715 | struct sgl_page_pairs *sgl_pg_pairs; | |
16716 | void *viraddr; | |
16717 | LPFC_MBOXQ_t *mbox; | |
16718 | uint32_t reqlen, alloclen, pg_pairs; | |
16719 | uint32_t mbox_tmo; | |
8a9d2e80 JS |
16720 | uint16_t xritag_start = 0; |
16721 | int rc = 0; | |
4f774513 JS |
16722 | uint32_t shdr_status, shdr_add_status; |
16723 | union lpfc_sli4_cfg_shdr *shdr; | |
16724 | ||
895427bd | 16725 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
4f774513 | 16726 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 16727 | if (reqlen > SLI4_PAGE_SIZE) { |
895427bd | 16728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4f774513 JS |
16729 | "2559 Block sgl registration required DMA " |
16730 | "size (%d) great than a page\n", reqlen); | |
16731 | return -ENOMEM; | |
16732 | } | |
895427bd | 16733 | |
4f774513 | 16734 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
6d368e53 | 16735 | if (!mbox) |
4f774513 | 16736 | return -ENOMEM; |
4f774513 JS |
16737 | |
16738 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
16739 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16740 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
16741 | LPFC_SLI4_MBX_NEMBED); | |
16742 | ||
16743 | if (alloclen < reqlen) { | |
16744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16745 | "0285 Allocated DMA memory size (%d) is " | |
16746 | "less than the requested DMA memory " | |
16747 | "size (%d)\n", alloclen, reqlen); | |
16748 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
16749 | return -ENOMEM; | |
16750 | } | |
4f774513 | 16751 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 16752 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
16753 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
16754 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
16755 | ||
8a9d2e80 JS |
16756 | pg_pairs = 0; |
16757 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { | |
4f774513 JS |
16758 | /* Set up the sge entry */ |
16759 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
16760 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
16761 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
16762 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
16763 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
16764 | cpu_to_le32(putPaddrLow(0)); | |
16765 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
16766 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 16767 | |
4f774513 JS |
16768 | /* Keep the first xritag on the list */ |
16769 | if (pg_pairs == 0) | |
16770 | xritag_start = sglq_entry->sli4_xritag; | |
16771 | sgl_pg_pairs++; | |
8a9d2e80 | 16772 | pg_pairs++; |
4f774513 | 16773 | } |
6d368e53 JS |
16774 | |
16775 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 16776 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
895427bd | 16777 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
4f774513 | 16778 | sgl->word0 = cpu_to_le32(sgl->word0); |
895427bd | 16779 | |
4f774513 JS |
16780 | if (!phba->sli4_hba.intr_enable) |
16781 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
16782 | else { | |
a183a15f | 16783 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
16784 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
16785 | } | |
16786 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
16787 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16788 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16789 | if (rc != MBX_TIMEOUT) | |
16790 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
16791 | if (shdr_status || shdr_add_status || rc) { | |
16792 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16793 | "2513 POST_SGL_BLOCK mailbox command failed " | |
16794 | "status x%x add_status x%x mbx status x%x\n", | |
16795 | shdr_status, shdr_add_status, rc); | |
16796 | rc = -ENXIO; | |
16797 | } | |
16798 | return rc; | |
16799 | } | |
16800 | ||
16801 | /** | |
16802 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
16803 | * @phba: pointer to lpfc hba data structure. | |
16804 | * @sblist: pointer to scsi buffer list. | |
16805 | * @count: number of scsi buffers on the list. | |
16806 | * | |
16807 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
16808 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
16809 | * No Lock is held. | |
16810 | * | |
16811 | **/ | |
16812 | int | |
8a9d2e80 JS |
16813 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
16814 | struct list_head *sblist, | |
16815 | int count) | |
4f774513 JS |
16816 | { |
16817 | struct lpfc_scsi_buf *psb; | |
16818 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
16819 | struct sgl_page_pairs *sgl_pg_pairs; | |
16820 | void *viraddr; | |
16821 | LPFC_MBOXQ_t *mbox; | |
16822 | uint32_t reqlen, alloclen, pg_pairs; | |
16823 | uint32_t mbox_tmo; | |
16824 | uint16_t xritag_start = 0; | |
16825 | int rc = 0; | |
16826 | uint32_t shdr_status, shdr_add_status; | |
16827 | dma_addr_t pdma_phys_bpl1; | |
16828 | union lpfc_sli4_cfg_shdr *shdr; | |
16829 | ||
16830 | /* Calculate the requested length of the dma memory */ | |
8a9d2e80 | 16831 | reqlen = count * sizeof(struct sgl_page_pairs) + |
4f774513 | 16832 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 16833 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
16834 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
16835 | "0217 Block sgl registration required DMA " | |
16836 | "size (%d) great than a page\n", reqlen); | |
16837 | return -ENOMEM; | |
16838 | } | |
16839 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
16840 | if (!mbox) { | |
16841 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16842 | "0283 Failed to allocate mbox cmd memory\n"); | |
16843 | return -ENOMEM; | |
16844 | } | |
16845 | ||
16846 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
16847 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
16848 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
16849 | LPFC_SLI4_MBX_NEMBED); | |
16850 | ||
16851 | if (alloclen < reqlen) { | |
16852 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
16853 | "2561 Allocated DMA memory size (%d) is " | |
16854 | "less than the requested DMA memory " | |
16855 | "size (%d)\n", alloclen, reqlen); | |
16856 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
16857 | return -ENOMEM; | |
16858 | } | |
6d368e53 | 16859 | |
4f774513 | 16860 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
16861 | viraddr = mbox->sge_array->addr[0]; |
16862 | ||
16863 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
16864 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
16865 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
16866 | ||
16867 | pg_pairs = 0; | |
16868 | list_for_each_entry(psb, sblist, list) { | |
16869 | /* Set up the sge entry */ | |
16870 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
16871 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
16872 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
16873 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
16874 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
16875 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
16876 | else | |
16877 | pdma_phys_bpl1 = 0; | |
16878 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
16879 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
16880 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
16881 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
16882 | /* Keep the first xritag on the list */ | |
16883 | if (pg_pairs == 0) | |
16884 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
16885 | sgl_pg_pairs++; | |
16886 | pg_pairs++; | |
16887 | } | |
16888 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
16889 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
16890 | /* Perform endian conversion if necessary */ | |
16891 | sgl->word0 = cpu_to_le32(sgl->word0); | |
16892 | ||
16893 | if (!phba->sli4_hba.intr_enable) | |
16894 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
16895 | else { | |
a183a15f | 16896 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
16897 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
16898 | } | |
16899 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
16900 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
16901 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
16902 | if (rc != MBX_TIMEOUT) | |
16903 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
16904 | if (shdr_status || shdr_add_status || rc) { | |
16905 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
16906 | "2564 POST_SGL_BLOCK mailbox command failed " | |
16907 | "status x%x add_status x%x mbx status x%x\n", | |
16908 | shdr_status, shdr_add_status, rc); | |
16909 | rc = -ENXIO; | |
16910 | } | |
16911 | return rc; | |
16912 | } | |
16913 | ||
16914 | /** | |
16915 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
16916 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
16917 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
16918 | * | |
16919 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
16920 | * valid type of frame that the LPFC driver will handle. This function will | |
16921 | * return a zero if the frame is a valid frame or a non zero value when the | |
16922 | * frame does not pass the check. | |
16923 | **/ | |
16924 | static int | |
16925 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
16926 | { | |
474ffb74 | 16927 | /* make rctl_names static to save stack space */ |
4f774513 | 16928 | struct fc_vft_header *fc_vft_hdr; |
546fc854 | 16929 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 | 16930 | |
ae9e28f3 JS |
16931 | #define FC_RCTL_MDS_DIAGS 0xF4 |
16932 | ||
4f774513 JS |
16933 | switch (fc_hdr->fh_r_ctl) { |
16934 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
16935 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
16936 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
16937 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
16938 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
16939 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
16940 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
16941 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
16942 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
16943 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
16944 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
16945 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
16946 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
16947 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
16948 | case FC_RCTL_BA_RMC: /* remove connection */ | |
16949 | case FC_RCTL_BA_ACC: /* basic accept */ | |
16950 | case FC_RCTL_BA_RJT: /* basic reject */ | |
16951 | case FC_RCTL_BA_PRMT: | |
16952 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
16953 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
16954 | case FC_RCTL_P_RJT: /* port reject */ | |
16955 | case FC_RCTL_F_RJT: /* fabric reject */ | |
16956 | case FC_RCTL_P_BSY: /* port busy */ | |
16957 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
16958 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
16959 | case FC_RCTL_LCR: /* link credit reset */ | |
ae9e28f3 | 16960 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
4f774513 JS |
16961 | case FC_RCTL_END: /* end */ |
16962 | break; | |
16963 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
16964 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
16965 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
16966 | return lpfc_fc_frame_check(phba, fc_hdr); | |
16967 | default: | |
16968 | goto drop; | |
16969 | } | |
ae9e28f3 JS |
16970 | |
16971 | #define FC_TYPE_VENDOR_UNIQUE 0xFF | |
16972 | ||
4f774513 JS |
16973 | switch (fc_hdr->fh_type) { |
16974 | case FC_TYPE_BLS: | |
16975 | case FC_TYPE_ELS: | |
16976 | case FC_TYPE_FCP: | |
16977 | case FC_TYPE_CT: | |
895427bd | 16978 | case FC_TYPE_NVME: |
ae9e28f3 | 16979 | case FC_TYPE_VENDOR_UNIQUE: |
4f774513 JS |
16980 | break; |
16981 | case FC_TYPE_IP: | |
16982 | case FC_TYPE_ILS: | |
16983 | default: | |
16984 | goto drop; | |
16985 | } | |
546fc854 | 16986 | |
4f774513 | 16987 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
78e1d200 | 16988 | "2538 Received frame rctl:x%x, type:x%x, " |
88f43a08 | 16989 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
78e1d200 JS |
16990 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
16991 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
16992 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
16993 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), | |
16994 | be32_to_cpu(header[6])); | |
4f774513 JS |
16995 | return 0; |
16996 | drop: | |
16997 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
78e1d200 JS |
16998 | "2539 Dropped frame rctl:x%x type:x%x\n", |
16999 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
4f774513 JS |
17000 | return 1; |
17001 | } | |
17002 | ||
17003 | /** | |
17004 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
17005 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
17006 | * | |
17007 | * This function processes the FC header to retrieve the VFI from the VF | |
17008 | * header, if one exists. This function will return the VFI if one exists | |
17009 | * or 0 if no VSAN Header exists. | |
17010 | **/ | |
17011 | static uint32_t | |
17012 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
17013 | { | |
17014 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
17015 | ||
17016 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
17017 | return 0; | |
17018 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
17019 | } | |
17020 | ||
17021 | /** | |
17022 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
17023 | * @phba: Pointer to the HBA structure to search for the vport on | |
17024 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
17025 | * @fcfi: The FC Fabric ID that the frame came from | |
17026 | * | |
17027 | * This function searches the @phba for a vport that matches the content of the | |
17028 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
17029 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
17030 | * returns the matching vport pointer or NULL if unable to match frame to a | |
17031 | * vport. | |
17032 | **/ | |
17033 | static struct lpfc_vport * | |
17034 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
895427bd | 17035 | uint16_t fcfi, uint32_t did) |
4f774513 JS |
17036 | { |
17037 | struct lpfc_vport **vports; | |
17038 | struct lpfc_vport *vport = NULL; | |
17039 | int i; | |
939723a4 | 17040 | |
bf08611b JS |
17041 | if (did == Fabric_DID) |
17042 | return phba->pport; | |
939723a4 JS |
17043 | if ((phba->pport->fc_flag & FC_PT2PT) && |
17044 | !(phba->link_state == LPFC_HBA_READY)) | |
17045 | return phba->pport; | |
17046 | ||
4f774513 | 17047 | vports = lpfc_create_vport_work_array(phba); |
895427bd | 17048 | if (vports != NULL) { |
4f774513 JS |
17049 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
17050 | if (phba->fcf.fcfi == fcfi && | |
17051 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
17052 | vports[i]->fc_myDID == did) { | |
17053 | vport = vports[i]; | |
17054 | break; | |
17055 | } | |
17056 | } | |
895427bd | 17057 | } |
4f774513 JS |
17058 | lpfc_destroy_vport_work_array(phba, vports); |
17059 | return vport; | |
17060 | } | |
17061 | ||
45ed1190 JS |
17062 | /** |
17063 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
17064 | * @vport: The vport to work on. | |
17065 | * | |
17066 | * This function updates the receive sequence time stamp for this vport. The | |
17067 | * receive sequence time stamp indicates the time that the last frame of the | |
17068 | * the sequence that has been idle for the longest amount of time was received. | |
17069 | * the driver uses this time stamp to indicate if any received sequences have | |
17070 | * timed out. | |
17071 | **/ | |
5d8b8167 | 17072 | static void |
45ed1190 JS |
17073 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
17074 | { | |
17075 | struct lpfc_dmabuf *h_buf; | |
17076 | struct hbq_dmabuf *dmabuf = NULL; | |
17077 | ||
17078 | /* get the oldest sequence on the rcv list */ | |
17079 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
17080 | struct lpfc_dmabuf, list); | |
17081 | if (!h_buf) | |
17082 | return; | |
17083 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
17084 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
17085 | } | |
17086 | ||
17087 | /** | |
17088 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
17089 | * @vport: The vport that the received sequences were sent to. | |
17090 | * | |
17091 | * This function cleans up all outstanding received sequences. This is called | |
17092 | * by the driver when a link event or user action invalidates all the received | |
17093 | * sequences. | |
17094 | **/ | |
17095 | void | |
17096 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
17097 | { | |
17098 | struct lpfc_dmabuf *h_buf, *hnext; | |
17099 | struct lpfc_dmabuf *d_buf, *dnext; | |
17100 | struct hbq_dmabuf *dmabuf = NULL; | |
17101 | ||
17102 | /* start with the oldest sequence on the rcv list */ | |
17103 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
17104 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
17105 | list_del_init(&dmabuf->hbuf.list); | |
17106 | list_for_each_entry_safe(d_buf, dnext, | |
17107 | &dmabuf->dbuf.list, list) { | |
17108 | list_del_init(&d_buf->list); | |
17109 | lpfc_in_buf_free(vport->phba, d_buf); | |
17110 | } | |
17111 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
17112 | } | |
17113 | } | |
17114 | ||
17115 | /** | |
17116 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
17117 | * @vport: The vport that the received sequences were sent to. | |
17118 | * | |
17119 | * This function determines whether any received sequences have timed out by | |
17120 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
17121 | * indicates that there is at least one timed out sequence this routine will | |
17122 | * go through the received sequences one at a time from most inactive to most | |
17123 | * active to determine which ones need to be cleaned up. Once it has determined | |
17124 | * that a sequence needs to be cleaned up it will simply free up the resources | |
17125 | * without sending an abort. | |
17126 | **/ | |
17127 | void | |
17128 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
17129 | { | |
17130 | struct lpfc_dmabuf *h_buf, *hnext; | |
17131 | struct lpfc_dmabuf *d_buf, *dnext; | |
17132 | struct hbq_dmabuf *dmabuf = NULL; | |
17133 | unsigned long timeout; | |
17134 | int abort_count = 0; | |
17135 | ||
17136 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
17137 | vport->rcv_buffer_time_stamp); | |
17138 | if (list_empty(&vport->rcv_buffer_list) || | |
17139 | time_before(jiffies, timeout)) | |
17140 | return; | |
17141 | /* start with the oldest sequence on the rcv list */ | |
17142 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
17143 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
17144 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
17145 | dmabuf->time_stamp); | |
17146 | if (time_before(jiffies, timeout)) | |
17147 | break; | |
17148 | abort_count++; | |
17149 | list_del_init(&dmabuf->hbuf.list); | |
17150 | list_for_each_entry_safe(d_buf, dnext, | |
17151 | &dmabuf->dbuf.list, list) { | |
17152 | list_del_init(&d_buf->list); | |
17153 | lpfc_in_buf_free(vport->phba, d_buf); | |
17154 | } | |
17155 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
17156 | } | |
17157 | if (abort_count) | |
17158 | lpfc_update_rcv_time_stamp(vport); | |
17159 | } | |
17160 | ||
4f774513 JS |
17161 | /** |
17162 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
17163 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
17164 | * | |
17165 | * This function searches through the existing incomplete sequences that have | |
17166 | * been sent to this @vport. If the frame matches one of the incomplete | |
17167 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
17168 | * make up that sequence. If no sequence is found that matches this frame then | |
17169 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
17170 | * This function returns a pointer to the first dmabuf in the sequence list that | |
17171 | * the frame was linked to. | |
17172 | **/ | |
17173 | static struct hbq_dmabuf * | |
17174 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
17175 | { | |
17176 | struct fc_frame_header *new_hdr; | |
17177 | struct fc_frame_header *temp_hdr; | |
17178 | struct lpfc_dmabuf *d_buf; | |
17179 | struct lpfc_dmabuf *h_buf; | |
17180 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
17181 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
4360ca9c | 17182 | uint8_t found = 0; |
4f774513 | 17183 | |
4d9ab994 | 17184 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 17185 | dmabuf->time_stamp = jiffies; |
4f774513 | 17186 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
4360ca9c | 17187 | |
4f774513 JS |
17188 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
17189 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
17190 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
17191 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
17192 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
17193 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
17194 | continue; | |
17195 | /* found a pending sequence that matches this frame */ | |
17196 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
17197 | break; | |
17198 | } | |
17199 | if (!seq_dmabuf) { | |
17200 | /* | |
17201 | * This indicates first frame received for this sequence. | |
17202 | * Queue the buffer on the vport's rcv_buffer_list. | |
17203 | */ | |
17204 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 17205 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
17206 | return dmabuf; |
17207 | } | |
17208 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
17209 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
17210 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
17211 | list_del_init(&seq_dmabuf->hbuf.list); |
17212 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
17213 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 17214 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
17215 | return dmabuf; |
17216 | } | |
45ed1190 JS |
17217 | /* move this sequence to the tail to indicate a young sequence */ |
17218 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
17219 | seq_dmabuf->time_stamp = jiffies; | |
17220 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
17221 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
17222 | temp_hdr = dmabuf->hbuf.virt; | |
17223 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
17224 | return seq_dmabuf; | |
17225 | } | |
4f774513 | 17226 | /* find the correct place in the sequence to insert this frame */ |
4360ca9c JS |
17227 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
17228 | while (!found) { | |
4f774513 JS |
17229 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
17230 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
17231 | /* | |
17232 | * If the frame's sequence count is greater than the frame on | |
17233 | * the list then insert the frame right after this frame | |
17234 | */ | |
eeead811 JS |
17235 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
17236 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 | 17237 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
4360ca9c JS |
17238 | found = 1; |
17239 | break; | |
4f774513 | 17240 | } |
4360ca9c JS |
17241 | |
17242 | if (&d_buf->list == &seq_dmabuf->dbuf.list) | |
17243 | break; | |
17244 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); | |
4f774513 | 17245 | } |
4360ca9c JS |
17246 | |
17247 | if (found) | |
17248 | return seq_dmabuf; | |
4f774513 JS |
17249 | return NULL; |
17250 | } | |
17251 | ||
6669f9bb JS |
17252 | /** |
17253 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
17254 | * @vport: pointer to a vitural port | |
17255 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
17256 | * | |
17257 | * This function tries to abort from the partially assembed sequence, described | |
17258 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
17259 | * partially assembled sequence held by the driver. If so, it shall free up all | |
17260 | * the frames from the partially assembled sequence. | |
17261 | * | |
17262 | * Return | |
17263 | * true -- if there is matching partially assembled sequence present and all | |
17264 | * the frames freed with the sequence; | |
17265 | * false -- if there is no matching partially assembled sequence present so | |
17266 | * nothing got aborted in the lower layer driver | |
17267 | **/ | |
17268 | static bool | |
17269 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
17270 | struct hbq_dmabuf *dmabuf) | |
17271 | { | |
17272 | struct fc_frame_header *new_hdr; | |
17273 | struct fc_frame_header *temp_hdr; | |
17274 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
17275 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
17276 | ||
17277 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
17278 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
17279 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
17280 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
17281 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
17282 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
17283 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
17284 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
17285 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
17286 | continue; | |
17287 | /* found a pending sequence that matches this frame */ | |
17288 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
17289 | break; | |
17290 | } | |
17291 | ||
17292 | /* Free up all the frames from the partially assembled sequence */ | |
17293 | if (seq_dmabuf) { | |
17294 | list_for_each_entry_safe(d_buf, n_buf, | |
17295 | &seq_dmabuf->dbuf.list, list) { | |
17296 | list_del_init(&d_buf->list); | |
17297 | lpfc_in_buf_free(vport->phba, d_buf); | |
17298 | } | |
17299 | return true; | |
17300 | } | |
17301 | return false; | |
17302 | } | |
17303 | ||
6dd9e31c JS |
17304 | /** |
17305 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp | |
17306 | * @vport: pointer to a vitural port | |
17307 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
17308 | * | |
17309 | * This function tries to abort from the assembed sequence from upper level | |
17310 | * protocol, described by the information from basic abbort @dmabuf. It | |
17311 | * checks to see whether such pending context exists at upper level protocol. | |
17312 | * If so, it shall clean up the pending context. | |
17313 | * | |
17314 | * Return | |
17315 | * true -- if there is matching pending context of the sequence cleaned | |
17316 | * at ulp; | |
17317 | * false -- if there is no matching pending context of the sequence present | |
17318 | * at ulp. | |
17319 | **/ | |
17320 | static bool | |
17321 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
17322 | { | |
17323 | struct lpfc_hba *phba = vport->phba; | |
17324 | int handled; | |
17325 | ||
17326 | /* Accepting abort at ulp with SLI4 only */ | |
17327 | if (phba->sli_rev < LPFC_SLI_REV4) | |
17328 | return false; | |
17329 | ||
17330 | /* Register all caring upper level protocols to attend abort */ | |
17331 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); | |
17332 | if (handled) | |
17333 | return true; | |
17334 | ||
17335 | return false; | |
17336 | } | |
17337 | ||
6669f9bb | 17338 | /** |
546fc854 | 17339 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
17340 | * @phba: Pointer to HBA context object. |
17341 | * @cmd_iocbq: pointer to the command iocbq structure. | |
17342 | * @rsp_iocbq: pointer to the response iocbq structure. | |
17343 | * | |
546fc854 | 17344 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
17345 | * event. It properly releases the memory allocated to the sequence abort |
17346 | * accept iocb. | |
17347 | **/ | |
17348 | static void | |
546fc854 | 17349 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
17350 | struct lpfc_iocbq *cmd_iocbq, |
17351 | struct lpfc_iocbq *rsp_iocbq) | |
17352 | { | |
6dd9e31c JS |
17353 | struct lpfc_nodelist *ndlp; |
17354 | ||
17355 | if (cmd_iocbq) { | |
17356 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; | |
17357 | lpfc_nlp_put(ndlp); | |
17358 | lpfc_nlp_not_used(ndlp); | |
6669f9bb | 17359 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
6dd9e31c | 17360 | } |
6b5151fd JS |
17361 | |
17362 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ | |
17363 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) | |
17364 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
17365 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", | |
17366 | rsp_iocbq->iocb.ulpStatus, | |
17367 | rsp_iocbq->iocb.un.ulpWord[4]); | |
6669f9bb JS |
17368 | } |
17369 | ||
6d368e53 JS |
17370 | /** |
17371 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
17372 | * @phba: Pointer to HBA context object. | |
17373 | * @xri: xri id in transaction. | |
17374 | * | |
17375 | * This function validates the xri maps to the known range of XRIs allocated an | |
17376 | * used by the driver. | |
17377 | **/ | |
7851fe2c | 17378 | uint16_t |
6d368e53 JS |
17379 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
17380 | uint16_t xri) | |
17381 | { | |
a2fc4aef | 17382 | uint16_t i; |
6d368e53 JS |
17383 | |
17384 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
17385 | if (xri == phba->sli4_hba.xri_ids[i]) | |
17386 | return i; | |
17387 | } | |
17388 | return NO_XRI; | |
17389 | } | |
17390 | ||
6669f9bb | 17391 | /** |
546fc854 | 17392 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
17393 | * @phba: Pointer to HBA context object. |
17394 | * @fc_hdr: pointer to a FC frame header. | |
17395 | * | |
546fc854 | 17396 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
17397 | * event after aborting the sequence handling. |
17398 | **/ | |
86c67379 | 17399 | void |
6dd9e31c JS |
17400 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
17401 | struct fc_frame_header *fc_hdr, bool aborted) | |
6669f9bb | 17402 | { |
6dd9e31c | 17403 | struct lpfc_hba *phba = vport->phba; |
6669f9bb JS |
17404 | struct lpfc_iocbq *ctiocb = NULL; |
17405 | struct lpfc_nodelist *ndlp; | |
ee0f4fe1 | 17406 | uint16_t oxid, rxid, xri, lxri; |
5ffc266e | 17407 | uint32_t sid, fctl; |
6669f9bb | 17408 | IOCB_t *icmd; |
546fc854 | 17409 | int rc; |
6669f9bb JS |
17410 | |
17411 | if (!lpfc_is_link_up(phba)) | |
17412 | return; | |
17413 | ||
17414 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
17415 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 17416 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb | 17417 | |
6dd9e31c | 17418 | ndlp = lpfc_findnode_did(vport, sid); |
6669f9bb | 17419 | if (!ndlp) { |
9d3d340d | 17420 | ndlp = lpfc_nlp_init(vport, sid); |
6dd9e31c JS |
17421 | if (!ndlp) { |
17422 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
17423 | "1268 Failed to allocate ndlp for " | |
17424 | "oxid:x%x SID:x%x\n", oxid, sid); | |
17425 | return; | |
17426 | } | |
6dd9e31c JS |
17427 | /* Put ndlp onto pport node list */ |
17428 | lpfc_enqueue_node(vport, ndlp); | |
17429 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
17430 | /* re-setup ndlp without removing from node list */ | |
17431 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
17432 | if (!ndlp) { | |
17433 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, | |
17434 | "3275 Failed to active ndlp found " | |
17435 | "for oxid:x%x SID:x%x\n", oxid, sid); | |
17436 | return; | |
17437 | } | |
6669f9bb JS |
17438 | } |
17439 | ||
546fc854 | 17440 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
17441 | ctiocb = lpfc_sli_get_iocbq(phba); |
17442 | if (!ctiocb) | |
17443 | return; | |
17444 | ||
5ffc266e JS |
17445 | /* Extract the F_CTL field from FC_HDR */ |
17446 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
17447 | ||
6669f9bb | 17448 | icmd = &ctiocb->iocb; |
6669f9bb | 17449 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 17450 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
17451 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
17452 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
17453 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
17454 | ||
17455 | /* Fill in the rest of iocb fields */ | |
17456 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
17457 | icmd->ulpBdeCount = 0; | |
17458 | icmd->ulpLe = 1; | |
17459 | icmd->ulpClass = CLASS3; | |
6d368e53 | 17460 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
6dd9e31c | 17461 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
6669f9bb | 17462 | |
6669f9bb JS |
17463 | ctiocb->iocb_cmpl = NULL; |
17464 | ctiocb->vport = phba->pport; | |
546fc854 | 17465 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 17466 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
17467 | ctiocb->sli4_xritag = NO_XRI; |
17468 | ||
ee0f4fe1 JS |
17469 | if (fctl & FC_FC_EX_CTX) |
17470 | /* Exchange responder sent the abort so we | |
17471 | * own the oxid. | |
17472 | */ | |
17473 | xri = oxid; | |
17474 | else | |
17475 | xri = rxid; | |
17476 | lxri = lpfc_sli4_xri_inrange(phba, xri); | |
17477 | if (lxri != NO_XRI) | |
17478 | lpfc_set_rrq_active(phba, ndlp, lxri, | |
17479 | (xri == oxid) ? rxid : oxid, 0); | |
6dd9e31c JS |
17480 | /* For BA_ABTS from exchange responder, if the logical xri with |
17481 | * the oxid maps to the FCP XRI range, the port no longer has | |
17482 | * that exchange context, send a BLS_RJT. Override the IOCB for | |
17483 | * a BA_RJT. | |
17484 | */ | |
17485 | if ((fctl & FC_FC_EX_CTX) && | |
895427bd | 17486 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
6dd9e31c JS |
17487 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
17488 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
17489 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
17490 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
17491 | } | |
17492 | ||
17493 | /* If BA_ABTS failed to abort a partially assembled receive sequence, | |
17494 | * the driver no longer has that exchange, send a BLS_RJT. Override | |
17495 | * the IOCB for a BA_RJT. | |
546fc854 | 17496 | */ |
6dd9e31c | 17497 | if (aborted == false) { |
546fc854 JS |
17498 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
17499 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
17500 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
17501 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
17502 | } | |
6669f9bb | 17503 | |
5ffc266e JS |
17504 | if (fctl & FC_FC_EX_CTX) { |
17505 | /* ABTS sent by responder to CT exchange, construction | |
17506 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
17507 | * field and RX_ID from ABTS for RX_ID field. | |
17508 | */ | |
546fc854 | 17509 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
5ffc266e JS |
17510 | } else { |
17511 | /* ABTS sent by initiator to CT exchange, construction | |
17512 | * of BA_ACC will need to allocate a new XRI as for the | |
f09c3acc | 17513 | * XRI_TAG field. |
5ffc266e | 17514 | */ |
546fc854 | 17515 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
5ffc266e | 17516 | } |
f09c3acc | 17517 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
546fc854 | 17518 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 17519 | |
546fc854 | 17520 | /* Xmit CT abts response on exchange <xid> */ |
6dd9e31c JS |
17521 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
17522 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", | |
17523 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
546fc854 JS |
17524 | |
17525 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
17526 | if (rc == IOCB_ERROR) { | |
6dd9e31c JS |
17527 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
17528 | "2925 Failed to issue CT ABTS RSP x%x on " | |
17529 | "xri x%x, Data x%x\n", | |
17530 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
17531 | phba->link_state); | |
17532 | lpfc_nlp_put(ndlp); | |
17533 | ctiocb->context1 = NULL; | |
546fc854 JS |
17534 | lpfc_sli_release_iocbq(phba, ctiocb); |
17535 | } | |
6669f9bb JS |
17536 | } |
17537 | ||
17538 | /** | |
17539 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
17540 | * @vport: Pointer to the vport on which this sequence was received | |
17541 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
17542 | * | |
17543 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
17544 | * receive sequence is only partially assembed by the driver, it shall abort | |
17545 | * the partially assembled frames for the sequence. Otherwise, if the | |
17546 | * unsolicited receive sequence has been completely assembled and passed to | |
17547 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
17548 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
17549 | * accept to accept the abort. | |
17550 | **/ | |
5d8b8167 | 17551 | static void |
6669f9bb JS |
17552 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
17553 | struct hbq_dmabuf *dmabuf) | |
17554 | { | |
17555 | struct lpfc_hba *phba = vport->phba; | |
17556 | struct fc_frame_header fc_hdr; | |
5ffc266e | 17557 | uint32_t fctl; |
6dd9e31c | 17558 | bool aborted; |
6669f9bb | 17559 | |
6669f9bb JS |
17560 | /* Make a copy of fc_hdr before the dmabuf being released */ |
17561 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 17562 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 17563 | |
5ffc266e | 17564 | if (fctl & FC_FC_EX_CTX) { |
6dd9e31c JS |
17565 | /* ABTS by responder to exchange, no cleanup needed */ |
17566 | aborted = true; | |
5ffc266e | 17567 | } else { |
6dd9e31c JS |
17568 | /* ABTS by initiator to exchange, need to do cleanup */ |
17569 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
17570 | if (aborted == false) | |
17571 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); | |
5ffc266e | 17572 | } |
6dd9e31c JS |
17573 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
17574 | ||
86c67379 JS |
17575 | if (phba->nvmet_support) { |
17576 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); | |
17577 | return; | |
17578 | } | |
17579 | ||
6dd9e31c JS |
17580 | /* Respond with BA_ACC or BA_RJT accordingly */ |
17581 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); | |
6669f9bb JS |
17582 | } |
17583 | ||
4f774513 JS |
17584 | /** |
17585 | * lpfc_seq_complete - Indicates if a sequence is complete | |
17586 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
17587 | * | |
17588 | * This function checks the sequence, starting with the frame described by | |
17589 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
17590 | * the frames associated with this sequence are linked to the @dmabuf using the | |
17591 | * dbuf list. This function looks for two major things. 1) That the first frame | |
17592 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
17593 | * set. 3) That there are no holes in the sequence count. The function will | |
17594 | * return 1 when the sequence is complete, otherwise it will return 0. | |
17595 | **/ | |
17596 | static int | |
17597 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
17598 | { | |
17599 | struct fc_frame_header *hdr; | |
17600 | struct lpfc_dmabuf *d_buf; | |
17601 | struct hbq_dmabuf *seq_dmabuf; | |
17602 | uint32_t fctl; | |
17603 | int seq_count = 0; | |
17604 | ||
17605 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
17606 | /* make sure first fame of sequence has a sequence count of zero */ | |
17607 | if (hdr->fh_seq_cnt != seq_count) | |
17608 | return 0; | |
17609 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
17610 | hdr->fh_f_ctl[1] << 8 | | |
17611 | hdr->fh_f_ctl[2]); | |
17612 | /* If last frame of sequence we can return success. */ | |
17613 | if (fctl & FC_FC_END_SEQ) | |
17614 | return 1; | |
17615 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
17616 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
17617 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
17618 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 17619 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
17620 | return 0; |
17621 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
17622 | hdr->fh_f_ctl[1] << 8 | | |
17623 | hdr->fh_f_ctl[2]); | |
17624 | /* If last frame of sequence we can return success. */ | |
17625 | if (fctl & FC_FC_END_SEQ) | |
17626 | return 1; | |
17627 | } | |
17628 | return 0; | |
17629 | } | |
17630 | ||
17631 | /** | |
17632 | * lpfc_prep_seq - Prep sequence for ULP processing | |
17633 | * @vport: Pointer to the vport on which this sequence was received | |
17634 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
17635 | * | |
17636 | * This function takes a sequence, described by a list of frames, and creates | |
17637 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
17638 | * used to issue to the generic unsolicited sequence handler. This routine | |
17639 | * returns a pointer to the first iocbq in the list. If the function is unable | |
17640 | * to allocate an iocbq then it throw out the received frames that were not | |
17641 | * able to be described and return a pointer to the first iocbq. If unable to | |
17642 | * allocate any iocbqs (including the first) this function will return NULL. | |
17643 | **/ | |
17644 | static struct lpfc_iocbq * | |
17645 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
17646 | { | |
7851fe2c | 17647 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
17648 | struct lpfc_dmabuf *d_buf, *n_buf; |
17649 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
17650 | struct fc_frame_header *fc_hdr; | |
17651 | uint32_t sid; | |
7851fe2c | 17652 | uint32_t len, tot_len; |
eeead811 | 17653 | struct ulp_bde64 *pbde; |
4f774513 JS |
17654 | |
17655 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
17656 | /* remove from receive buffer list */ | |
17657 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 17658 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 17659 | /* get the Remote Port's SID */ |
6669f9bb | 17660 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 17661 | tot_len = 0; |
4f774513 JS |
17662 | /* Get an iocbq struct to fill in. */ |
17663 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
17664 | if (first_iocbq) { | |
17665 | /* Initialize the first IOCB. */ | |
8fa38513 | 17666 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 | 17667 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
895427bd | 17668 | first_iocbq->vport = vport; |
939723a4 JS |
17669 | |
17670 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ | |
17671 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { | |
17672 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; | |
17673 | first_iocbq->iocb.un.rcvels.parmRo = | |
17674 | sli4_did_from_fc_hdr(fc_hdr); | |
17675 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; | |
17676 | } else | |
17677 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
17678 | first_iocbq->iocb.ulpContext = NO_XRI; |
17679 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
17680 | be16_to_cpu(fc_hdr->fh_ox_id); | |
17681 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
17682 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
17683 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 | 17684 | /* put the first buffer into the first IOCBq */ |
48a5a664 JS |
17685 | tot_len = bf_get(lpfc_rcqe_length, |
17686 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
17687 | ||
4f774513 JS |
17688 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
17689 | first_iocbq->context3 = NULL; | |
17690 | first_iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
17691 | if (tot_len > LPFC_DATA_BUF_SIZE) |
17692 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 17693 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
17694 | else |
17695 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; | |
17696 | ||
4f774513 | 17697 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
48a5a664 | 17698 | |
7851fe2c | 17699 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
17700 | } |
17701 | iocbq = first_iocbq; | |
17702 | /* | |
17703 | * Each IOCBq can have two Buffers assigned, so go through the list | |
17704 | * of buffers for this sequence and save two buffers in each IOCBq | |
17705 | */ | |
17706 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
17707 | if (!iocbq) { | |
17708 | lpfc_in_buf_free(vport->phba, d_buf); | |
17709 | continue; | |
17710 | } | |
17711 | if (!iocbq->context3) { | |
17712 | iocbq->context3 = d_buf; | |
17713 | iocbq->iocb.ulpBdeCount++; | |
7851fe2c JS |
17714 | /* We need to get the size out of the right CQE */ |
17715 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
17716 | len = bf_get(lpfc_rcqe_length, | |
17717 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
48a5a664 JS |
17718 | pbde = (struct ulp_bde64 *) |
17719 | &iocbq->iocb.unsli3.sli3Words[4]; | |
17720 | if (len > LPFC_DATA_BUF_SIZE) | |
17721 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
17722 | else | |
17723 | pbde->tus.f.bdeSize = len; | |
17724 | ||
7851fe2c JS |
17725 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
17726 | tot_len += len; | |
4f774513 JS |
17727 | } else { |
17728 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
17729 | if (!iocbq) { | |
17730 | if (first_iocbq) { | |
17731 | first_iocbq->iocb.ulpStatus = | |
17732 | IOSTAT_FCP_RSP_ERROR; | |
17733 | first_iocbq->iocb.un.ulpWord[4] = | |
17734 | IOERR_NO_RESOURCES; | |
17735 | } | |
17736 | lpfc_in_buf_free(vport->phba, d_buf); | |
17737 | continue; | |
17738 | } | |
48a5a664 JS |
17739 | /* We need to get the size out of the right CQE */ |
17740 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
17741 | len = bf_get(lpfc_rcqe_length, | |
17742 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
17743 | iocbq->context2 = d_buf; |
17744 | iocbq->context3 = NULL; | |
17745 | iocbq->iocb.ulpBdeCount = 1; | |
48a5a664 JS |
17746 | if (len > LPFC_DATA_BUF_SIZE) |
17747 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
4f774513 | 17748 | LPFC_DATA_BUF_SIZE; |
48a5a664 JS |
17749 | else |
17750 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; | |
7851fe2c | 17751 | |
7851fe2c JS |
17752 | tot_len += len; |
17753 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
17754 | ||
4f774513 JS |
17755 | iocbq->iocb.un.rcvels.remoteID = sid; |
17756 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
17757 | } | |
17758 | } | |
17759 | return first_iocbq; | |
17760 | } | |
17761 | ||
6669f9bb JS |
17762 | static void |
17763 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
17764 | struct hbq_dmabuf *seq_dmabuf) | |
17765 | { | |
17766 | struct fc_frame_header *fc_hdr; | |
17767 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
17768 | struct lpfc_hba *phba = vport->phba; | |
17769 | ||
17770 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
17771 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
17772 | if (!iocbq) { | |
17773 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
17774 | "2707 Ring %d handler: Failed to allocate " | |
17775 | "iocb Rctl x%x Type x%x received\n", | |
17776 | LPFC_ELS_RING, | |
17777 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
17778 | return; | |
17779 | } | |
17780 | if (!lpfc_complete_unsol_iocb(phba, | |
895427bd | 17781 | phba->sli4_hba.els_wq->pring, |
6669f9bb JS |
17782 | iocbq, fc_hdr->fh_r_ctl, |
17783 | fc_hdr->fh_type)) | |
6d368e53 | 17784 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
17785 | "2540 Ring %d handler: unexpected Rctl " |
17786 | "x%x Type x%x received\n", | |
17787 | LPFC_ELS_RING, | |
17788 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
17789 | ||
17790 | /* Free iocb created in lpfc_prep_seq */ | |
17791 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
17792 | &iocbq->list, list) { | |
17793 | list_del_init(&curr_iocb->list); | |
17794 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
17795 | } | |
17796 | lpfc_sli_release_iocbq(phba, iocbq); | |
17797 | } | |
17798 | ||
ae9e28f3 JS |
17799 | static void |
17800 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
17801 | struct lpfc_iocbq *rspiocb) | |
17802 | { | |
17803 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; | |
17804 | ||
17805 | if (pcmd && pcmd->virt) | |
771db5c0 | 17806 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
ae9e28f3 JS |
17807 | kfree(pcmd); |
17808 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
17809 | } | |
17810 | ||
17811 | static void | |
17812 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, | |
17813 | struct hbq_dmabuf *dmabuf) | |
17814 | { | |
17815 | struct fc_frame_header *fc_hdr; | |
17816 | struct lpfc_hba *phba = vport->phba; | |
17817 | struct lpfc_iocbq *iocbq = NULL; | |
17818 | union lpfc_wqe *wqe; | |
17819 | struct lpfc_dmabuf *pcmd = NULL; | |
17820 | uint32_t frame_len; | |
17821 | int rc; | |
17822 | ||
17823 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
17824 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
17825 | ||
17826 | /* Send the received frame back */ | |
17827 | iocbq = lpfc_sli_get_iocbq(phba); | |
17828 | if (!iocbq) | |
17829 | goto exit; | |
17830 | ||
17831 | /* Allocate buffer for command payload */ | |
17832 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
17833 | if (pcmd) | |
771db5c0 | 17834 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
ae9e28f3 JS |
17835 | &pcmd->phys); |
17836 | if (!pcmd || !pcmd->virt) | |
17837 | goto exit; | |
17838 | ||
17839 | INIT_LIST_HEAD(&pcmd->list); | |
17840 | ||
17841 | /* copyin the payload */ | |
17842 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); | |
17843 | ||
17844 | /* fill in BDE's for command */ | |
17845 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); | |
17846 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); | |
17847 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; | |
17848 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; | |
17849 | ||
17850 | iocbq->context2 = pcmd; | |
17851 | iocbq->vport = vport; | |
17852 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; | |
17853 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; | |
17854 | ||
17855 | /* | |
17856 | * Setup rest of the iocb as though it were a WQE | |
17857 | * Build the SEND_FRAME WQE | |
17858 | */ | |
17859 | wqe = (union lpfc_wqe *)&iocbq->iocb; | |
17860 | ||
17861 | wqe->send_frame.frame_len = frame_len; | |
17862 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); | |
17863 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); | |
17864 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); | |
17865 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); | |
17866 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); | |
17867 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); | |
17868 | ||
17869 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; | |
17870 | iocbq->iocb.ulpLe = 1; | |
17871 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; | |
17872 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); | |
17873 | if (rc == IOCB_ERROR) | |
17874 | goto exit; | |
17875 | ||
17876 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
17877 | return; | |
17878 | ||
17879 | exit: | |
17880 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
17881 | "2023 Unable to process MDS loopback frame\n"); | |
17882 | if (pcmd && pcmd->virt) | |
771db5c0 | 17883 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
ae9e28f3 | 17884 | kfree(pcmd); |
401bb416 DK |
17885 | if (iocbq) |
17886 | lpfc_sli_release_iocbq(phba, iocbq); | |
ae9e28f3 JS |
17887 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
17888 | } | |
17889 | ||
4f774513 JS |
17890 | /** |
17891 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
17892 | * @phba: Pointer to HBA context object. | |
17893 | * | |
17894 | * This function is called with no lock held. This function processes all | |
17895 | * the received buffers and gives it to upper layers when a received buffer | |
17896 | * indicates that it is the final frame in the sequence. The interrupt | |
895427bd | 17897 | * service routine processes received buffers at interrupt contexts. |
4f774513 JS |
17898 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
17899 | * appropriate receive function when the final frame in a sequence is received. | |
17900 | **/ | |
4d9ab994 JS |
17901 | void |
17902 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
17903 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 17904 | { |
4d9ab994 | 17905 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
17906 | struct fc_frame_header *fc_hdr; |
17907 | struct lpfc_vport *vport; | |
17908 | uint32_t fcfi; | |
939723a4 | 17909 | uint32_t did; |
4f774513 | 17910 | |
4f774513 | 17911 | /* Process each received buffer */ |
4d9ab994 | 17912 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
2ea259ee | 17913 | |
4d9ab994 JS |
17914 | /* check to see if this a valid type of frame */ |
17915 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
17916 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
17917 | return; | |
17918 | } | |
2ea259ee | 17919 | |
7851fe2c JS |
17920 | if ((bf_get(lpfc_cqe_code, |
17921 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
17922 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
17923 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
17924 | else | |
17925 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
17926 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
939723a4 | 17927 | |
ae9e28f3 JS |
17928 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
17929 | vport = phba->pport; | |
17930 | /* Handle MDS Loopback frames */ | |
17931 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); | |
17932 | return; | |
17933 | } | |
17934 | ||
895427bd JS |
17935 | /* d_id this frame is directed to */ |
17936 | did = sli4_did_from_fc_hdr(fc_hdr); | |
17937 | ||
17938 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); | |
939723a4 | 17939 | if (!vport) { |
4d9ab994 JS |
17940 | /* throw out the frame */ |
17941 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
17942 | return; | |
17943 | } | |
939723a4 | 17944 | |
939723a4 JS |
17945 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
17946 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && | |
17947 | (did != Fabric_DID)) { | |
17948 | /* | |
17949 | * Throw out the frame if we are not pt2pt. | |
17950 | * The pt2pt protocol allows for discovery frames | |
17951 | * to be received without a registered VPI. | |
17952 | */ | |
17953 | if (!(vport->fc_flag & FC_PT2PT) || | |
17954 | (phba->link_state == LPFC_HBA_READY)) { | |
17955 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
17956 | return; | |
17957 | } | |
17958 | } | |
17959 | ||
6669f9bb JS |
17960 | /* Handle the basic abort sequence (BA_ABTS) event */ |
17961 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
17962 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
17963 | return; | |
17964 | } | |
17965 | ||
4d9ab994 JS |
17966 | /* Link this frame */ |
17967 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
17968 | if (!seq_dmabuf) { | |
17969 | /* unable to add frame to vport - throw it out */ | |
17970 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
17971 | return; | |
17972 | } | |
17973 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 17974 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 17975 | return; |
def9c7a9 | 17976 | |
6669f9bb JS |
17977 | /* Send the complete sequence to the upper layer protocol */ |
17978 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 17979 | } |
6fb120a7 JS |
17980 | |
17981 | /** | |
17982 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
17983 | * @phba: pointer to lpfc hba data structure. | |
17984 | * | |
17985 | * This routine is invoked to post rpi header templates to the | |
17986 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
17987 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
17988 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
17989 | * |
17990 | * This routine does not require any locks. It's usage is expected | |
17991 | * to be driver load or reset recovery when the driver is | |
17992 | * sequential. | |
17993 | * | |
17994 | * Return codes | |
af901ca1 | 17995 | * 0 - successful |
d439d286 | 17996 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
17997 | * When this error occurs, the driver is not guaranteed |
17998 | * to have any rpi regions posted to the device and | |
17999 | * must either attempt to repost the regions or take a | |
18000 | * fatal error. | |
18001 | **/ | |
18002 | int | |
18003 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
18004 | { | |
18005 | struct lpfc_rpi_hdr *rpi_page; | |
18006 | uint32_t rc = 0; | |
6d368e53 JS |
18007 | uint16_t lrpi = 0; |
18008 | ||
18009 | /* SLI4 ports that support extents do not require RPI headers. */ | |
18010 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
18011 | goto exit; | |
18012 | if (phba->sli4_hba.extents_in_use) | |
18013 | return -EIO; | |
6fb120a7 | 18014 | |
6fb120a7 | 18015 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
18016 | /* |
18017 | * Assign the rpi headers a physical rpi only if the driver | |
18018 | * has not initialized those resources. A port reset only | |
18019 | * needs the headers posted. | |
18020 | */ | |
18021 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
18022 | LPFC_RPI_RSRC_RDY) | |
18023 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
18024 | ||
6fb120a7 JS |
18025 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
18026 | if (rc != MBX_SUCCESS) { | |
18027 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
18028 | "2008 Error %d posting all rpi " | |
18029 | "headers\n", rc); | |
18030 | rc = -EIO; | |
18031 | break; | |
18032 | } | |
18033 | } | |
18034 | ||
6d368e53 JS |
18035 | exit: |
18036 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
18037 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
18038 | return rc; |
18039 | } | |
18040 | ||
18041 | /** | |
18042 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
18043 | * @phba: pointer to lpfc hba data structure. | |
18044 | * @rpi_page: pointer to the rpi memory region. | |
18045 | * | |
18046 | * This routine is invoked to post a single rpi header to the | |
18047 | * HBA consistent with the SLI-4 interface spec. This memory region | |
18048 | * maps up to 64 rpi context regions. | |
18049 | * | |
18050 | * Return codes | |
af901ca1 | 18051 | * 0 - successful |
d439d286 JS |
18052 | * -ENOMEM - No available memory |
18053 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
18054 | **/ |
18055 | int | |
18056 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
18057 | { | |
18058 | LPFC_MBOXQ_t *mboxq; | |
18059 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
18060 | uint32_t rc = 0; | |
6fb120a7 JS |
18061 | uint32_t shdr_status, shdr_add_status; |
18062 | union lpfc_sli4_cfg_shdr *shdr; | |
18063 | ||
6d368e53 JS |
18064 | /* SLI4 ports that support extents do not require RPI headers. */ |
18065 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
18066 | return rc; | |
18067 | if (phba->sli4_hba.extents_in_use) | |
18068 | return -EIO; | |
18069 | ||
6fb120a7 JS |
18070 | /* The port is notified of the header region via a mailbox command. */ |
18071 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
18072 | if (!mboxq) { | |
18073 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
18074 | "2001 Unable to allocate memory for issuing " | |
18075 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
18076 | return -ENOMEM; | |
18077 | } | |
18078 | ||
18079 | /* Post all rpi memory regions to the port. */ | |
18080 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
18081 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
18082 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
18083 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
18084 | sizeof(struct lpfc_sli4_cfg_mhdr), |
18085 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
18086 | |
18087 | ||
18088 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
18089 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
18090 | rpi_page->start_rpi); | |
6d368e53 JS |
18091 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
18092 | hdr_tmpl, rpi_page->page_count); | |
18093 | ||
6fb120a7 JS |
18094 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
18095 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 18096 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
18097 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
18098 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
18099 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
18100 | if (rc != MBX_TIMEOUT) | |
18101 | mempool_free(mboxq, phba->mbox_mem_pool); | |
18102 | if (shdr_status || shdr_add_status || rc) { | |
18103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18104 | "2514 POST_RPI_HDR mailbox failed with " | |
18105 | "status x%x add_status x%x, mbx status x%x\n", | |
18106 | shdr_status, shdr_add_status, rc); | |
18107 | rc = -ENXIO; | |
845d9e8d JS |
18108 | } else { |
18109 | /* | |
18110 | * The next_rpi stores the next logical module-64 rpi value used | |
18111 | * to post physical rpis in subsequent rpi postings. | |
18112 | */ | |
18113 | spin_lock_irq(&phba->hbalock); | |
18114 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; | |
18115 | spin_unlock_irq(&phba->hbalock); | |
6fb120a7 JS |
18116 | } |
18117 | return rc; | |
18118 | } | |
18119 | ||
18120 | /** | |
18121 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
18122 | * @phba: pointer to lpfc hba data structure. | |
18123 | * | |
18124 | * This routine is invoked to post rpi header templates to the | |
18125 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
18126 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
18127 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
18128 | * |
18129 | * Returns | |
af901ca1 | 18130 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
18131 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
18132 | **/ | |
18133 | int | |
18134 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
18135 | { | |
6d368e53 JS |
18136 | unsigned long rpi; |
18137 | uint16_t max_rpi, rpi_limit; | |
18138 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 | 18139 | struct lpfc_rpi_hdr *rpi_hdr; |
4902b381 | 18140 | unsigned long iflag; |
6fb120a7 | 18141 | |
6fb120a7 | 18142 | /* |
6d368e53 JS |
18143 | * Fetch the next logical rpi. Because this index is logical, |
18144 | * the driver starts at 0 each time. | |
6fb120a7 | 18145 | */ |
4902b381 | 18146 | spin_lock_irqsave(&phba->hbalock, iflag); |
be6bb941 JS |
18147 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
18148 | rpi_limit = phba->sli4_hba.next_rpi; | |
18149 | ||
6d368e53 JS |
18150 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
18151 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
18152 | rpi = LPFC_RPI_ALLOC_ERROR; |
18153 | else { | |
18154 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
18155 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
18156 | phba->sli4_hba.rpi_count++; | |
18157 | } | |
be6bb941 JS |
18158 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
18159 | "0001 rpi:%x max:%x lim:%x\n", | |
18160 | (int) rpi, max_rpi, rpi_limit); | |
6fb120a7 JS |
18161 | |
18162 | /* | |
18163 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 18164 | * has been exhausted. |
6fb120a7 JS |
18165 | */ |
18166 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
18167 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
4902b381 | 18168 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
18169 | return rpi; |
18170 | } | |
18171 | ||
6d368e53 JS |
18172 | /* |
18173 | * RPI header postings are not required for SLI4 ports capable of | |
18174 | * extents. | |
18175 | */ | |
18176 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
4902b381 | 18177 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6d368e53 JS |
18178 | return rpi; |
18179 | } | |
18180 | ||
6fb120a7 JS |
18181 | /* |
18182 | * If the driver is running low on rpi resources, allocate another | |
18183 | * page now. Note that the next_rpi value is used because | |
18184 | * it represents how many are actually in use whereas max_rpi notes | |
18185 | * how many are supported max by the device. | |
18186 | */ | |
6d368e53 | 18187 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
4902b381 | 18188 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6fb120a7 JS |
18189 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
18190 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
18191 | if (!rpi_hdr) { | |
18192 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
18193 | "2002 Error Could not grow rpi " | |
18194 | "count\n"); | |
18195 | } else { | |
6d368e53 JS |
18196 | lrpi = rpi_hdr->start_rpi; |
18197 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
18198 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
18199 | } | |
18200 | } | |
18201 | ||
18202 | return rpi; | |
18203 | } | |
18204 | ||
d7c47992 JS |
18205 | /** |
18206 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
18207 | * @phba: pointer to lpfc hba data structure. | |
18208 | * | |
18209 | * This routine is invoked to release an rpi to the pool of | |
18210 | * available rpis maintained by the driver. | |
18211 | **/ | |
5d8b8167 | 18212 | static void |
d7c47992 JS |
18213 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
18214 | { | |
18215 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
18216 | phba->sli4_hba.rpi_count--; | |
18217 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
18218 | } | |
18219 | } | |
18220 | ||
6fb120a7 JS |
18221 | /** |
18222 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
18223 | * @phba: pointer to lpfc hba data structure. | |
18224 | * | |
18225 | * This routine is invoked to release an rpi to the pool of | |
18226 | * available rpis maintained by the driver. | |
18227 | **/ | |
18228 | void | |
18229 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
18230 | { | |
18231 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 18232 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
18233 | spin_unlock_irq(&phba->hbalock); |
18234 | } | |
18235 | ||
18236 | /** | |
18237 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
18238 | * @phba: pointer to lpfc hba data structure. | |
18239 | * | |
18240 | * This routine is invoked to remove the memory region that | |
18241 | * provided rpi via a bitmask. | |
18242 | **/ | |
18243 | void | |
18244 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
18245 | { | |
18246 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
18247 | kfree(phba->sli4_hba.rpi_ids); |
18248 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
18249 | } |
18250 | ||
18251 | /** | |
18252 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
18253 | * @phba: pointer to lpfc hba data structure. | |
18254 | * | |
18255 | * This routine is invoked to remove the memory region that | |
18256 | * provided rpi via a bitmask. | |
18257 | **/ | |
18258 | int | |
6b5151fd JS |
18259 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
18260 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) | |
6fb120a7 JS |
18261 | { |
18262 | LPFC_MBOXQ_t *mboxq; | |
18263 | struct lpfc_hba *phba = ndlp->phba; | |
18264 | int rc; | |
18265 | ||
18266 | /* The port is notified of the header region via a mailbox command. */ | |
18267 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
18268 | if (!mboxq) | |
18269 | return -ENOMEM; | |
18270 | ||
18271 | /* Post all rpi memory regions to the port. */ | |
18272 | lpfc_resume_rpi(mboxq, ndlp); | |
6b5151fd JS |
18273 | if (cmpl) { |
18274 | mboxq->mbox_cmpl = cmpl; | |
3e1f0718 JS |
18275 | mboxq->ctx_buf = arg; |
18276 | mboxq->ctx_ndlp = ndlp; | |
72859909 JS |
18277 | } else |
18278 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6b5151fd | 18279 | mboxq->vport = ndlp->vport; |
6fb120a7 JS |
18280 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
18281 | if (rc == MBX_NOT_FINISHED) { | |
18282 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
18283 | "2010 Resume RPI Mailbox failed " | |
18284 | "status %d, mbxStatus x%x\n", rc, | |
18285 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
18286 | mempool_free(mboxq, phba->mbox_mem_pool); | |
18287 | return -EIO; | |
18288 | } | |
18289 | return 0; | |
18290 | } | |
18291 | ||
18292 | /** | |
18293 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 18294 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 18295 | * |
76a95d75 | 18296 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
18297 | * |
18298 | * Returns: | |
18299 | * 0 success | |
18300 | * -Evalue otherwise | |
18301 | **/ | |
18302 | int | |
76a95d75 | 18303 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
18304 | { |
18305 | LPFC_MBOXQ_t *mboxq; | |
18306 | int rc = 0; | |
6a9c52cf | 18307 | int retval = MBX_SUCCESS; |
6fb120a7 | 18308 | uint32_t mbox_tmo; |
76a95d75 | 18309 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
18310 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
18311 | if (!mboxq) | |
18312 | return -ENOMEM; | |
76a95d75 | 18313 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 18314 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 18315 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 18316 | if (rc != MBX_SUCCESS) { |
76a95d75 | 18317 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
18318 | "2022 INIT VPI Mailbox failed " |
18319 | "status %d, mbxStatus x%x\n", rc, | |
18320 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 18321 | retval = -EIO; |
6fb120a7 | 18322 | } |
6a9c52cf | 18323 | if (rc != MBX_TIMEOUT) |
76a95d75 | 18324 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
18325 | |
18326 | return retval; | |
6fb120a7 JS |
18327 | } |
18328 | ||
18329 | /** | |
18330 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
18331 | * @phba: pointer to lpfc hba data structure. | |
18332 | * @mboxq: Pointer to mailbox object. | |
18333 | * | |
18334 | * This routine is invoked to manually add a single FCF record. The caller | |
18335 | * must pass a completely initialized FCF_Record. This routine takes | |
18336 | * care of the nonembedded mailbox operations. | |
18337 | **/ | |
18338 | static void | |
18339 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
18340 | { | |
18341 | void *virt_addr; | |
18342 | union lpfc_sli4_cfg_shdr *shdr; | |
18343 | uint32_t shdr_status, shdr_add_status; | |
18344 | ||
18345 | virt_addr = mboxq->sge_array->addr[0]; | |
18346 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
18347 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
18348 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
18349 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
18350 | ||
18351 | if ((shdr_status || shdr_add_status) && | |
18352 | (shdr_status != STATUS_FCF_IN_USE)) | |
18353 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18354 | "2558 ADD_FCF_RECORD mailbox failed with " | |
18355 | "status x%x add_status x%x\n", | |
18356 | shdr_status, shdr_add_status); | |
18357 | ||
18358 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
18359 | } | |
18360 | ||
18361 | /** | |
18362 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
18363 | * @phba: pointer to lpfc hba data structure. | |
18364 | * @fcf_record: pointer to the initialized fcf record to add. | |
18365 | * | |
18366 | * This routine is invoked to manually add a single FCF record. The caller | |
18367 | * must pass a completely initialized FCF_Record. This routine takes | |
18368 | * care of the nonembedded mailbox operations. | |
18369 | **/ | |
18370 | int | |
18371 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
18372 | { | |
18373 | int rc = 0; | |
18374 | LPFC_MBOXQ_t *mboxq; | |
18375 | uint8_t *bytep; | |
18376 | void *virt_addr; | |
6fb120a7 JS |
18377 | struct lpfc_mbx_sge sge; |
18378 | uint32_t alloc_len, req_len; | |
18379 | uint32_t fcfindex; | |
18380 | ||
18381 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
18382 | if (!mboxq) { | |
18383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18384 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
18385 | return -ENOMEM; | |
18386 | } | |
18387 | ||
18388 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
18389 | sizeof(uint32_t); | |
18390 | ||
18391 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
18392 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
18393 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
18394 | req_len, LPFC_SLI4_MBX_NEMBED); | |
18395 | if (alloc_len < req_len) { | |
18396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18397 | "2523 Allocated DMA memory size (x%x) is " | |
18398 | "less than the requested DMA memory " | |
18399 | "size (x%x)\n", alloc_len, req_len); | |
18400 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
18401 | return -ENOMEM; | |
18402 | } | |
18403 | ||
18404 | /* | |
18405 | * Get the first SGE entry from the non-embedded DMA memory. This | |
18406 | * routine only uses a single SGE. | |
18407 | */ | |
18408 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
6fb120a7 JS |
18409 | virt_addr = mboxq->sge_array->addr[0]; |
18410 | /* | |
18411 | * Configure the FCF record for FCFI 0. This is the driver's | |
18412 | * hardcoded default and gets used in nonFIP mode. | |
18413 | */ | |
18414 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
18415 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
18416 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
18417 | ||
18418 | /* | |
18419 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
18420 | * the FCoE header plus word10. The data copy needs to be endian | |
18421 | * correct. | |
18422 | */ | |
18423 | bytep += sizeof(uint32_t); | |
18424 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
18425 | mboxq->vport = phba->pport; | |
18426 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
18427 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
18428 | if (rc == MBX_NOT_FINISHED) { | |
18429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18430 | "2515 ADD_FCF_RECORD mailbox failed with " | |
18431 | "status 0x%x\n", rc); | |
18432 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
18433 | rc = -EIO; | |
18434 | } else | |
18435 | rc = 0; | |
18436 | ||
18437 | return rc; | |
18438 | } | |
18439 | ||
18440 | /** | |
18441 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
18442 | * @phba: pointer to lpfc hba data structure. | |
18443 | * @fcf_record: pointer to the fcf record to write the default data. | |
18444 | * @fcf_index: FCF table entry index. | |
18445 | * | |
18446 | * This routine is invoked to build the driver's default FCF record. The | |
18447 | * values used are hardcoded. This routine handles memory initialization. | |
18448 | * | |
18449 | **/ | |
18450 | void | |
18451 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
18452 | struct fcf_record *fcf_record, | |
18453 | uint16_t fcf_index) | |
18454 | { | |
18455 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
18456 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
18457 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
18458 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
18459 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
18460 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
18461 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
18462 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
18463 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
18464 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
18465 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
18466 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
18467 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
18468 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 18469 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
18470 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
18471 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
18472 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
18473 | /* Set the VLAN bit map */ | |
18474 | if (phba->valid_vlan) { | |
18475 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
18476 | = 1 << (phba->vlan_id % 8); | |
18477 | } | |
18478 | } | |
18479 | ||
18480 | /** | |
0c9ab6f5 | 18481 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
18482 | * @phba: pointer to lpfc hba data structure. |
18483 | * @fcf_index: FCF table entry offset. | |
18484 | * | |
0c9ab6f5 JS |
18485 | * This routine is invoked to scan the entire FCF table by reading FCF |
18486 | * record and processing it one at a time starting from the @fcf_index | |
18487 | * for initial FCF discovery or fast FCF failover rediscovery. | |
18488 | * | |
25985edc | 18489 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 18490 | * otherwise. |
6fb120a7 JS |
18491 | **/ |
18492 | int | |
0c9ab6f5 | 18493 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
18494 | { |
18495 | int rc = 0, error; | |
18496 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 18497 | |
32b9793f | 18498 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
80c17849 | 18499 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
6fb120a7 JS |
18500 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
18501 | if (!mboxq) { | |
18502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
18503 | "2000 Failed to allocate mbox for " | |
18504 | "READ_FCF cmd\n"); | |
4d9ab994 | 18505 | error = -ENOMEM; |
0c9ab6f5 | 18506 | goto fail_fcf_scan; |
6fb120a7 | 18507 | } |
ecfd03c6 | 18508 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 18509 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
18510 | if (rc) { |
18511 | error = -EINVAL; | |
0c9ab6f5 | 18512 | goto fail_fcf_scan; |
6fb120a7 | 18513 | } |
ecfd03c6 | 18514 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 18515 | mboxq->vport = phba->pport; |
0c9ab6f5 | 18516 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
18517 | |
18518 | spin_lock_irq(&phba->hbalock); | |
18519 | phba->hba_flag |= FCF_TS_INPROG; | |
18520 | spin_unlock_irq(&phba->hbalock); | |
18521 | ||
6fb120a7 | 18522 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 18523 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 18524 | error = -EIO; |
ecfd03c6 | 18525 | else { |
38b92ef8 JS |
18526 | /* Reset eligible FCF count for new scan */ |
18527 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 18528 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 18529 | error = 0; |
32b9793f | 18530 | } |
0c9ab6f5 | 18531 | fail_fcf_scan: |
4d9ab994 JS |
18532 | if (error) { |
18533 | if (mboxq) | |
18534 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 18535 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 18536 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 18537 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
18538 | spin_unlock_irq(&phba->hbalock); |
18539 | } | |
6fb120a7 JS |
18540 | return error; |
18541 | } | |
a0c87cbd | 18542 | |
0c9ab6f5 | 18543 | /** |
a93ff37a | 18544 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
18545 | * @phba: pointer to lpfc hba data structure. |
18546 | * @fcf_index: FCF table entry offset. | |
18547 | * | |
18548 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 18549 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 18550 | * |
25985edc | 18551 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
18552 | * otherwise. |
18553 | **/ | |
18554 | int | |
18555 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
18556 | { | |
18557 | int rc = 0, error; | |
18558 | LPFC_MBOXQ_t *mboxq; | |
18559 | ||
18560 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
18561 | if (!mboxq) { | |
18562 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
18563 | "2763 Failed to allocate mbox for " | |
18564 | "READ_FCF cmd\n"); | |
18565 | error = -ENOMEM; | |
18566 | goto fail_fcf_read; | |
18567 | } | |
18568 | /* Construct the read FCF record mailbox command */ | |
18569 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
18570 | if (rc) { | |
18571 | error = -EINVAL; | |
18572 | goto fail_fcf_read; | |
18573 | } | |
18574 | /* Issue the mailbox command asynchronously */ | |
18575 | mboxq->vport = phba->pport; | |
18576 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
18577 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
18578 | if (rc == MBX_NOT_FINISHED) | |
18579 | error = -EIO; | |
18580 | else | |
18581 | error = 0; | |
18582 | ||
18583 | fail_fcf_read: | |
18584 | if (error && mboxq) | |
18585 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
18586 | return error; | |
18587 | } | |
18588 | ||
18589 | /** | |
18590 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
18591 | * @phba: pointer to lpfc hba data structure. | |
18592 | * @fcf_index: FCF table entry offset. | |
18593 | * | |
18594 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 18595 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 18596 | * |
25985edc | 18597 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
18598 | * otherwise. |
18599 | **/ | |
18600 | int | |
18601 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
18602 | { | |
18603 | int rc = 0, error; | |
18604 | LPFC_MBOXQ_t *mboxq; | |
18605 | ||
18606 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
18607 | if (!mboxq) { | |
18608 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
18609 | "2758 Failed to allocate mbox for " | |
18610 | "READ_FCF cmd\n"); | |
18611 | error = -ENOMEM; | |
18612 | goto fail_fcf_read; | |
18613 | } | |
18614 | /* Construct the read FCF record mailbox command */ | |
18615 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
18616 | if (rc) { | |
18617 | error = -EINVAL; | |
18618 | goto fail_fcf_read; | |
18619 | } | |
18620 | /* Issue the mailbox command asynchronously */ | |
18621 | mboxq->vport = phba->pport; | |
18622 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
18623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
18624 | if (rc == MBX_NOT_FINISHED) | |
18625 | error = -EIO; | |
18626 | else | |
18627 | error = 0; | |
18628 | ||
18629 | fail_fcf_read: | |
18630 | if (error && mboxq) | |
18631 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
18632 | return error; | |
18633 | } | |
18634 | ||
7d791df7 | 18635 | /** |
f5cb5304 | 18636 | * lpfc_check_next_fcf_pri_level |
7d791df7 JS |
18637 | * phba pointer to the lpfc_hba struct for this port. |
18638 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
18639 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
18640 | * rr_bmask based on their priority level. Starting from the highest priority | |
18641 | * to the lowest. The most likely FCF candidate will be in the highest | |
18642 | * priority group. When this routine is called it searches the fcf_pri list for | |
18643 | * next lowest priority group and repopulates the rr_bmask with only those | |
18644 | * fcf_indexes. | |
18645 | * returns: | |
18646 | * 1=success 0=failure | |
18647 | **/ | |
5d8b8167 | 18648 | static int |
7d791df7 JS |
18649 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
18650 | { | |
18651 | uint16_t next_fcf_pri; | |
18652 | uint16_t last_index; | |
18653 | struct lpfc_fcf_pri *fcf_pri; | |
18654 | int rc; | |
18655 | int ret = 0; | |
18656 | ||
18657 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
18658 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
18659 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
18660 | "3060 Last IDX %d\n", last_index); | |
2562669c JS |
18661 | |
18662 | /* Verify the priority list has 2 or more entries */ | |
18663 | spin_lock_irq(&phba->hbalock); | |
18664 | if (list_empty(&phba->fcf.fcf_pri_list) || | |
18665 | list_is_singular(&phba->fcf.fcf_pri_list)) { | |
18666 | spin_unlock_irq(&phba->hbalock); | |
7d791df7 JS |
18667 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
18668 | "3061 Last IDX %d\n", last_index); | |
18669 | return 0; /* Empty rr list */ | |
18670 | } | |
2562669c JS |
18671 | spin_unlock_irq(&phba->hbalock); |
18672 | ||
7d791df7 JS |
18673 | next_fcf_pri = 0; |
18674 | /* | |
18675 | * Clear the rr_bmask and set all of the bits that are at this | |
18676 | * priority. | |
18677 | */ | |
18678 | memset(phba->fcf.fcf_rr_bmask, 0, | |
18679 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
18680 | spin_lock_irq(&phba->hbalock); | |
18681 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
18682 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
18683 | continue; | |
18684 | /* | |
18685 | * the 1st priority that has not FLOGI failed | |
18686 | * will be the highest. | |
18687 | */ | |
18688 | if (!next_fcf_pri) | |
18689 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
18690 | spin_unlock_irq(&phba->hbalock); | |
18691 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
18692 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
18693 | fcf_pri->fcf_rec.fcf_index); | |
18694 | if (rc) | |
18695 | return 0; | |
18696 | } | |
18697 | spin_lock_irq(&phba->hbalock); | |
18698 | } | |
18699 | /* | |
18700 | * if next_fcf_pri was not set above and the list is not empty then | |
18701 | * we have failed flogis on all of them. So reset flogi failed | |
4907cb7b | 18702 | * and start at the beginning. |
7d791df7 JS |
18703 | */ |
18704 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
18705 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
18706 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
18707 | /* | |
18708 | * the 1st priority that has not FLOGI failed | |
18709 | * will be the highest. | |
18710 | */ | |
18711 | if (!next_fcf_pri) | |
18712 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
18713 | spin_unlock_irq(&phba->hbalock); | |
18714 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
18715 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
18716 | fcf_pri->fcf_rec.fcf_index); | |
18717 | if (rc) | |
18718 | return 0; | |
18719 | } | |
18720 | spin_lock_irq(&phba->hbalock); | |
18721 | } | |
18722 | } else | |
18723 | ret = 1; | |
18724 | spin_unlock_irq(&phba->hbalock); | |
18725 | ||
18726 | return ret; | |
18727 | } | |
0c9ab6f5 JS |
18728 | /** |
18729 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
18730 | * @phba: pointer to lpfc hba data structure. | |
18731 | * | |
18732 | * This routine is to get the next eligible FCF record index in a round | |
18733 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 18734 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
18735 | * shall be returned, otherwise, the next eligible FCF record's index |
18736 | * shall be returned. | |
18737 | **/ | |
18738 | uint16_t | |
18739 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
18740 | { | |
18741 | uint16_t next_fcf_index; | |
18742 | ||
421c6622 | 18743 | initial_priority: |
3804dc84 | 18744 | /* Search start from next bit of currently registered FCF index */ |
421c6622 JS |
18745 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
18746 | ||
7d791df7 | 18747 | next_priority: |
421c6622 JS |
18748 | /* Determine the next fcf index to check */ |
18749 | next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
18750 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
18751 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
18752 | next_fcf_index); |
18753 | ||
0c9ab6f5 | 18754 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
18755 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
18756 | /* | |
18757 | * If we have wrapped then we need to clear the bits that | |
18758 | * have been tested so that we can detect when we should | |
18759 | * change the priority level. | |
18760 | */ | |
0c9ab6f5 JS |
18761 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
18762 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
18763 | } |
18764 | ||
3804dc84 JS |
18765 | |
18766 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
18767 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
18768 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
18769 | /* | |
18770 | * If next fcf index is not found check if there are lower | |
18771 | * Priority level fcf's in the fcf_priority list. | |
18772 | * Set up the rr_bmask with all of the avaiable fcf bits | |
18773 | * at that level and continue the selection process. | |
18774 | */ | |
18775 | if (lpfc_check_next_fcf_pri_level(phba)) | |
421c6622 | 18776 | goto initial_priority; |
3804dc84 JS |
18777 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
18778 | "2844 No roundrobin failover FCF available\n"); | |
036cad1f JS |
18779 | |
18780 | return LPFC_FCOE_FCF_NEXT_NONE; | |
3804dc84 JS |
18781 | } |
18782 | ||
7d791df7 JS |
18783 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
18784 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
f5cb5304 JS |
18785 | LPFC_FCF_FLOGI_FAILED) { |
18786 | if (list_is_singular(&phba->fcf.fcf_pri_list)) | |
18787 | return LPFC_FCOE_FCF_NEXT_NONE; | |
18788 | ||
7d791df7 | 18789 | goto next_priority; |
f5cb5304 | 18790 | } |
7d791df7 | 18791 | |
3804dc84 | 18792 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
18793 | "2845 Get next roundrobin failover FCF (x%x)\n", |
18794 | next_fcf_index); | |
18795 | ||
0c9ab6f5 JS |
18796 | return next_fcf_index; |
18797 | } | |
18798 | ||
18799 | /** | |
18800 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
18801 | * @phba: pointer to lpfc hba data structure. | |
18802 | * | |
18803 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 18804 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
18805 | * does not go beyond the range of the driver allocated bmask dimension |
18806 | * before setting the bit. | |
18807 | * | |
18808 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
18809 | * -EINVAL. | |
18810 | **/ | |
18811 | int | |
18812 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
18813 | { | |
18814 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
18815 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
18816 | "2610 FCF (x%x) reached driver's book " |
18817 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
18818 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
18819 | return -EINVAL; | |
18820 | } | |
18821 | /* Set the eligible FCF record index bmask */ | |
18822 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
18823 | ||
3804dc84 | 18824 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 18825 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
18826 | "bmask\n", fcf_index); |
18827 | ||
0c9ab6f5 JS |
18828 | return 0; |
18829 | } | |
18830 | ||
18831 | /** | |
3804dc84 | 18832 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
18833 | * @phba: pointer to lpfc hba data structure. |
18834 | * | |
18835 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 18836 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
18837 | * does not go beyond the range of the driver allocated bmask dimension |
18838 | * before clearing the bit. | |
18839 | **/ | |
18840 | void | |
18841 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
18842 | { | |
9a803a74 | 18843 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
0c9ab6f5 JS |
18844 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
18845 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
18846 | "2762 FCF (x%x) reached driver's book " |
18847 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
18848 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
18849 | return; | |
18850 | } | |
18851 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 | 18852 | spin_lock_irq(&phba->hbalock); |
9a803a74 JS |
18853 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
18854 | list) { | |
7d791df7 JS |
18855 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
18856 | list_del_init(&fcf_pri->list); | |
18857 | break; | |
18858 | } | |
18859 | } | |
18860 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 18861 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
18862 | |
18863 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 18864 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 18865 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
18866 | } |
18867 | ||
ecfd03c6 JS |
18868 | /** |
18869 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
18870 | * @phba: pointer to lpfc hba data structure. | |
18871 | * | |
18872 | * This routine is the completion routine for the rediscover FCF table mailbox | |
18873 | * command. If the mailbox command returned failure, it will try to stop the | |
18874 | * FCF rediscover wait timer. | |
18875 | **/ | |
5d8b8167 | 18876 | static void |
ecfd03c6 JS |
18877 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
18878 | { | |
18879 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
18880 | uint32_t shdr_status, shdr_add_status; | |
18881 | ||
18882 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
18883 | ||
18884 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
18885 | &redisc_fcf->header.cfg_shdr.response); | |
18886 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
18887 | &redisc_fcf->header.cfg_shdr.response); | |
18888 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 18889 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
18890 | "2746 Requesting for FCF rediscovery failed " |
18891 | "status x%x add_status x%x\n", | |
18892 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 18893 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 18894 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 18895 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
18896 | spin_unlock_irq(&phba->hbalock); |
18897 | /* | |
18898 | * CVL event triggered FCF rediscover request failed, | |
18899 | * last resort to re-try current registered FCF entry. | |
18900 | */ | |
18901 | lpfc_retry_pport_discovery(phba); | |
18902 | } else { | |
18903 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 18904 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
18905 | spin_unlock_irq(&phba->hbalock); |
18906 | /* | |
18907 | * DEAD FCF event triggered FCF rediscover request | |
18908 | * failed, last resort to fail over as a link down | |
18909 | * to FCF registration. | |
18910 | */ | |
18911 | lpfc_sli4_fcf_dead_failthrough(phba); | |
18912 | } | |
0c9ab6f5 JS |
18913 | } else { |
18914 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 18915 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
18916 | /* |
18917 | * Start FCF rediscovery wait timer for pending FCF | |
18918 | * before rescan FCF record table. | |
18919 | */ | |
18920 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 18921 | } |
ecfd03c6 JS |
18922 | |
18923 | mempool_free(mbox, phba->mbox_mem_pool); | |
18924 | } | |
18925 | ||
18926 | /** | |
3804dc84 | 18927 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
18928 | * @phba: pointer to lpfc hba data structure. |
18929 | * | |
18930 | * This routine is invoked to request for rediscovery of the entire FCF table | |
18931 | * by the port. | |
18932 | **/ | |
18933 | int | |
18934 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
18935 | { | |
18936 | LPFC_MBOXQ_t *mbox; | |
18937 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
18938 | int rc, length; | |
18939 | ||
0c9ab6f5 JS |
18940 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
18941 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
18942 | ||
ecfd03c6 JS |
18943 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
18944 | if (!mbox) { | |
18945 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
18946 | "2745 Failed to allocate mbox for " | |
18947 | "requesting FCF rediscover.\n"); | |
18948 | return -ENOMEM; | |
18949 | } | |
18950 | ||
18951 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
18952 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
18953 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
18954 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
18955 | length, LPFC_SLI4_MBX_EMBED); | |
18956 | ||
18957 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
18958 | /* Set count to 0 for invalidating the entire FCF database */ | |
18959 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
18960 | ||
18961 | /* Issue the mailbox command asynchronously */ | |
18962 | mbox->vport = phba->pport; | |
18963 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
18964 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
18965 | ||
18966 | if (rc == MBX_NOT_FINISHED) { | |
18967 | mempool_free(mbox, phba->mbox_mem_pool); | |
18968 | return -EIO; | |
18969 | } | |
18970 | return 0; | |
18971 | } | |
18972 | ||
fc2b989b JS |
18973 | /** |
18974 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
18975 | * @phba: pointer to lpfc hba data structure. | |
18976 | * | |
18977 | * This function is the failover routine as a last resort to the FCF DEAD | |
18978 | * event when driver failed to perform fast FCF failover. | |
18979 | **/ | |
18980 | void | |
18981 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
18982 | { | |
18983 | uint32_t link_state; | |
18984 | ||
18985 | /* | |
18986 | * Last resort as FCF DEAD event failover will treat this as | |
18987 | * a link down, but save the link state because we don't want | |
18988 | * it to be changed to Link Down unless it is already down. | |
18989 | */ | |
18990 | link_state = phba->link_state; | |
18991 | lpfc_linkdown(phba); | |
18992 | phba->link_state = link_state; | |
18993 | ||
18994 | /* Unregister FCF if no devices connected to it */ | |
18995 | lpfc_unregister_unused_fcf(phba); | |
18996 | } | |
18997 | ||
a0c87cbd | 18998 | /** |
026abb87 | 18999 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 19000 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 19001 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 19002 | * |
026abb87 JS |
19003 | * This function gets SLI3 port configure region 23 data through memory dump |
19004 | * mailbox command. When it successfully retrieves data, the size of the data | |
19005 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 19006 | **/ |
026abb87 JS |
19007 | static uint32_t |
19008 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
19009 | { |
19010 | LPFC_MBOXQ_t *pmb = NULL; | |
19011 | MAILBOX_t *mb; | |
026abb87 | 19012 | uint32_t offset = 0; |
a0c87cbd JS |
19013 | int rc; |
19014 | ||
026abb87 JS |
19015 | if (!rgn23_data) |
19016 | return 0; | |
19017 | ||
a0c87cbd JS |
19018 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
19019 | if (!pmb) { | |
19020 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
19021 | "2600 failed to allocate mailbox memory\n"); |
19022 | return 0; | |
a0c87cbd JS |
19023 | } |
19024 | mb = &pmb->u.mb; | |
19025 | ||
a0c87cbd JS |
19026 | do { |
19027 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
19028 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
19029 | ||
19030 | if (rc != MBX_SUCCESS) { | |
19031 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
19032 | "2601 failed to read config " |
19033 | "region 23, rc 0x%x Status 0x%x\n", | |
19034 | rc, mb->mbxStatus); | |
a0c87cbd JS |
19035 | mb->un.varDmp.word_cnt = 0; |
19036 | } | |
19037 | /* | |
19038 | * dump mem may return a zero when finished or we got a | |
19039 | * mailbox error, either way we are done. | |
19040 | */ | |
19041 | if (mb->un.varDmp.word_cnt == 0) | |
19042 | break; | |
19043 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
19044 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
19045 | ||
19046 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
19047 | rgn23_data + offset, |
19048 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
19049 | offset += mb->un.varDmp.word_cnt; |
19050 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
19051 | ||
026abb87 JS |
19052 | mempool_free(pmb, phba->mbox_mem_pool); |
19053 | return offset; | |
19054 | } | |
19055 | ||
19056 | /** | |
19057 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
19058 | * @phba: pointer to lpfc hba data structure. | |
19059 | * @rgn23_data: pointer to configure region 23 data. | |
19060 | * | |
19061 | * This function gets SLI4 port configure region 23 data through memory dump | |
19062 | * mailbox command. When it successfully retrieves data, the size of the data | |
19063 | * will be returned, otherwise, 0 will be returned. | |
19064 | **/ | |
19065 | static uint32_t | |
19066 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
19067 | { | |
19068 | LPFC_MBOXQ_t *mboxq = NULL; | |
19069 | struct lpfc_dmabuf *mp = NULL; | |
19070 | struct lpfc_mqe *mqe; | |
19071 | uint32_t data_length = 0; | |
19072 | int rc; | |
19073 | ||
19074 | if (!rgn23_data) | |
19075 | return 0; | |
19076 | ||
19077 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
19078 | if (!mboxq) { | |
19079 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
19080 | "3105 failed to allocate mailbox memory\n"); | |
19081 | return 0; | |
19082 | } | |
19083 | ||
19084 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
19085 | goto out; | |
19086 | mqe = &mboxq->u.mqe; | |
3e1f0718 | 19087 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
026abb87 JS |
19088 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
19089 | if (rc) | |
19090 | goto out; | |
19091 | data_length = mqe->un.mb_words[5]; | |
19092 | if (data_length == 0) | |
19093 | goto out; | |
19094 | if (data_length > DMP_RGN23_SIZE) { | |
19095 | data_length = 0; | |
19096 | goto out; | |
19097 | } | |
19098 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
19099 | out: | |
19100 | mempool_free(mboxq, phba->mbox_mem_pool); | |
19101 | if (mp) { | |
19102 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
19103 | kfree(mp); | |
19104 | } | |
19105 | return data_length; | |
19106 | } | |
19107 | ||
19108 | /** | |
19109 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
19110 | * @phba: pointer to lpfc hba data structure. | |
19111 | * | |
19112 | * This function read region 23 and parse TLV for port status to | |
19113 | * decide if the user disaled the port. If the TLV indicates the | |
19114 | * port is disabled, the hba_flag is set accordingly. | |
19115 | **/ | |
19116 | void | |
19117 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
19118 | { | |
19119 | uint8_t *rgn23_data = NULL; | |
19120 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
19121 | uint32_t offset = 0; | |
19122 | ||
19123 | /* Get adapter Region 23 data */ | |
19124 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
19125 | if (!rgn23_data) | |
19126 | goto out; | |
19127 | ||
19128 | if (phba->sli_rev < LPFC_SLI_REV4) | |
19129 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
19130 | else { | |
19131 | if_type = bf_get(lpfc_sli_intf_if_type, | |
19132 | &phba->sli4_hba.sli_intf); | |
19133 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
19134 | goto out; | |
19135 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
19136 | } | |
a0c87cbd JS |
19137 | |
19138 | if (!data_size) | |
19139 | goto out; | |
19140 | ||
19141 | /* Check the region signature first */ | |
19142 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
19143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
19144 | "2619 Config region 23 has bad signature\n"); | |
19145 | goto out; | |
19146 | } | |
19147 | offset += 4; | |
19148 | ||
19149 | /* Check the data structure version */ | |
19150 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
19151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
19152 | "2620 Config region 23 has bad version\n"); | |
19153 | goto out; | |
19154 | } | |
19155 | offset += 4; | |
19156 | ||
19157 | /* Parse TLV entries in the region */ | |
19158 | while (offset < data_size) { | |
19159 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
19160 | break; | |
19161 | /* | |
19162 | * If the TLV is not driver specific TLV or driver id is | |
19163 | * not linux driver id, skip the record. | |
19164 | */ | |
19165 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
19166 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
19167 | (rgn23_data[offset + 3] != 0)) { | |
19168 | offset += rgn23_data[offset + 1] * 4 + 4; | |
19169 | continue; | |
19170 | } | |
19171 | ||
19172 | /* Driver found a driver specific TLV in the config region */ | |
19173 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
19174 | offset += 4; | |
19175 | tlv_offset = 0; | |
19176 | ||
19177 | /* | |
19178 | * Search for configured port state sub-TLV. | |
19179 | */ | |
19180 | while ((offset < data_size) && | |
19181 | (tlv_offset < sub_tlv_len)) { | |
19182 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
19183 | offset += 4; | |
19184 | tlv_offset += 4; | |
19185 | break; | |
19186 | } | |
19187 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
19188 | offset += rgn23_data[offset + 1] * 4 + 4; | |
19189 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
19190 | continue; | |
19191 | } | |
19192 | ||
19193 | /* This HBA contains PORT_STE configured */ | |
19194 | if (!rgn23_data[offset + 2]) | |
19195 | phba->hba_flag |= LINK_DISABLED; | |
19196 | ||
19197 | goto out; | |
19198 | } | |
19199 | } | |
026abb87 | 19200 | |
a0c87cbd | 19201 | out: |
a0c87cbd JS |
19202 | kfree(rgn23_data); |
19203 | return; | |
19204 | } | |
695a814e | 19205 | |
52d52440 JS |
19206 | /** |
19207 | * lpfc_wr_object - write an object to the firmware | |
19208 | * @phba: HBA structure that indicates port to create a queue on. | |
19209 | * @dmabuf_list: list of dmabufs to write to the port. | |
19210 | * @size: the total byte value of the objects to write to the port. | |
19211 | * @offset: the current offset to be used to start the transfer. | |
19212 | * | |
19213 | * This routine will create a wr_object mailbox command to send to the port. | |
19214 | * the mailbox command will be constructed using the dma buffers described in | |
19215 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
19216 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
19217 | * used to indicate the starting offset of the transfer and will also return | |
19218 | * the offset after the write object mailbox has completed. @size is used to | |
19219 | * determine the end of the object and whether the eof bit should be set. | |
19220 | * | |
19221 | * Return 0 is successful and offset will contain the the new offset to use | |
19222 | * for the next write. | |
19223 | * Return negative value for error cases. | |
19224 | **/ | |
19225 | int | |
19226 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
19227 | uint32_t size, uint32_t *offset) | |
19228 | { | |
19229 | struct lpfc_mbx_wr_object *wr_object; | |
19230 | LPFC_MBOXQ_t *mbox; | |
19231 | int rc = 0, i = 0; | |
19232 | uint32_t shdr_status, shdr_add_status; | |
19233 | uint32_t mbox_tmo; | |
19234 | union lpfc_sli4_cfg_shdr *shdr; | |
19235 | struct lpfc_dmabuf *dmabuf; | |
19236 | uint32_t written = 0; | |
19237 | ||
19238 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
19239 | if (!mbox) | |
19240 | return -ENOMEM; | |
19241 | ||
19242 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
19243 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
19244 | sizeof(struct lpfc_mbx_wr_object) - | |
19245 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
19246 | ||
19247 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
19248 | wr_object->u.request.write_offset = *offset; | |
19249 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
19250 | wr_object->u.request.object_name[0] = | |
19251 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
19252 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
19253 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
19254 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
19255 | break; | |
19256 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
19257 | wr_object->u.request.bde[i].addrHigh = | |
19258 | putPaddrHigh(dmabuf->phys); | |
19259 | if (written + SLI4_PAGE_SIZE >= size) { | |
19260 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
19261 | (size - written); | |
19262 | written += (size - written); | |
19263 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
19264 | } else { | |
19265 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
19266 | SLI4_PAGE_SIZE; | |
19267 | written += SLI4_PAGE_SIZE; | |
19268 | } | |
19269 | i++; | |
19270 | } | |
19271 | wr_object->u.request.bde_count = i; | |
19272 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
19273 | if (!phba->sli4_hba.intr_enable) | |
19274 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
19275 | else { | |
a183a15f | 19276 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
19277 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
19278 | } | |
19279 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
19280 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
19281 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
19282 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
19283 | if (rc != MBX_TIMEOUT) | |
19284 | mempool_free(mbox, phba->mbox_mem_pool); | |
19285 | if (shdr_status || shdr_add_status || rc) { | |
19286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
19287 | "3025 Write Object mailbox failed with " | |
19288 | "status x%x add_status x%x, mbx status x%x\n", | |
19289 | shdr_status, shdr_add_status, rc); | |
19290 | rc = -ENXIO; | |
1feb8204 | 19291 | *offset = shdr_add_status; |
52d52440 JS |
19292 | } else |
19293 | *offset += wr_object->u.response.actual_write_length; | |
19294 | return rc; | |
19295 | } | |
19296 | ||
695a814e JS |
19297 | /** |
19298 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
19299 | * @vport: pointer to vport data structure. | |
19300 | * | |
19301 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
19302 | * and REG_VPI mailbox commands associated with the vport. This function | |
19303 | * is called when driver want to restart discovery of the vport due to | |
19304 | * a Clear Virtual Link event. | |
19305 | **/ | |
19306 | void | |
19307 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
19308 | { | |
19309 | struct lpfc_hba *phba = vport->phba; | |
19310 | LPFC_MBOXQ_t *mb, *nextmb; | |
19311 | struct lpfc_dmabuf *mp; | |
78730cfe | 19312 | struct lpfc_nodelist *ndlp; |
d439d286 | 19313 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 19314 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 19315 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 19316 | uint8_t restart_loop; |
695a814e | 19317 | |
d439d286 | 19318 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
19319 | spin_lock_irq(&phba->hbalock); |
19320 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
19321 | if (mb->vport != vport) | |
19322 | continue; | |
19323 | ||
19324 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
19325 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
19326 | continue; | |
19327 | ||
d439d286 JS |
19328 | list_del(&mb->list); |
19329 | list_add_tail(&mb->list, &mbox_cmd_list); | |
19330 | } | |
19331 | /* Clean up active mailbox command with the vport */ | |
19332 | mb = phba->sli.mbox_active; | |
19333 | if (mb && (mb->vport == vport)) { | |
19334 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
19335 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
19336 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
19337 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
3e1f0718 | 19338 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
d439d286 JS |
19339 | /* Put reference count for delayed processing */ |
19340 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
19341 | /* Unregister the RPI when mailbox complete */ | |
19342 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
19343 | } | |
19344 | } | |
63e801ce JS |
19345 | /* Cleanup any mailbox completions which are not yet processed */ |
19346 | do { | |
19347 | restart_loop = 0; | |
19348 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
19349 | /* | |
19350 | * If this mailox is already processed or it is | |
19351 | * for another vport ignore it. | |
19352 | */ | |
19353 | if ((mb->vport != vport) || | |
19354 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
19355 | continue; | |
19356 | ||
19357 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
19358 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
19359 | continue; | |
19360 | ||
19361 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
19362 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
3e1f0718 | 19363 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
63e801ce JS |
19364 | /* Unregister the RPI when mailbox complete */ |
19365 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
19366 | restart_loop = 1; | |
19367 | spin_unlock_irq(&phba->hbalock); | |
19368 | spin_lock(shost->host_lock); | |
19369 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
19370 | spin_unlock(shost->host_lock); | |
19371 | spin_lock_irq(&phba->hbalock); | |
19372 | break; | |
19373 | } | |
19374 | } | |
19375 | } while (restart_loop); | |
19376 | ||
d439d286 JS |
19377 | spin_unlock_irq(&phba->hbalock); |
19378 | ||
19379 | /* Release the cleaned-up mailbox commands */ | |
19380 | while (!list_empty(&mbox_cmd_list)) { | |
19381 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e | 19382 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
3e1f0718 | 19383 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
695a814e JS |
19384 | if (mp) { |
19385 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
19386 | kfree(mp); | |
19387 | } | |
3e1f0718 JS |
19388 | mb->ctx_buf = NULL; |
19389 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; | |
19390 | mb->ctx_ndlp = NULL; | |
78730cfe | 19391 | if (ndlp) { |
ec21b3b0 | 19392 | spin_lock(shost->host_lock); |
589a52d6 | 19393 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 19394 | spin_unlock(shost->host_lock); |
78730cfe | 19395 | lpfc_nlp_put(ndlp); |
78730cfe | 19396 | } |
695a814e | 19397 | } |
695a814e JS |
19398 | mempool_free(mb, phba->mbox_mem_pool); |
19399 | } | |
d439d286 JS |
19400 | |
19401 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
19402 | if (act_mbx_ndlp) { | |
19403 | spin_lock(shost->host_lock); | |
19404 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
19405 | spin_unlock(shost->host_lock); | |
19406 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 19407 | } |
695a814e JS |
19408 | } |
19409 | ||
2a9bf3d0 JS |
19410 | /** |
19411 | * lpfc_drain_txq - Drain the txq | |
19412 | * @phba: Pointer to HBA context object. | |
19413 | * | |
19414 | * This function attempt to submit IOCBs on the txq | |
19415 | * to the adapter. For SLI4 adapters, the txq contains | |
19416 | * ELS IOCBs that have been deferred because the there | |
19417 | * are no SGLs. This congestion can occur with large | |
19418 | * vport counts during node discovery. | |
19419 | **/ | |
19420 | ||
19421 | uint32_t | |
19422 | lpfc_drain_txq(struct lpfc_hba *phba) | |
19423 | { | |
19424 | LIST_HEAD(completions); | |
895427bd | 19425 | struct lpfc_sli_ring *pring; |
2e706377 | 19426 | struct lpfc_iocbq *piocbq = NULL; |
2a9bf3d0 JS |
19427 | unsigned long iflags = 0; |
19428 | char *fail_msg = NULL; | |
19429 | struct lpfc_sglq *sglq; | |
205e8240 | 19430 | union lpfc_wqe128 wqe; |
a2fc4aef | 19431 | uint32_t txq_cnt = 0; |
dc19e3b4 | 19432 | struct lpfc_queue *wq; |
2a9bf3d0 | 19433 | |
dc19e3b4 JS |
19434 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
19435 | /* MDS WQE are posted only to first WQ*/ | |
19436 | wq = phba->sli4_hba.fcp_wq[0]; | |
19437 | if (unlikely(!wq)) | |
19438 | return 0; | |
19439 | pring = wq->pring; | |
19440 | } else { | |
19441 | wq = phba->sli4_hba.els_wq; | |
19442 | if (unlikely(!wq)) | |
19443 | return 0; | |
19444 | pring = lpfc_phba_elsring(phba); | |
19445 | } | |
19446 | ||
19447 | if (unlikely(!pring) || list_empty(&pring->txq)) | |
1234a6d5 | 19448 | return 0; |
895427bd | 19449 | |
398d81c9 | 19450 | spin_lock_irqsave(&pring->ring_lock, iflags); |
0e9bb8d7 JS |
19451 | list_for_each_entry(piocbq, &pring->txq, list) { |
19452 | txq_cnt++; | |
19453 | } | |
19454 | ||
19455 | if (txq_cnt > pring->txq_max) | |
19456 | pring->txq_max = txq_cnt; | |
2a9bf3d0 | 19457 | |
398d81c9 | 19458 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 19459 | |
0e9bb8d7 | 19460 | while (!list_empty(&pring->txq)) { |
398d81c9 | 19461 | spin_lock_irqsave(&pring->ring_lock, iflags); |
2a9bf3d0 | 19462 | |
19ca7609 | 19463 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
a629852a | 19464 | if (!piocbq) { |
398d81c9 | 19465 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
a629852a JS |
19466 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
19467 | "2823 txq empty and txq_cnt is %d\n ", | |
0e9bb8d7 | 19468 | txq_cnt); |
a629852a JS |
19469 | break; |
19470 | } | |
895427bd | 19471 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
2a9bf3d0 | 19472 | if (!sglq) { |
19ca7609 | 19473 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
398d81c9 | 19474 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 | 19475 | break; |
2a9bf3d0 | 19476 | } |
0e9bb8d7 | 19477 | txq_cnt--; |
2a9bf3d0 JS |
19478 | |
19479 | /* The xri and iocb resources secured, | |
19480 | * attempt to issue request | |
19481 | */ | |
6d368e53 | 19482 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
19483 | piocbq->sli4_xritag = sglq->sli4_xritag; |
19484 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
19485 | fail_msg = "to convert bpl to sgl"; | |
205e8240 | 19486 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
2a9bf3d0 | 19487 | fail_msg = "to convert iocb to wqe"; |
dc19e3b4 | 19488 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
2a9bf3d0 JS |
19489 | fail_msg = " - Wq is full"; |
19490 | else | |
19491 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
19492 | ||
19493 | if (fail_msg) { | |
19494 | /* Failed means we can't issue and need to cancel */ | |
19495 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
19496 | "2822 IOCB failed %s iotag 0x%x " | |
19497 | "xri 0x%x\n", | |
19498 | fail_msg, | |
19499 | piocbq->iotag, piocbq->sli4_xritag); | |
19500 | list_add_tail(&piocbq->list, &completions); | |
19501 | } | |
398d81c9 | 19502 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
2a9bf3d0 JS |
19503 | } |
19504 | ||
2a9bf3d0 JS |
19505 | /* Cancel all the IOCBs that cannot be issued */ |
19506 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
19507 | IOERR_SLI_ABORTED); | |
19508 | ||
0e9bb8d7 | 19509 | return txq_cnt; |
2a9bf3d0 | 19510 | } |
895427bd JS |
19511 | |
19512 | /** | |
19513 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. | |
19514 | * @phba: Pointer to HBA context object. | |
19515 | * @pwqe: Pointer to command WQE. | |
19516 | * @sglq: Pointer to the scatter gather queue object. | |
19517 | * | |
19518 | * This routine converts the bpl or bde that is in the WQE | |
19519 | * to a sgl list for the sli4 hardware. The physical address | |
19520 | * of the bpl/bde is converted back to a virtual address. | |
19521 | * If the WQE contains a BPL then the list of BDE's is | |
19522 | * converted to sli4_sge's. If the WQE contains a single | |
19523 | * BDE then it is converted to a single sli_sge. | |
19524 | * The WQE is still in cpu endianness so the contents of | |
19525 | * the bpl can be used without byte swapping. | |
19526 | * | |
19527 | * Returns valid XRI = Success, NO_XRI = Failure. | |
19528 | */ | |
19529 | static uint16_t | |
19530 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, | |
19531 | struct lpfc_sglq *sglq) | |
19532 | { | |
19533 | uint16_t xritag = NO_XRI; | |
19534 | struct ulp_bde64 *bpl = NULL; | |
19535 | struct ulp_bde64 bde; | |
19536 | struct sli4_sge *sgl = NULL; | |
19537 | struct lpfc_dmabuf *dmabuf; | |
205e8240 | 19538 | union lpfc_wqe128 *wqe; |
895427bd JS |
19539 | int numBdes = 0; |
19540 | int i = 0; | |
19541 | uint32_t offset = 0; /* accumulated offset in the sg request list */ | |
19542 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
19543 | uint32_t cmd; | |
19544 | ||
19545 | if (!pwqeq || !sglq) | |
19546 | return xritag; | |
19547 | ||
19548 | sgl = (struct sli4_sge *)sglq->sgl; | |
19549 | wqe = &pwqeq->wqe; | |
19550 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; | |
19551 | ||
19552 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); | |
19553 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) | |
19554 | return sglq->sli4_xritag; | |
19555 | numBdes = pwqeq->rsvd2; | |
19556 | if (numBdes) { | |
19557 | /* The addrHigh and addrLow fields within the WQE | |
19558 | * have not been byteswapped yet so there is no | |
19559 | * need to swap them back. | |
19560 | */ | |
19561 | if (pwqeq->context3) | |
19562 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; | |
19563 | else | |
19564 | return xritag; | |
19565 | ||
19566 | bpl = (struct ulp_bde64 *)dmabuf->virt; | |
19567 | if (!bpl) | |
19568 | return xritag; | |
19569 | ||
19570 | for (i = 0; i < numBdes; i++) { | |
19571 | /* Should already be byte swapped. */ | |
19572 | sgl->addr_hi = bpl->addrHigh; | |
19573 | sgl->addr_lo = bpl->addrLow; | |
19574 | ||
19575 | sgl->word2 = le32_to_cpu(sgl->word2); | |
19576 | if ((i+1) == numBdes) | |
19577 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
19578 | else | |
19579 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
19580 | /* swap the size field back to the cpu so we | |
19581 | * can assign it to the sgl. | |
19582 | */ | |
19583 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
19584 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
19585 | /* The offsets in the sgl need to be accumulated | |
19586 | * separately for the request and reply lists. | |
19587 | * The request is always first, the reply follows. | |
19588 | */ | |
19589 | switch (cmd) { | |
19590 | case CMD_GEN_REQUEST64_WQE: | |
19591 | /* add up the reply sg entries */ | |
19592 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
19593 | inbound++; | |
19594 | /* first inbound? reset the offset */ | |
19595 | if (inbound == 1) | |
19596 | offset = 0; | |
19597 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
19598 | bf_set(lpfc_sli4_sge_type, sgl, | |
19599 | LPFC_SGE_TYPE_DATA); | |
19600 | offset += bde.tus.f.bdeSize; | |
19601 | break; | |
19602 | case CMD_FCP_TRSP64_WQE: | |
19603 | bf_set(lpfc_sli4_sge_offset, sgl, 0); | |
19604 | bf_set(lpfc_sli4_sge_type, sgl, | |
19605 | LPFC_SGE_TYPE_DATA); | |
19606 | break; | |
19607 | case CMD_FCP_TSEND64_WQE: | |
19608 | case CMD_FCP_TRECEIVE64_WQE: | |
19609 | bf_set(lpfc_sli4_sge_type, sgl, | |
19610 | bpl->tus.f.bdeFlags); | |
19611 | if (i < 3) | |
19612 | offset = 0; | |
19613 | else | |
19614 | offset += bde.tus.f.bdeSize; | |
19615 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
19616 | break; | |
19617 | } | |
19618 | sgl->word2 = cpu_to_le32(sgl->word2); | |
19619 | bpl++; | |
19620 | sgl++; | |
19621 | } | |
19622 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { | |
19623 | /* The addrHigh and addrLow fields of the BDE have not | |
19624 | * been byteswapped yet so they need to be swapped | |
19625 | * before putting them in the sgl. | |
19626 | */ | |
19627 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); | |
19628 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); | |
19629 | sgl->word2 = le32_to_cpu(sgl->word2); | |
19630 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
19631 | sgl->word2 = cpu_to_le32(sgl->word2); | |
19632 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); | |
19633 | } | |
19634 | return sglq->sli4_xritag; | |
19635 | } | |
19636 | ||
19637 | /** | |
19638 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) | |
19639 | * @phba: Pointer to HBA context object. | |
19640 | * @ring_number: Base sli ring number | |
19641 | * @pwqe: Pointer to command WQE. | |
19642 | **/ | |
19643 | int | |
19644 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, | |
19645 | struct lpfc_iocbq *pwqe) | |
19646 | { | |
205e8240 | 19647 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
f358dd0c | 19648 | struct lpfc_nvmet_rcv_ctx *ctxp; |
895427bd JS |
19649 | struct lpfc_queue *wq; |
19650 | struct lpfc_sglq *sglq; | |
19651 | struct lpfc_sli_ring *pring; | |
19652 | unsigned long iflags; | |
cd22d605 | 19653 | uint32_t ret = 0; |
895427bd JS |
19654 | |
19655 | /* NVME_LS and NVME_LS ABTS requests. */ | |
19656 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { | |
19657 | pring = phba->sli4_hba.nvmels_wq->pring; | |
19658 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
19659 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); | |
19660 | if (!sglq) { | |
19661 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
19662 | return WQE_BUSY; | |
19663 | } | |
19664 | pwqe->sli4_lxritag = sglq->sli4_lxritag; | |
19665 | pwqe->sli4_xritag = sglq->sli4_xritag; | |
19666 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { | |
19667 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
19668 | return WQE_ERROR; | |
19669 | } | |
19670 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, | |
19671 | pwqe->sli4_xritag); | |
cd22d605 DK |
19672 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
19673 | if (ret) { | |
895427bd | 19674 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
cd22d605 | 19675 | return ret; |
895427bd | 19676 | } |
cd22d605 | 19677 | |
895427bd JS |
19678 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
19679 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
19680 | return 0; | |
19681 | } | |
19682 | ||
19683 | /* NVME_FCREQ and NVME_ABTS requests */ | |
19684 | if (pwqe->iocb_flag & LPFC_IO_NVME) { | |
19685 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ | |
19686 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; | |
19687 | ||
19688 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
19689 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; | |
19690 | bf_set(wqe_cqid, &wqe->generic.wqe_com, | |
19691 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); | |
cd22d605 DK |
19692 | ret = lpfc_sli4_wq_put(wq, wqe); |
19693 | if (ret) { | |
895427bd | 19694 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
cd22d605 | 19695 | return ret; |
895427bd JS |
19696 | } |
19697 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); | |
19698 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
19699 | return 0; | |
19700 | } | |
19701 | ||
f358dd0c JS |
19702 | /* NVMET requests */ |
19703 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { | |
19704 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ | |
19705 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; | |
19706 | ||
19707 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
19708 | ctxp = pwqe->context2; | |
6c621a22 | 19709 | sglq = ctxp->ctxbuf->sglq; |
f358dd0c JS |
19710 | if (pwqe->sli4_xritag == NO_XRI) { |
19711 | pwqe->sli4_lxritag = sglq->sli4_lxritag; | |
19712 | pwqe->sli4_xritag = sglq->sli4_xritag; | |
19713 | } | |
19714 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, | |
19715 | pwqe->sli4_xritag); | |
19716 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; | |
19717 | bf_set(wqe_cqid, &wqe->generic.wqe_com, | |
19718 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); | |
cd22d605 DK |
19719 | ret = lpfc_sli4_wq_put(wq, wqe); |
19720 | if (ret) { | |
f358dd0c | 19721 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
cd22d605 | 19722 | return ret; |
f358dd0c JS |
19723 | } |
19724 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); | |
19725 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
19726 | return 0; | |
19727 | } | |
895427bd JS |
19728 | return WQE_ERROR; |
19729 | } |