]>
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. * |
1b32f6aa | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
26 | ||
91886523 | 27 | #include <scsi/scsi.h> |
dea3101e JB |
28 | #include <scsi/scsi_cmnd.h> |
29 | #include <scsi/scsi_device.h> | |
30 | #include <scsi/scsi_host.h> | |
f888ba3c | 31 | #include <scsi/scsi_transport_fc.h> |
dea3101e JB |
32 | |
33 | #include "lpfc_hw.h" | |
34 | #include "lpfc_sli.h" | |
35 | #include "lpfc_disc.h" | |
36 | #include "lpfc_scsi.h" | |
37 | #include "lpfc.h" | |
38 | #include "lpfc_crtn.h" | |
39 | #include "lpfc_logmsg.h" | |
40 | #include "lpfc_compat.h" | |
858c9f6c | 41 | #include "lpfc_debugfs.h" |
dea3101e JB |
42 | |
43 | /* | |
44 | * Define macro to log: Mailbox command x%x cannot issue Data | |
45 | * This allows multiple uses of lpfc_msgBlk0311 | |
46 | * w/o perturbing log msg utility. | |
47 | */ | |
92d7f7b0 | 48 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ |
dea3101e JB |
49 | lpfc_printf_log(phba, \ |
50 | KERN_INFO, \ | |
51 | LOG_MBOX | LOG_SLI, \ | |
e8b62011 | 52 | "(%d):0311 Mailbox command x%x cannot " \ |
92d7f7b0 | 53 | "issue Data: x%x x%x x%x\n", \ |
92d7f7b0 JS |
54 | pmbox->vport ? pmbox->vport->vpi : 0, \ |
55 | pmbox->mb.mbxCommand, \ | |
2e0fef85 | 56 | phba->pport->port_state, \ |
dea3101e | 57 | psli->sli_flag, \ |
2e0fef85 | 58 | flag) |
dea3101e JB |
59 | |
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 | ||
e59058c4 JS |
69 | /** |
70 | * lpfc_cmd_iocb: Get next command iocb entry in the ring. | |
71 | * @phba: Pointer to HBA context object. | |
72 | * @pring: Pointer to driver SLI ring object. | |
73 | * | |
74 | * This function returns pointer to next command iocb entry | |
75 | * in the command ring. The caller must hold hbalock to prevent | |
76 | * other threads consume the next command iocb. | |
77 | * SLI-2/SLI-3 provide different sized iocbs. | |
78 | **/ | |
ed957684 JS |
79 | static inline IOCB_t * |
80 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
81 | { | |
82 | return (IOCB_t *) (((char *) pring->cmdringaddr) + | |
83 | pring->cmdidx * phba->iocb_cmd_size); | |
84 | } | |
85 | ||
e59058c4 JS |
86 | /** |
87 | * lpfc_resp_iocb: Get next response iocb entry in the ring. | |
88 | * @phba: Pointer to HBA context object. | |
89 | * @pring: Pointer to driver SLI ring object. | |
90 | * | |
91 | * This function returns pointer to next response iocb entry | |
92 | * in the response ring. The caller must hold hbalock to make sure | |
93 | * that no other thread consume the next response iocb. | |
94 | * SLI-2/SLI-3 provide different sized iocbs. | |
95 | **/ | |
ed957684 JS |
96 | static inline IOCB_t * |
97 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
98 | { | |
99 | return (IOCB_t *) (((char *) pring->rspringaddr) + | |
100 | pring->rspidx * phba->iocb_rsp_size); | |
101 | } | |
102 | ||
e59058c4 JS |
103 | /** |
104 | * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. | |
105 | * @phba: Pointer to HBA context object. | |
106 | * | |
107 | * This function is called with hbalock held. This function | |
108 | * allocates a new driver iocb object from the iocb pool. If the | |
109 | * allocation is successful, it returns pointer to the newly | |
110 | * allocated iocb object else it returns NULL. | |
111 | **/ | |
2e0fef85 JS |
112 | static struct lpfc_iocbq * |
113 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
0bd4ca25 JSEC |
114 | { |
115 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
116 | struct lpfc_iocbq * iocbq = NULL; | |
117 | ||
118 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
119 | return iocbq; | |
120 | } | |
121 | ||
e59058c4 JS |
122 | /** |
123 | * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool. | |
124 | * @phba: Pointer to HBA context object. | |
125 | * | |
126 | * This function is called with no lock held. This function | |
127 | * allocates a new driver iocb object from the iocb pool. If the | |
128 | * allocation is successful, it returns pointer to the newly | |
129 | * allocated iocb object else it returns NULL. | |
130 | **/ | |
2e0fef85 JS |
131 | struct lpfc_iocbq * |
132 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
133 | { | |
134 | struct lpfc_iocbq * iocbq = NULL; | |
135 | unsigned long iflags; | |
136 | ||
137 | spin_lock_irqsave(&phba->hbalock, iflags); | |
138 | iocbq = __lpfc_sli_get_iocbq(phba); | |
139 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
140 | return iocbq; | |
141 | } | |
142 | ||
e59058c4 JS |
143 | /** |
144 | * __lpfc_sli_release_iocbq: Release iocb to the iocb pool. | |
145 | * @phba: Pointer to HBA context object. | |
146 | * @iocbq: Pointer to driver iocb object. | |
147 | * | |
148 | * This function is called with hbalock held to release driver | |
149 | * iocb object to the iocb pool. The iotag in the iocb object | |
150 | * does not change for each use of the iocb object. This function | |
151 | * clears all other fields of the iocb object when it is freed. | |
152 | **/ | |
a6ababd2 | 153 | static void |
2e0fef85 | 154 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 155 | { |
2e0fef85 | 156 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
157 | |
158 | /* | |
159 | * Clean all volatile data fields, preserve iotag and node struct. | |
160 | */ | |
161 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
162 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
163 | } | |
164 | ||
e59058c4 JS |
165 | /** |
166 | * lpfc_sli_release_iocbq: Release iocb to the iocb pool. | |
167 | * @phba: Pointer to HBA context object. | |
168 | * @iocbq: Pointer to driver iocb object. | |
169 | * | |
170 | * This function is called with no lock held to release the iocb to | |
171 | * iocb pool. | |
172 | **/ | |
2e0fef85 JS |
173 | void |
174 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
175 | { | |
176 | unsigned long iflags; | |
177 | ||
178 | /* | |
179 | * Clean all volatile data fields, preserve iotag and node struct. | |
180 | */ | |
181 | spin_lock_irqsave(&phba->hbalock, iflags); | |
182 | __lpfc_sli_release_iocbq(phba, iocbq); | |
183 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
184 | } | |
185 | ||
e59058c4 JS |
186 | /** |
187 | * lpfc_sli_iocb_cmd_type: Get the iocb type. | |
188 | * @iocb_cmnd : iocb command code. | |
189 | * | |
190 | * This function is called by ring event handler function to get the iocb type. | |
191 | * This function translates the iocb command to an iocb command type used to | |
192 | * decide the final disposition of each completed IOCB. | |
193 | * The function returns | |
194 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
195 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
196 | * LPFC_ABORT_IOCB if it is an abort iocb | |
197 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
198 | * | |
199 | * The caller is not required to hold any lock. | |
200 | **/ | |
dea3101e JB |
201 | static lpfc_iocb_type |
202 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
203 | { | |
204 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
205 | ||
206 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
207 | return 0; | |
208 | ||
209 | switch (iocb_cmnd) { | |
210 | case CMD_XMIT_SEQUENCE_CR: | |
211 | case CMD_XMIT_SEQUENCE_CX: | |
212 | case CMD_XMIT_BCAST_CN: | |
213 | case CMD_XMIT_BCAST_CX: | |
214 | case CMD_ELS_REQUEST_CR: | |
215 | case CMD_ELS_REQUEST_CX: | |
216 | case CMD_CREATE_XRI_CR: | |
217 | case CMD_CREATE_XRI_CX: | |
218 | case CMD_GET_RPI_CN: | |
219 | case CMD_XMIT_ELS_RSP_CX: | |
220 | case CMD_GET_RPI_CR: | |
221 | case CMD_FCP_IWRITE_CR: | |
222 | case CMD_FCP_IWRITE_CX: | |
223 | case CMD_FCP_IREAD_CR: | |
224 | case CMD_FCP_IREAD_CX: | |
225 | case CMD_FCP_ICMND_CR: | |
226 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
227 | case CMD_FCP_TSEND_CX: |
228 | case CMD_FCP_TRSP_CX: | |
229 | case CMD_FCP_TRECEIVE_CX: | |
230 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
231 | case CMD_ADAPTER_MSG: |
232 | case CMD_ADAPTER_DUMP: | |
233 | case CMD_XMIT_SEQUENCE64_CR: | |
234 | case CMD_XMIT_SEQUENCE64_CX: | |
235 | case CMD_XMIT_BCAST64_CN: | |
236 | case CMD_XMIT_BCAST64_CX: | |
237 | case CMD_ELS_REQUEST64_CR: | |
238 | case CMD_ELS_REQUEST64_CX: | |
239 | case CMD_FCP_IWRITE64_CR: | |
240 | case CMD_FCP_IWRITE64_CX: | |
241 | case CMD_FCP_IREAD64_CR: | |
242 | case CMD_FCP_IREAD64_CX: | |
243 | case CMD_FCP_ICMND64_CR: | |
244 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
245 | case CMD_FCP_TSEND64_CX: |
246 | case CMD_FCP_TRSP64_CX: | |
247 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
248 | case CMD_GEN_REQUEST64_CR: |
249 | case CMD_GEN_REQUEST64_CX: | |
250 | case CMD_XMIT_ELS_RSP64_CX: | |
251 | type = LPFC_SOL_IOCB; | |
252 | break; | |
253 | case CMD_ABORT_XRI_CN: | |
254 | case CMD_ABORT_XRI_CX: | |
255 | case CMD_CLOSE_XRI_CN: | |
256 | case CMD_CLOSE_XRI_CX: | |
257 | case CMD_XRI_ABORTED_CX: | |
258 | case CMD_ABORT_MXRI64_CN: | |
259 | type = LPFC_ABORT_IOCB; | |
260 | break; | |
261 | case CMD_RCV_SEQUENCE_CX: | |
262 | case CMD_RCV_ELS_REQ_CX: | |
263 | case CMD_RCV_SEQUENCE64_CX: | |
264 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 265 | case CMD_ASYNC_STATUS: |
ed957684 JS |
266 | case CMD_IOCB_RCV_SEQ64_CX: |
267 | case CMD_IOCB_RCV_ELS64_CX: | |
268 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 269 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
270 | type = LPFC_UNSOL_IOCB; |
271 | break; | |
3163f725 JS |
272 | case CMD_IOCB_XMIT_MSEQ64_CR: |
273 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
274 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
275 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
276 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
277 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
278 | case CMD_IOCB_RET_HBQE64_CN: | |
279 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
280 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
281 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
282 | case CMD_IOCB_LOGENTRY_CN: | |
283 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
284 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 285 | __func__, iocb_cmnd); |
3163f725 JS |
286 | type = LPFC_UNKNOWN_IOCB; |
287 | break; | |
dea3101e JB |
288 | default: |
289 | type = LPFC_UNKNOWN_IOCB; | |
290 | break; | |
291 | } | |
292 | ||
293 | return type; | |
294 | } | |
295 | ||
e59058c4 JS |
296 | /** |
297 | * lpfc_sli_ring_map: Issue config_ring mbox for all rings. | |
298 | * @phba: Pointer to HBA context object. | |
299 | * | |
300 | * This function is called from SLI initialization code | |
301 | * to configure every ring of the HBA's SLI interface. The | |
302 | * caller is not required to hold any lock. This function issues | |
303 | * a config_ring mailbox command for each ring. | |
304 | * This function returns zero if successful else returns a negative | |
305 | * error code. | |
306 | **/ | |
dea3101e | 307 | static int |
ed957684 | 308 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
309 | { |
310 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
311 | LPFC_MBOXQ_t *pmb; |
312 | MAILBOX_t *pmbox; | |
313 | int i, rc, ret = 0; | |
dea3101e | 314 | |
ed957684 JS |
315 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
316 | if (!pmb) | |
317 | return -ENOMEM; | |
318 | pmbox = &pmb->mb; | |
319 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
dea3101e | 320 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
321 | lpfc_config_ring(phba, i, pmb); |
322 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
323 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 325 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
326 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
327 | "ring %d\n", | |
e8b62011 JS |
328 | rc, pmbox->mbxCommand, |
329 | pmbox->mbxStatus, i); | |
2e0fef85 | 330 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
331 | ret = -ENXIO; |
332 | break; | |
dea3101e JB |
333 | } |
334 | } | |
ed957684 JS |
335 | mempool_free(pmb, phba->mbox_mem_pool); |
336 | return ret; | |
dea3101e JB |
337 | } |
338 | ||
e59058c4 JS |
339 | /** |
340 | * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq. | |
341 | * @phba: Pointer to HBA context object. | |
342 | * @pring: Pointer to driver SLI ring object. | |
343 | * @piocb: Pointer to the driver iocb object. | |
344 | * | |
345 | * This function is called with hbalock held. The function adds the | |
346 | * new iocb to txcmplq of the given ring. This function always returns | |
347 | * 0. If this function is called for ELS ring, this function checks if | |
348 | * there is a vport associated with the ELS command. This function also | |
349 | * starts els_tmofunc timer if this is an ELS command. | |
350 | **/ | |
dea3101e | 351 | static int |
2e0fef85 JS |
352 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
353 | struct lpfc_iocbq *piocb) | |
dea3101e | 354 | { |
dea3101e JB |
355 | list_add_tail(&piocb->list, &pring->txcmplq); |
356 | pring->txcmplq_cnt++; | |
92d7f7b0 JS |
357 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
358 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
359 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
360 | if (!piocb->vport) | |
361 | BUG(); | |
362 | else | |
363 | mod_timer(&piocb->vport->els_tmofunc, | |
364 | jiffies + HZ * (phba->fc_ratov << 1)); | |
365 | } | |
366 | ||
dea3101e | 367 | |
2e0fef85 | 368 | return 0; |
dea3101e JB |
369 | } |
370 | ||
e59058c4 JS |
371 | /** |
372 | * lpfc_sli_ringtx_get: Get first element of the txq. | |
373 | * @phba: Pointer to HBA context object. | |
374 | * @pring: Pointer to driver SLI ring object. | |
375 | * | |
376 | * This function is called with hbalock held to get next | |
377 | * iocb in txq of the given ring. If there is any iocb in | |
378 | * the txq, the function returns first iocb in the list after | |
379 | * removing the iocb from the list, else it returns NULL. | |
380 | **/ | |
dea3101e | 381 | static struct lpfc_iocbq * |
2e0fef85 | 382 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 383 | { |
dea3101e JB |
384 | struct lpfc_iocbq *cmd_iocb; |
385 | ||
858c9f6c JS |
386 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
387 | if (cmd_iocb != NULL) | |
dea3101e | 388 | pring->txq_cnt--; |
2e0fef85 | 389 | return cmd_iocb; |
dea3101e JB |
390 | } |
391 | ||
e59058c4 JS |
392 | /** |
393 | * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring. | |
394 | * @phba: Pointer to HBA context object. | |
395 | * @pring: Pointer to driver SLI ring object. | |
396 | * | |
397 | * This function is called with hbalock held and the caller must post the | |
398 | * iocb without releasing the lock. If the caller releases the lock, | |
399 | * iocb slot returned by the function is not guaranteed to be available. | |
400 | * The function returns pointer to the next available iocb slot if there | |
401 | * is available slot in the ring, else it returns NULL. | |
402 | * If the get index of the ring is ahead of the put index, the function | |
403 | * will post an error attention event to the worker thread to take the | |
404 | * HBA to offline state. | |
405 | **/ | |
dea3101e JB |
406 | static IOCB_t * |
407 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
408 | { | |
ed957684 JS |
409 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
410 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : | |
411 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; | |
dea3101e | 412 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e JB |
413 | |
414 | if ((pring->next_cmdidx == pring->cmdidx) && | |
415 | (++pring->next_cmdidx >= max_cmd_idx)) | |
416 | pring->next_cmdidx = 0; | |
417 | ||
418 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
419 | ||
420 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
421 | ||
422 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
423 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 424 | "0315 Ring %d issue: portCmdGet %d " |
dea3101e | 425 | "is bigger then cmd ring %d\n", |
e8b62011 | 426 | pring->ringno, |
dea3101e JB |
427 | pring->local_getidx, max_cmd_idx); |
428 | ||
2e0fef85 | 429 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
430 | /* |
431 | * All error attention handlers are posted to | |
432 | * worker thread | |
433 | */ | |
434 | phba->work_ha |= HA_ERATT; | |
435 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 436 | |
5e9d9b82 | 437 | lpfc_worker_wake_up(phba); |
dea3101e JB |
438 | |
439 | return NULL; | |
440 | } | |
441 | ||
442 | if (pring->local_getidx == pring->next_cmdidx) | |
443 | return NULL; | |
444 | } | |
445 | ||
ed957684 | 446 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
447 | } |
448 | ||
e59058c4 JS |
449 | /** |
450 | * lpfc_sli_next_iotag: Get an iotag for the iocb. | |
451 | * @phba: Pointer to HBA context object. | |
452 | * @iocbq: Pointer to driver iocb object. | |
453 | * | |
454 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
455 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
456 | * array and assigns a new iotag. | |
457 | * The function returns the allocated iotag if successful, else returns zero. | |
458 | * Zero is not a valid iotag. | |
459 | * The caller is not required to hold any lock. | |
460 | **/ | |
604a3e30 | 461 | uint16_t |
2e0fef85 | 462 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 463 | { |
2e0fef85 JS |
464 | struct lpfc_iocbq **new_arr; |
465 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
466 | size_t new_len; |
467 | struct lpfc_sli *psli = &phba->sli; | |
468 | uint16_t iotag; | |
dea3101e | 469 | |
2e0fef85 | 470 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
471 | iotag = psli->last_iotag; |
472 | if(++iotag < psli->iocbq_lookup_len) { | |
473 | psli->last_iotag = iotag; | |
474 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 475 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
476 | iocbq->iotag = iotag; |
477 | return iotag; | |
2e0fef85 | 478 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
479 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
480 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
481 | spin_unlock_irq(&phba->hbalock); |
482 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
483 | GFP_KERNEL); |
484 | if (new_arr) { | |
2e0fef85 | 485 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
486 | old_arr = psli->iocbq_lookup; |
487 | if (new_len <= psli->iocbq_lookup_len) { | |
488 | /* highly unprobable case */ | |
489 | kfree(new_arr); | |
490 | iotag = psli->last_iotag; | |
491 | if(++iotag < psli->iocbq_lookup_len) { | |
492 | psli->last_iotag = iotag; | |
493 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 494 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
495 | iocbq->iotag = iotag; |
496 | return iotag; | |
497 | } | |
2e0fef85 | 498 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
499 | return 0; |
500 | } | |
501 | if (psli->iocbq_lookup) | |
502 | memcpy(new_arr, old_arr, | |
503 | ((psli->last_iotag + 1) * | |
311464ec | 504 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
505 | psli->iocbq_lookup = new_arr; |
506 | psli->iocbq_lookup_len = new_len; | |
507 | psli->last_iotag = iotag; | |
508 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 509 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
510 | iocbq->iotag = iotag; |
511 | kfree(old_arr); | |
512 | return iotag; | |
513 | } | |
8f6d98d2 | 514 | } else |
2e0fef85 | 515 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 516 | |
604a3e30 | 517 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
e8b62011 JS |
518 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
519 | psli->last_iotag); | |
dea3101e | 520 | |
604a3e30 | 521 | return 0; |
dea3101e JB |
522 | } |
523 | ||
e59058c4 JS |
524 | /** |
525 | * lpfc_sli_submit_iocb: Submit an iocb to the firmware. | |
526 | * @phba: Pointer to HBA context object. | |
527 | * @pring: Pointer to driver SLI ring object. | |
528 | * @iocb: Pointer to iocb slot in the ring. | |
529 | * @nextiocb: Pointer to driver iocb object which need to be | |
530 | * posted to firmware. | |
531 | * | |
532 | * This function is called with hbalock held to post a new iocb to | |
533 | * the firmware. This function copies the new iocb to ring iocb slot and | |
534 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
535 | * a completion call back for this iocb else the function will free the | |
536 | * iocb object. | |
537 | **/ | |
dea3101e JB |
538 | static void |
539 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
540 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
541 | { | |
542 | /* | |
604a3e30 | 543 | * Set up an iotag |
dea3101e | 544 | */ |
604a3e30 | 545 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 546 | |
a58cbd52 JS |
547 | if (pring->ringno == LPFC_ELS_RING) { |
548 | lpfc_debugfs_slow_ring_trc(phba, | |
549 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
550 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
551 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
552 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
553 | } | |
554 | ||
dea3101e JB |
555 | /* |
556 | * Issue iocb command to adapter | |
557 | */ | |
92d7f7b0 | 558 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
559 | wmb(); |
560 | pring->stats.iocb_cmd++; | |
561 | ||
562 | /* | |
563 | * If there is no completion routine to call, we can release the | |
564 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
565 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
566 | */ | |
567 | if (nextiocb->iocb_cmpl) | |
568 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 569 | else |
2e0fef85 | 570 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
571 | |
572 | /* | |
573 | * Let the HBA know what IOCB slot will be the next one the | |
574 | * driver will put a command into. | |
575 | */ | |
576 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 577 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e JB |
578 | } |
579 | ||
e59058c4 JS |
580 | /** |
581 | * lpfc_sli_update_full_ring: Update the chip attention register. | |
582 | * @phba: Pointer to HBA context object. | |
583 | * @pring: Pointer to driver SLI ring object. | |
584 | * | |
585 | * The caller is not required to hold any lock for calling this function. | |
586 | * This function updates the chip attention bits for the ring to inform firmware | |
587 | * that there are pending work to be done for this ring and requests an | |
588 | * interrupt when there is space available in the ring. This function is | |
589 | * called when the driver is unable to post more iocbs to the ring due | |
590 | * to unavailability of space in the ring. | |
591 | **/ | |
dea3101e | 592 | static void |
2e0fef85 | 593 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
594 | { |
595 | int ringno = pring->ringno; | |
596 | ||
597 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
598 | ||
599 | wmb(); | |
600 | ||
601 | /* | |
602 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
603 | * The HBA will tell us when an IOCB entry is available. | |
604 | */ | |
605 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
606 | readl(phba->CAregaddr); /* flush */ | |
607 | ||
608 | pring->stats.iocb_cmd_full++; | |
609 | } | |
610 | ||
e59058c4 JS |
611 | /** |
612 | * lpfc_sli_update_ring: Update chip attention register. | |
613 | * @phba: Pointer to HBA context object. | |
614 | * @pring: Pointer to driver SLI ring object. | |
615 | * | |
616 | * This function updates the chip attention register bit for the | |
617 | * given ring to inform HBA that there is more work to be done | |
618 | * in this ring. The caller is not required to hold any lock. | |
619 | **/ | |
dea3101e | 620 | static void |
2e0fef85 | 621 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
622 | { |
623 | int ringno = pring->ringno; | |
624 | ||
625 | /* | |
626 | * Tell the HBA that there is work to do in this ring. | |
627 | */ | |
628 | wmb(); | |
629 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
630 | readl(phba->CAregaddr); /* flush */ | |
631 | } | |
632 | ||
e59058c4 JS |
633 | /** |
634 | * lpfc_sli_resume_iocb: Process iocbs in the txq. | |
635 | * @phba: Pointer to HBA context object. | |
636 | * @pring: Pointer to driver SLI ring object. | |
637 | * | |
638 | * This function is called with hbalock held to post pending iocbs | |
639 | * in the txq to the firmware. This function is called when driver | |
640 | * detects space available in the ring. | |
641 | **/ | |
dea3101e | 642 | static void |
2e0fef85 | 643 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
644 | { |
645 | IOCB_t *iocb; | |
646 | struct lpfc_iocbq *nextiocb; | |
647 | ||
648 | /* | |
649 | * Check to see if: | |
650 | * (a) there is anything on the txq to send | |
651 | * (b) link is up | |
652 | * (c) link attention events can be processed (fcp ring only) | |
653 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
654 | */ | |
655 | if (pring->txq_cnt && | |
2e0fef85 | 656 | lpfc_is_link_up(phba) && |
dea3101e | 657 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 658 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
659 | |
660 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
661 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
662 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
663 | ||
664 | if (iocb) | |
665 | lpfc_sli_update_ring(phba, pring); | |
666 | else | |
667 | lpfc_sli_update_full_ring(phba, pring); | |
668 | } | |
669 | ||
670 | return; | |
671 | } | |
672 | ||
e59058c4 JS |
673 | /** |
674 | * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ. | |
675 | * @phba: Pointer to HBA context object. | |
676 | * @hbqno: HBQ number. | |
677 | * | |
678 | * This function is called with hbalock held to get the next | |
679 | * available slot for the given HBQ. If there is free slot | |
680 | * available for the HBQ it will return pointer to the next available | |
681 | * HBQ entry else it will return NULL. | |
682 | **/ | |
a6ababd2 | 683 | static struct lpfc_hbq_entry * |
ed957684 JS |
684 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
685 | { | |
686 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
687 | ||
688 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
689 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
690 | hbqp->next_hbqPutIdx = 0; | |
691 | ||
692 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 693 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
694 | uint32_t getidx = le32_to_cpu(raw_index); |
695 | ||
696 | hbqp->local_hbqGetIdx = getidx; | |
697 | ||
698 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
699 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 700 | LOG_SLI | LOG_VPORT, |
e8b62011 | 701 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 702 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 703 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
704 | hbqp->entry_count); |
705 | ||
706 | phba->link_state = LPFC_HBA_ERROR; | |
707 | return NULL; | |
708 | } | |
709 | ||
710 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
711 | return NULL; | |
712 | } | |
713 | ||
51ef4c26 JS |
714 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
715 | hbqp->hbqPutIdx; | |
ed957684 JS |
716 | } |
717 | ||
e59058c4 JS |
718 | /** |
719 | * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers. | |
720 | * @phba: Pointer to HBA context object. | |
721 | * | |
722 | * This function is called with no lock held to free all the | |
723 | * hbq buffers while uninitializing the SLI interface. It also | |
724 | * frees the HBQ buffers returned by the firmware but not yet | |
725 | * processed by the upper layers. | |
726 | **/ | |
ed957684 JS |
727 | void |
728 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
729 | { | |
92d7f7b0 JS |
730 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
731 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 732 | unsigned long flags; |
51ef4c26 | 733 | int i, hbq_count; |
3163f725 | 734 | uint32_t hbqno; |
ed957684 | 735 | |
51ef4c26 | 736 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 737 | /* Return all memory used by all HBQs */ |
3163f725 | 738 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
739 | for (i = 0; i < hbq_count; ++i) { |
740 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
741 | &phba->hbqs[i].hbq_buffer_list, list) { | |
742 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
743 | list_del(&hbq_buf->dbuf.list); | |
744 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
745 | } | |
a8adb832 | 746 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 747 | } |
3163f725 JS |
748 | /* Return all HBQ buffer that are in-fly */ |
749 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
750 | &phba->hbqbuf_in_list, list) { | |
751 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
752 | list_del(&hbq_buf->dbuf.list); | |
753 | if (hbq_buf->tag == -1) { | |
754 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
755 | (phba, hbq_buf); | |
756 | } else { | |
757 | hbqno = hbq_buf->tag >> 16; | |
758 | if (hbqno >= LPFC_MAX_HBQS) | |
759 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
760 | (phba, hbq_buf); | |
761 | else | |
762 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
763 | hbq_buf); | |
764 | } | |
765 | } | |
766 | ||
767 | /* Mark the HBQs not in use */ | |
768 | phba->hbq_in_use = 0; | |
769 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
770 | } |
771 | ||
e59058c4 JS |
772 | /** |
773 | * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware. | |
774 | * @phba: Pointer to HBA context object. | |
775 | * @hbqno: HBQ number. | |
776 | * @hbq_buf: Pointer to HBQ buffer. | |
777 | * | |
778 | * This function is called with the hbalock held to post a | |
779 | * hbq buffer to the firmware. If the function finds an empty | |
780 | * slot in the HBQ, it will post the buffer. The function will return | |
781 | * pointer to the hbq entry if it successfully post the buffer | |
782 | * else it will return NULL. | |
783 | **/ | |
51ef4c26 | 784 | static struct lpfc_hbq_entry * |
ed957684 | 785 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 786 | struct hbq_dmabuf *hbq_buf) |
ed957684 JS |
787 | { |
788 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 789 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
790 | |
791 | /* Get next HBQ entry slot to use */ | |
792 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
793 | if (hbqe) { | |
794 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
795 | ||
92d7f7b0 JS |
796 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
797 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 798 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 799 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
800 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
801 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
802 | /* Sync SLIM */ | |
ed957684 JS |
803 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
804 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 805 | /* flush */ |
ed957684 | 806 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 807 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
ed957684 | 808 | } |
51ef4c26 | 809 | return hbqe; |
ed957684 JS |
810 | } |
811 | ||
e59058c4 | 812 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
813 | static struct lpfc_hbq_init lpfc_els_hbq = { |
814 | .rn = 1, | |
815 | .entry_count = 200, | |
816 | .mask_count = 0, | |
817 | .profile = 0, | |
51ef4c26 | 818 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 JS |
819 | .buffer_count = 0, |
820 | .init_count = 20, | |
821 | .add_count = 5, | |
822 | }; | |
ed957684 | 823 | |
e59058c4 | 824 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
825 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
826 | .rn = 1, | |
827 | .entry_count = 200, | |
828 | .mask_count = 0, | |
829 | .profile = 0, | |
830 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
831 | .buffer_count = 0, | |
832 | .init_count = 0, | |
833 | .add_count = 5, | |
834 | }; | |
835 | ||
e59058c4 | 836 | /* Array of HBQs */ |
78b2d852 | 837 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 838 | &lpfc_els_hbq, |
51ef4c26 | 839 | &lpfc_extra_hbq, |
92d7f7b0 | 840 | }; |
ed957684 | 841 | |
e59058c4 JS |
842 | /** |
843 | * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ. | |
844 | * @phba: Pointer to HBA context object. | |
845 | * @hbqno: HBQ number. | |
846 | * @count: Number of HBQ buffers to be posted. | |
847 | * | |
848 | * This function is called with no lock held to post more | |
849 | * hbq buffers to the given HBQ. The function returns 0 | |
850 | * when successful and returns 1 other wise. | |
851 | **/ | |
311464ec | 852 | static int |
92d7f7b0 | 853 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 854 | { |
92d7f7b0 | 855 | uint32_t i, start, end; |
3163f725 | 856 | unsigned long flags; |
92d7f7b0 | 857 | struct hbq_dmabuf *hbq_buffer; |
ed957684 | 858 | |
eafe1df9 | 859 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 860 | return 0; |
51ef4c26 | 861 | |
a8adb832 JS |
862 | start = phba->hbqs[hbqno].buffer_count; |
863 | end = count + start; | |
eafe1df9 | 864 | if (end > lpfc_hbq_defs[hbqno]->entry_count) |
92d7f7b0 | 865 | end = lpfc_hbq_defs[hbqno]->entry_count; |
ed957684 | 866 | |
3163f725 JS |
867 | /* Check whether HBQ is still in use */ |
868 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 MW |
869 | if (!phba->hbq_in_use) |
870 | goto out; | |
3163f725 | 871 | |
ed957684 | 872 | /* Populate HBQ entries */ |
92d7f7b0 | 873 | for (i = start; i < end; i++) { |
51ef4c26 | 874 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
92d7f7b0 | 875 | if (!hbq_buffer) |
eafe1df9 | 876 | goto err; |
92d7f7b0 | 877 | hbq_buffer->tag = (i | (hbqno << 16)); |
51ef4c26 | 878 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
a8adb832 | 879 | phba->hbqs[hbqno].buffer_count++; |
51ef4c26 JS |
880 | else |
881 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
ed957684 | 882 | } |
3163f725 | 883 | |
eafe1df9 | 884 | out: |
3163f725 | 885 | spin_unlock_irqrestore(&phba->hbalock, flags); |
ed957684 | 886 | return 0; |
eafe1df9 MW |
887 | err: |
888 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
889 | return 1; | |
ed957684 JS |
890 | } |
891 | ||
e59058c4 JS |
892 | /** |
893 | * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware. | |
894 | * @phba: Pointer to HBA context object. | |
895 | * @qno: HBQ number. | |
896 | * | |
897 | * This function posts more buffers to the HBQ. This function | |
898 | * is called with no lock held. The function returns 0 when | |
899 | * successful and returns 1 otherwise. | |
900 | **/ | |
92d7f7b0 JS |
901 | int |
902 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 903 | { |
92d7f7b0 JS |
904 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
905 | lpfc_hbq_defs[qno]->add_count)); | |
906 | } | |
ed957684 | 907 | |
e59058c4 JS |
908 | /** |
909 | * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ. | |
910 | * @phba: Pointer to HBA context object. | |
911 | * @qno: HBQ queue number. | |
912 | * | |
913 | * This function is called from SLI initialization code path with | |
914 | * no lock held to post initial HBQ buffers to firmware. The | |
915 | * function returns 0 when successful and returns 1 otherwise. | |
916 | **/ | |
a6ababd2 | 917 | static int |
92d7f7b0 JS |
918 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
919 | { | |
920 | return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
921 | lpfc_hbq_defs[qno]->init_count)); | |
ed957684 JS |
922 | } |
923 | ||
e59058c4 JS |
924 | /** |
925 | * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag. | |
926 | * @phba: Pointer to HBA context object. | |
927 | * @tag: Tag of the hbq buffer. | |
928 | * | |
929 | * This function is called with hbalock held. This function searches | |
930 | * for the hbq buffer associated with the given tag in the hbq buffer | |
931 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
932 | * it returns NULL. | |
933 | **/ | |
a6ababd2 | 934 | static struct hbq_dmabuf * |
92d7f7b0 | 935 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 936 | { |
92d7f7b0 JS |
937 | struct lpfc_dmabuf *d_buf; |
938 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
939 | uint32_t hbqno; |
940 | ||
941 | hbqno = tag >> 16; | |
a0a74e45 | 942 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 943 | return NULL; |
ed957684 | 944 | |
51ef4c26 | 945 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 946 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 947 | if (hbq_buf->tag == tag) { |
92d7f7b0 | 948 | return hbq_buf; |
ed957684 JS |
949 | } |
950 | } | |
92d7f7b0 | 951 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 952 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 953 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 954 | return NULL; |
ed957684 JS |
955 | } |
956 | ||
e59058c4 JS |
957 | /** |
958 | * lpfc_sli_free_hbq: Give back the hbq buffer to firmware. | |
959 | * @phba: Pointer to HBA context object. | |
960 | * @hbq_buffer: Pointer to HBQ buffer. | |
961 | * | |
962 | * This function is called with hbalock. This function gives back | |
963 | * the hbq buffer to firmware. If the HBQ does not have space to | |
964 | * post the buffer, it will free the buffer. | |
965 | **/ | |
ed957684 | 966 | void |
51ef4c26 | 967 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
968 | { |
969 | uint32_t hbqno; | |
970 | ||
51ef4c26 JS |
971 | if (hbq_buffer) { |
972 | hbqno = hbq_buffer->tag >> 16; | |
973 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { | |
974 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
975 | } | |
ed957684 JS |
976 | } |
977 | } | |
978 | ||
e59058c4 JS |
979 | /** |
980 | * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox. | |
981 | * @mbxCommand: mailbox command code. | |
982 | * | |
983 | * This function is called by the mailbox event handler function to verify | |
984 | * that the completed mailbox command is a legitimate mailbox command. If the | |
985 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
986 | * and the mailbox event handler will take the HBA offline. | |
987 | **/ | |
dea3101e JB |
988 | static int |
989 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
990 | { | |
991 | uint8_t ret; | |
992 | ||
993 | switch (mbxCommand) { | |
994 | case MBX_LOAD_SM: | |
995 | case MBX_READ_NV: | |
996 | case MBX_WRITE_NV: | |
a8adb832 | 997 | case MBX_WRITE_VPARMS: |
dea3101e JB |
998 | case MBX_RUN_BIU_DIAG: |
999 | case MBX_INIT_LINK: | |
1000 | case MBX_DOWN_LINK: | |
1001 | case MBX_CONFIG_LINK: | |
1002 | case MBX_CONFIG_RING: | |
1003 | case MBX_RESET_RING: | |
1004 | case MBX_READ_CONFIG: | |
1005 | case MBX_READ_RCONFIG: | |
1006 | case MBX_READ_SPARM: | |
1007 | case MBX_READ_STATUS: | |
1008 | case MBX_READ_RPI: | |
1009 | case MBX_READ_XRI: | |
1010 | case MBX_READ_REV: | |
1011 | case MBX_READ_LNK_STAT: | |
1012 | case MBX_REG_LOGIN: | |
1013 | case MBX_UNREG_LOGIN: | |
1014 | case MBX_READ_LA: | |
1015 | case MBX_CLEAR_LA: | |
1016 | case MBX_DUMP_MEMORY: | |
1017 | case MBX_DUMP_CONTEXT: | |
1018 | case MBX_RUN_DIAGS: | |
1019 | case MBX_RESTART: | |
1020 | case MBX_UPDATE_CFG: | |
1021 | case MBX_DOWN_LOAD: | |
1022 | case MBX_DEL_LD_ENTRY: | |
1023 | case MBX_RUN_PROGRAM: | |
1024 | case MBX_SET_MASK: | |
09372820 | 1025 | case MBX_SET_VARIABLE: |
dea3101e | 1026 | case MBX_UNREG_D_ID: |
41415862 | 1027 | case MBX_KILL_BOARD: |
dea3101e | 1028 | case MBX_CONFIG_FARP: |
41415862 | 1029 | case MBX_BEACON: |
dea3101e JB |
1030 | case MBX_LOAD_AREA: |
1031 | case MBX_RUN_BIU_DIAG64: | |
1032 | case MBX_CONFIG_PORT: | |
1033 | case MBX_READ_SPARM64: | |
1034 | case MBX_READ_RPI64: | |
1035 | case MBX_REG_LOGIN64: | |
1036 | case MBX_READ_LA64: | |
09372820 | 1037 | case MBX_WRITE_WWN: |
dea3101e JB |
1038 | case MBX_SET_DEBUG: |
1039 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 1040 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
1041 | case MBX_REG_VPI: |
1042 | case MBX_UNREG_VPI: | |
858c9f6c | 1043 | case MBX_HEARTBEAT: |
dea3101e JB |
1044 | ret = mbxCommand; |
1045 | break; | |
1046 | default: | |
1047 | ret = MBX_SHUTDOWN; | |
1048 | break; | |
1049 | } | |
2e0fef85 | 1050 | return ret; |
dea3101e | 1051 | } |
e59058c4 JS |
1052 | |
1053 | /** | |
1054 | * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from | |
1055 | * lpfc_sli_issue_mbox_wait. | |
1056 | * @phba: Pointer to HBA context object. | |
1057 | * @pmboxq: Pointer to mailbox command. | |
1058 | * | |
1059 | * This is completion handler function for mailbox commands issued from | |
1060 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
1061 | * mailbox event handler function with no lock held. This function | |
1062 | * will wake up thread waiting on the wait queue pointed by context1 | |
1063 | * of the mailbox. | |
1064 | **/ | |
dea3101e | 1065 | static void |
2e0fef85 | 1066 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
1067 | { |
1068 | wait_queue_head_t *pdone_q; | |
858c9f6c | 1069 | unsigned long drvr_flag; |
dea3101e JB |
1070 | |
1071 | /* | |
1072 | * If pdone_q is empty, the driver thread gave up waiting and | |
1073 | * continued running. | |
1074 | */ | |
7054a606 | 1075 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 1076 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
1077 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
1078 | if (pdone_q) | |
1079 | wake_up_interruptible(pdone_q); | |
858c9f6c | 1080 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
1081 | return; |
1082 | } | |
1083 | ||
e59058c4 JS |
1084 | |
1085 | /** | |
1086 | * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler. | |
1087 | * @phba: Pointer to HBA context object. | |
1088 | * @pmb: Pointer to mailbox object. | |
1089 | * | |
1090 | * This function is the default mailbox completion handler. It | |
1091 | * frees the memory resources associated with the completed mailbox | |
1092 | * command. If the completed command is a REG_LOGIN mailbox command, | |
1093 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
1094 | **/ | |
dea3101e | 1095 | void |
2e0fef85 | 1096 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e JB |
1097 | { |
1098 | struct lpfc_dmabuf *mp; | |
7054a606 JS |
1099 | uint16_t rpi; |
1100 | int rc; | |
1101 | ||
dea3101e | 1102 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 1103 | |
dea3101e JB |
1104 | if (mp) { |
1105 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1106 | kfree(mp); | |
1107 | } | |
7054a606 JS |
1108 | |
1109 | /* | |
1110 | * If a REG_LOGIN succeeded after node is destroyed or node | |
1111 | * is in re-discovery driver need to cleanup the RPI. | |
1112 | */ | |
2e0fef85 JS |
1113 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
1114 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && | |
1115 | !pmb->mb.mbxStatus) { | |
7054a606 JS |
1116 | |
1117 | rpi = pmb->mb.un.varWords[0]; | |
92d7f7b0 JS |
1118 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); |
1119 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
7054a606 JS |
1120 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
1121 | if (rc != MBX_NOT_FINISHED) | |
1122 | return; | |
1123 | } | |
1124 | ||
2e0fef85 | 1125 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1126 | return; |
1127 | } | |
1128 | ||
e59058c4 JS |
1129 | /** |
1130 | * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware. | |
1131 | * @phba: Pointer to HBA context object. | |
1132 | * | |
1133 | * This function is called with no lock held. This function processes all | |
1134 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
1135 | * service routine processes mailbox completion interrupt and adds completed | |
1136 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
1137 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
1138 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
1139 | * function returns the mailbox commands to the upper layer by calling the | |
1140 | * completion handler function of each mailbox. | |
1141 | **/ | |
dea3101e | 1142 | int |
2e0fef85 | 1143 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 1144 | { |
92d7f7b0 | 1145 | MAILBOX_t *pmbox; |
dea3101e | 1146 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
1147 | int rc; |
1148 | LIST_HEAD(cmplq); | |
dea3101e JB |
1149 | |
1150 | phba->sli.slistat.mbox_event++; | |
1151 | ||
92d7f7b0 JS |
1152 | /* Get all completed mailboxe buffers into the cmplq */ |
1153 | spin_lock_irq(&phba->hbalock); | |
1154 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
1155 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 1156 | |
92d7f7b0 JS |
1157 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
1158 | do { | |
1159 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
1160 | if (pmb == NULL) | |
1161 | break; | |
2e0fef85 | 1162 | |
92d7f7b0 | 1163 | pmbox = &pmb->mb; |
dea3101e | 1164 | |
858c9f6c JS |
1165 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
1166 | if (pmb->vport) { | |
1167 | lpfc_debugfs_disc_trc(pmb->vport, | |
1168 | LPFC_DISC_TRC_MBOX_VPORT, | |
1169 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
1170 | (uint32_t)pmbox->mbxCommand, | |
1171 | pmbox->un.varWords[0], | |
1172 | pmbox->un.varWords[1]); | |
1173 | } | |
1174 | else { | |
1175 | lpfc_debugfs_disc_trc(phba->pport, | |
1176 | LPFC_DISC_TRC_MBOX, | |
1177 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
1178 | (uint32_t)pmbox->mbxCommand, | |
1179 | pmbox->un.varWords[0], | |
1180 | pmbox->un.varWords[1]); | |
1181 | } | |
1182 | } | |
1183 | ||
dea3101e JB |
1184 | /* |
1185 | * It is a fatal error if unknown mbox command completion. | |
1186 | */ | |
1187 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
1188 | MBX_SHUTDOWN) { | |
dea3101e | 1189 | /* Unknow mailbox command compl */ |
92d7f7b0 | 1190 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 1191 | "(%d):0323 Unknown Mailbox command " |
92d7f7b0 | 1192 | "%x Cmpl\n", |
92d7f7b0 JS |
1193 | pmb->vport ? pmb->vport->vpi : 0, |
1194 | pmbox->mbxCommand); | |
2e0fef85 | 1195 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1196 | phba->work_hs = HS_FFER3; |
1197 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 1198 | continue; |
dea3101e JB |
1199 | } |
1200 | ||
dea3101e JB |
1201 | if (pmbox->mbxStatus) { |
1202 | phba->sli.slistat.mbox_stat_err++; | |
1203 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
1204 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
1205 | lpfc_printf_log(phba, KERN_INFO, |
1206 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 1207 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 JS |
1208 | "error - RETRYing Data: x%x " |
1209 | "x%x x%x x%x\n", | |
92d7f7b0 JS |
1210 | pmb->vport ? pmb->vport->vpi :0, |
1211 | pmbox->mbxCommand, | |
1212 | pmbox->mbxStatus, | |
1213 | pmbox->un.varWords[0], | |
1214 | pmb->vport->port_state); | |
dea3101e JB |
1215 | pmbox->mbxStatus = 0; |
1216 | pmbox->mbxOwner = OWN_HOST; | |
2e0fef85 | 1217 | spin_lock_irq(&phba->hbalock); |
dea3101e | 1218 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 1219 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1220 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
1221 | if (rc == MBX_SUCCESS) | |
92d7f7b0 | 1222 | continue; |
dea3101e JB |
1223 | } |
1224 | } | |
1225 | ||
1226 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 1227 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 1228 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " |
dea3101e | 1229 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 1230 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e JB |
1231 | pmbox->mbxCommand, |
1232 | pmb->mbox_cmpl, | |
1233 | *((uint32_t *) pmbox), | |
1234 | pmbox->un.varWords[0], | |
1235 | pmbox->un.varWords[1], | |
1236 | pmbox->un.varWords[2], | |
1237 | pmbox->un.varWords[3], | |
1238 | pmbox->un.varWords[4], | |
1239 | pmbox->un.varWords[5], | |
1240 | pmbox->un.varWords[6], | |
1241 | pmbox->un.varWords[7]); | |
1242 | ||
92d7f7b0 | 1243 | if (pmb->mbox_cmpl) |
dea3101e | 1244 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
1245 | } while (1); |
1246 | return 0; | |
1247 | } | |
dea3101e | 1248 | |
e59058c4 JS |
1249 | /** |
1250 | * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer. | |
1251 | * @phba: Pointer to HBA context object. | |
1252 | * @tag: Tag for the HBQ buffer. | |
1253 | * | |
1254 | * This function is called from unsolicited event handler code path to get the | |
1255 | * HBQ buffer associated with an unsolicited iocb. This function is called with | |
1256 | * no lock held. It returns the buffer associated with the given tag and posts | |
1257 | * another buffer to the firmware. | |
1258 | **/ | |
92d7f7b0 JS |
1259 | static struct lpfc_dmabuf * |
1260 | lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) | |
1261 | { | |
1262 | struct hbq_dmabuf *hbq_entry, *new_hbq_entry; | |
51ef4c26 JS |
1263 | uint32_t hbqno; |
1264 | void *virt; /* virtual address ptr */ | |
1265 | dma_addr_t phys; /* mapped address */ | |
3163f725 JS |
1266 | unsigned long flags; |
1267 | ||
1268 | /* Check whether HBQ is still in use */ | |
1269 | spin_lock_irqsave(&phba->hbalock, flags); | |
1270 | if (!phba->hbq_in_use) { | |
1271 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1272 | return NULL; | |
1273 | } | |
dea3101e | 1274 | |
92d7f7b0 | 1275 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
3163f725 JS |
1276 | if (hbq_entry == NULL) { |
1277 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
92d7f7b0 | 1278 | return NULL; |
3163f725 | 1279 | } |
92d7f7b0 | 1280 | list_del(&hbq_entry->dbuf.list); |
51ef4c26 JS |
1281 | |
1282 | hbqno = tag >> 16; | |
1283 | new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
3163f725 JS |
1284 | if (new_hbq_entry == NULL) { |
1285 | list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list); | |
1286 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
92d7f7b0 | 1287 | return &hbq_entry->dbuf; |
3163f725 | 1288 | } |
92d7f7b0 | 1289 | new_hbq_entry->tag = -1; |
51ef4c26 JS |
1290 | phys = new_hbq_entry->dbuf.phys; |
1291 | virt = new_hbq_entry->dbuf.virt; | |
1292 | new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys; | |
1293 | new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt; | |
1294 | hbq_entry->dbuf.phys = phys; | |
1295 | hbq_entry->dbuf.virt = virt; | |
92d7f7b0 | 1296 | lpfc_sli_free_hbq(phba, hbq_entry); |
3163f725 JS |
1297 | list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list); |
1298 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
1299 | ||
92d7f7b0 | 1300 | return &new_hbq_entry->dbuf; |
dea3101e | 1301 | } |
92d7f7b0 | 1302 | |
e59058c4 JS |
1303 | /** |
1304 | * lpfc_sli_get_buff: Get the buffer associated with the buffer tag. | |
1305 | * @phba: Pointer to HBA context object. | |
1306 | * @pring: Pointer to driver SLI ring object. | |
1307 | * @tag: buffer tag. | |
1308 | * | |
1309 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
1310 | * is set in the tag the buffer is posted for a particular exchange, | |
1311 | * the function will return the buffer without replacing the buffer. | |
1312 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
1313 | * returns the buffer and also posts another buffer to the firmware. | |
1314 | **/ | |
76bb24ef JS |
1315 | static struct lpfc_dmabuf * |
1316 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
1317 | struct lpfc_sli_ring *pring, | |
1318 | uint32_t tag) | |
1319 | { | |
1320 | if (tag & QUE_BUFTAG_BIT) | |
1321 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
1322 | else | |
1323 | return lpfc_sli_replace_hbqbuff(phba, tag); | |
1324 | } | |
57127f15 | 1325 | |
e59058c4 JS |
1326 | |
1327 | /** | |
1328 | * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler. | |
1329 | * @phba: Pointer to HBA context object. | |
1330 | * @pring: Pointer to driver SLI ring object. | |
1331 | * @saveq: Pointer to the unsolicited iocb. | |
1332 | * | |
1333 | * This function is called with no lock held by the ring event handler | |
1334 | * when there is an unsolicited iocb posted to the response ring by the | |
1335 | * firmware. This function gets the buffer associated with the iocbs | |
1336 | * and calls the event handler for the ring. This function handles both | |
1337 | * qring buffers and hbq buffers. | |
1338 | * When the function returns 1 the caller can free the iocb object otherwise | |
1339 | * upper layer functions will free the iocb objects. | |
1340 | **/ | |
dea3101e JB |
1341 | static int |
1342 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1343 | struct lpfc_iocbq *saveq) | |
1344 | { | |
1345 | IOCB_t * irsp; | |
1346 | WORD5 * w5p; | |
1347 | uint32_t Rctl, Type; | |
1348 | uint32_t match, i; | |
76bb24ef | 1349 | struct lpfc_iocbq *iocbq; |
3163f725 | 1350 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
1351 | |
1352 | match = 0; | |
1353 | irsp = &(saveq->iocb); | |
57127f15 | 1354 | |
9c2face6 JS |
1355 | if (irsp->ulpStatus == IOSTAT_NEED_BUFFER) |
1356 | return 1; | |
57127f15 JS |
1357 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
1358 | if (pring->lpfc_sli_rcv_async_status) | |
1359 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
1360 | else | |
1361 | lpfc_printf_log(phba, | |
1362 | KERN_WARNING, | |
1363 | LOG_SLI, | |
1364 | "0316 Ring %d handler: unexpected " | |
1365 | "ASYNC_STATUS iocb received evt_code " | |
1366 | "0x%x\n", | |
1367 | pring->ringno, | |
1368 | irsp->un.asyncstat.evt_code); | |
1369 | return 1; | |
1370 | } | |
1371 | ||
3163f725 JS |
1372 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
1373 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
1374 | if (irsp->ulpBdeCount > 0) { | |
1375 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
1376 | irsp->un.ulpWord[3]); | |
1377 | lpfc_in_buf_free(phba, dmzbuf); | |
1378 | } | |
1379 | ||
1380 | if (irsp->ulpBdeCount > 1) { | |
1381 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
1382 | irsp->unsli3.sli3Words[3]); | |
1383 | lpfc_in_buf_free(phba, dmzbuf); | |
1384 | } | |
1385 | ||
1386 | if (irsp->ulpBdeCount > 2) { | |
1387 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
1388 | irsp->unsli3.sli3Words[7]); | |
1389 | lpfc_in_buf_free(phba, dmzbuf); | |
1390 | } | |
1391 | ||
1392 | return 1; | |
1393 | } | |
1394 | ||
92d7f7b0 | 1395 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
1396 | if (irsp->ulpBdeCount != 0) { |
1397 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
1398 | irsp->un.ulpWord[3]); | |
1399 | if (!saveq->context2) | |
1400 | lpfc_printf_log(phba, | |
1401 | KERN_ERR, | |
1402 | LOG_SLI, | |
1403 | "0341 Ring %d Cannot find buffer for " | |
1404 | "an unsolicited iocb. tag 0x%x\n", | |
1405 | pring->ringno, | |
1406 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
1407 | } |
1408 | if (irsp->ulpBdeCount == 2) { | |
1409 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
1410 | irsp->unsli3.sli3Words[7]); | |
1411 | if (!saveq->context3) | |
1412 | lpfc_printf_log(phba, | |
1413 | KERN_ERR, | |
1414 | LOG_SLI, | |
1415 | "0342 Ring %d Cannot find buffer for an" | |
1416 | " unsolicited iocb. tag 0x%x\n", | |
1417 | pring->ringno, | |
1418 | irsp->unsli3.sli3Words[7]); | |
1419 | } | |
1420 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 1421 | irsp = &(iocbq->iocb); |
76bb24ef JS |
1422 | if (irsp->ulpBdeCount != 0) { |
1423 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
1424 | irsp->un.ulpWord[3]); | |
9c2face6 | 1425 | if (!iocbq->context2) |
76bb24ef JS |
1426 | lpfc_printf_log(phba, |
1427 | KERN_ERR, | |
1428 | LOG_SLI, | |
1429 | "0343 Ring %d Cannot find " | |
1430 | "buffer for an unsolicited iocb" | |
1431 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 1432 | irsp->un.ulpWord[3]); |
76bb24ef JS |
1433 | } |
1434 | if (irsp->ulpBdeCount == 2) { | |
1435 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 1436 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 1437 | if (!iocbq->context3) |
76bb24ef JS |
1438 | lpfc_printf_log(phba, |
1439 | KERN_ERR, | |
1440 | LOG_SLI, | |
1441 | "0344 Ring %d Cannot find " | |
1442 | "buffer for an unsolicited " | |
1443 | "iocb. tag 0x%x\n", | |
1444 | pring->ringno, | |
1445 | irsp->unsli3.sli3Words[7]); | |
1446 | } | |
1447 | } | |
92d7f7b0 | 1448 | } |
9c2face6 JS |
1449 | if (irsp->ulpBdeCount != 0 && |
1450 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
1451 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
1452 | int found = 0; | |
1453 | ||
1454 | /* search continue save q for same XRI */ | |
1455 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
1456 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
1457 | list_add_tail(&saveq->list, &iocbq->list); | |
1458 | found = 1; | |
1459 | break; | |
1460 | } | |
1461 | } | |
1462 | if (!found) | |
1463 | list_add_tail(&saveq->clist, | |
1464 | &pring->iocb_continue_saveq); | |
1465 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
1466 | list_del_init(&iocbq->clist); | |
1467 | saveq = iocbq; | |
1468 | irsp = &(saveq->iocb); | |
1469 | } else | |
1470 | return 0; | |
1471 | } | |
1472 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
1473 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
1474 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
1475 | Rctl = FC_ELS_REQ; | |
1476 | Type = FC_ELS_DATA; | |
1477 | } else { | |
1478 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
1479 | Rctl = w5p->hcsw.Rctl; | |
1480 | Type = w5p->hcsw.Type; | |
1481 | ||
1482 | /* Firmware Workaround */ | |
1483 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
1484 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
1485 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
1486 | Rctl = FC_ELS_REQ; | |
1487 | Type = FC_ELS_DATA; | |
1488 | w5p->hcsw.Rctl = Rctl; | |
1489 | w5p->hcsw.Type = Type; | |
1490 | } | |
1491 | } | |
92d7f7b0 | 1492 | |
dea3101e JB |
1493 | /* unSolicited Responses */ |
1494 | if (pring->prt[0].profile) { | |
cf5bf97e JW |
1495 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
1496 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
1497 | saveq); | |
dea3101e JB |
1498 | match = 1; |
1499 | } else { | |
1500 | /* We must search, based on rctl / type | |
1501 | for the right routine */ | |
9c2face6 JS |
1502 | for (i = 0; i < pring->num_mask; i++) { |
1503 | if ((pring->prt[i].rctl == Rctl) | |
1504 | && (pring->prt[i].type == Type)) { | |
cf5bf97e JW |
1505 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
1506 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
1507 | (phba, pring, saveq); | |
dea3101e JB |
1508 | match = 1; |
1509 | break; | |
1510 | } | |
1511 | } | |
1512 | } | |
1513 | if (match == 0) { | |
1514 | /* Unexpected Rctl / Type received */ | |
1515 | /* Ring <ringno> handler: unexpected | |
1516 | Rctl <Rctl> Type <Type> received */ | |
92d7f7b0 | 1517 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 1518 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 1519 | "Type x%x received\n", |
e8b62011 | 1520 | pring->ringno, Rctl, Type); |
dea3101e | 1521 | } |
92d7f7b0 | 1522 | return 1; |
dea3101e JB |
1523 | } |
1524 | ||
e59058c4 JS |
1525 | /** |
1526 | * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb. | |
1527 | * @phba: Pointer to HBA context object. | |
1528 | * @pring: Pointer to driver SLI ring object. | |
1529 | * @prspiocb: Pointer to response iocb object. | |
1530 | * | |
1531 | * This function looks up the iocb_lookup table to get the command iocb | |
1532 | * corresponding to the given response iocb using the iotag of the | |
1533 | * response iocb. This function is called with the hbalock held. | |
1534 | * This function returns the command iocb object if it finds the command | |
1535 | * iocb else returns NULL. | |
1536 | **/ | |
dea3101e | 1537 | static struct lpfc_iocbq * |
2e0fef85 JS |
1538 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
1539 | struct lpfc_sli_ring *pring, | |
1540 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 1541 | { |
dea3101e JB |
1542 | struct lpfc_iocbq *cmd_iocb = NULL; |
1543 | uint16_t iotag; | |
1544 | ||
604a3e30 JB |
1545 | iotag = prspiocb->iocb.ulpIoTag; |
1546 | ||
1547 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
1548 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 1549 | list_del_init(&cmd_iocb->list); |
604a3e30 JB |
1550 | pring->txcmplq_cnt--; |
1551 | return cmd_iocb; | |
dea3101e JB |
1552 | } |
1553 | ||
dea3101e | 1554 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1555 | "0317 iotag x%x is out off " |
604a3e30 | 1556 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 1557 | iotag, phba->sli.last_iotag, |
604a3e30 | 1558 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
1559 | return NULL; |
1560 | } | |
1561 | ||
e59058c4 JS |
1562 | /** |
1563 | * lpfc_sli_process_sol_iocb: process solicited iocb completion. | |
1564 | * @phba: Pointer to HBA context object. | |
1565 | * @pring: Pointer to driver SLI ring object. | |
1566 | * @saveq: Pointer to the response iocb to be processed. | |
1567 | * | |
1568 | * This function is called by the ring event handler for non-fcp | |
1569 | * rings when there is a new response iocb in the response ring. | |
1570 | * The caller is not required to hold any locks. This function | |
1571 | * gets the command iocb associated with the response iocb and | |
1572 | * calls the completion handler for the command iocb. If there | |
1573 | * is no completion handler, the function will free the resources | |
1574 | * associated with command iocb. If the response iocb is for | |
1575 | * an already aborted command iocb, the status of the completion | |
1576 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
1577 | * This function always returns 1. | |
1578 | **/ | |
dea3101e | 1579 | static int |
2e0fef85 | 1580 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
1581 | struct lpfc_iocbq *saveq) |
1582 | { | |
2e0fef85 | 1583 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
1584 | int rc = 1; |
1585 | unsigned long iflag; | |
1586 | ||
1587 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 1588 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 1589 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
1590 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
1591 | ||
dea3101e JB |
1592 | if (cmdiocbp) { |
1593 | if (cmdiocbp->iocb_cmpl) { | |
1594 | /* | |
1595 | * Post all ELS completions to the worker thread. | |
1596 | * All other are passed to the completion callback. | |
1597 | */ | |
1598 | if (pring->ringno == LPFC_ELS_RING) { | |
07951076 JS |
1599 | if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { |
1600 | cmdiocbp->iocb_flag &= | |
1601 | ~LPFC_DRIVER_ABORTED; | |
1602 | saveq->iocb.ulpStatus = | |
1603 | IOSTAT_LOCAL_REJECT; | |
1604 | saveq->iocb.un.ulpWord[4] = | |
1605 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
1606 | |
1607 | /* Firmware could still be in progress | |
1608 | * of DMAing payload, so don't free data | |
1609 | * buffer till after a hbeat. | |
1610 | */ | |
1611 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
07951076 | 1612 | } |
dea3101e | 1613 | } |
2e0fef85 | 1614 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
1615 | } else |
1616 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
1617 | } else { |
1618 | /* | |
1619 | * Unknown initiating command based on the response iotag. | |
1620 | * This could be the case on the ELS ring because of | |
1621 | * lpfc_els_abort(). | |
1622 | */ | |
1623 | if (pring->ringno != LPFC_ELS_RING) { | |
1624 | /* | |
1625 | * Ring <ringno> handler: unexpected completion IoTag | |
1626 | * <IoTag> | |
1627 | */ | |
e8b62011 JS |
1628 | lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI, |
1629 | "0322 Ring %d handler: " | |
1630 | "unexpected completion IoTag x%x " | |
1631 | "Data: x%x x%x x%x x%x\n", | |
1632 | pring->ringno, | |
1633 | saveq->iocb.ulpIoTag, | |
1634 | saveq->iocb.ulpStatus, | |
1635 | saveq->iocb.un.ulpWord[4], | |
1636 | saveq->iocb.ulpCommand, | |
1637 | saveq->iocb.ulpContext); | |
dea3101e JB |
1638 | } |
1639 | } | |
68876920 | 1640 | |
dea3101e JB |
1641 | return rc; |
1642 | } | |
1643 | ||
e59058c4 JS |
1644 | /** |
1645 | * lpfc_sli_rsp_pointers_error: Response ring pointer error handler. | |
1646 | * @phba: Pointer to HBA context object. | |
1647 | * @pring: Pointer to driver SLI ring object. | |
1648 | * | |
1649 | * This function is called from the iocb ring event handlers when | |
1650 | * put pointer is ahead of the get pointer for a ring. This function signal | |
1651 | * an error attention condition to the worker thread and the worker | |
1652 | * thread will transition the HBA to offline state. | |
1653 | **/ | |
2e0fef85 JS |
1654 | static void |
1655 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 1656 | { |
ed957684 JS |
1657 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
1658 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : | |
1659 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; | |
875fbdfe JSEC |
1660 | /* |
1661 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then | |
1662 | * rsp ring <portRspMax> | |
1663 | */ | |
1664 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1665 | "0312 Ring %d handler: portRspPut %d " |
875fbdfe | 1666 | "is bigger then rsp ring %d\n", |
e8b62011 | 1667 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
1668 | pring->numRiocb); |
1669 | ||
2e0fef85 | 1670 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
1671 | |
1672 | /* | |
1673 | * All error attention handlers are posted to | |
1674 | * worker thread | |
1675 | */ | |
1676 | phba->work_ha |= HA_ERATT; | |
1677 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1678 | |
5e9d9b82 | 1679 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
1680 | |
1681 | return; | |
1682 | } | |
1683 | ||
e59058c4 JS |
1684 | /** |
1685 | * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode. | |
1686 | * @phba: Pointer to HBA context object. | |
1687 | * | |
1688 | * This function is called from lpfc_queuecommand, lpfc_poll_timeout, | |
1689 | * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING | |
1690 | * is enabled. | |
1691 | * | |
1692 | * The caller does not hold any lock. | |
1693 | * The function processes each response iocb in the response ring until it | |
1694 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
1695 | * LE bit set. The function will call the completion handler of the command iocb | |
1696 | * if the response iocb indicates a completion for a command iocb or it is | |
1697 | * an abort completion. | |
1698 | **/ | |
2e0fef85 | 1699 | void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) |
875fbdfe | 1700 | { |
2e0fef85 JS |
1701 | struct lpfc_sli *psli = &phba->sli; |
1702 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING]; | |
875fbdfe JSEC |
1703 | IOCB_t *irsp = NULL; |
1704 | IOCB_t *entry = NULL; | |
1705 | struct lpfc_iocbq *cmdiocbq = NULL; | |
1706 | struct lpfc_iocbq rspiocbq; | |
1707 | struct lpfc_pgp *pgp; | |
1708 | uint32_t status; | |
1709 | uint32_t portRspPut, portRspMax; | |
1710 | int type; | |
1711 | uint32_t rsp_cmpl = 0; | |
875fbdfe | 1712 | uint32_t ha_copy; |
2e0fef85 | 1713 | unsigned long iflags; |
875fbdfe JSEC |
1714 | |
1715 | pring->stats.iocb_event++; | |
1716 | ||
ed957684 JS |
1717 | pgp = (phba->sli_rev == 3) ? |
1718 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : | |
1719 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; | |
1720 | ||
875fbdfe JSEC |
1721 | |
1722 | /* | |
1723 | * The next available response entry should never exceed the maximum | |
1724 | * entries. If it does, treat it as an adapter hardware error. | |
1725 | */ | |
1726 | portRspMax = pring->numRiocb; | |
1727 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
1728 | if (unlikely(portRspPut >= portRspMax)) { | |
1729 | lpfc_sli_rsp_pointers_error(phba, pring); | |
1730 | return; | |
1731 | } | |
1732 | ||
1733 | rmb(); | |
1734 | while (pring->rspidx != portRspPut) { | |
ed957684 | 1735 | entry = lpfc_resp_iocb(phba, pring); |
875fbdfe JSEC |
1736 | if (++pring->rspidx >= portRspMax) |
1737 | pring->rspidx = 0; | |
1738 | ||
1739 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, | |
1740 | (uint32_t *) &rspiocbq.iocb, | |
92d7f7b0 | 1741 | phba->iocb_rsp_size); |
875fbdfe JSEC |
1742 | irsp = &rspiocbq.iocb; |
1743 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); | |
1744 | pring->stats.iocb_rsp++; | |
1745 | rsp_cmpl++; | |
1746 | ||
1747 | if (unlikely(irsp->ulpStatus)) { | |
1748 | /* Rsp ring <ringno> error: IOCB */ | |
1749 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 1750 | "0326 Rsp Ring %d error: IOCB Data: " |
875fbdfe | 1751 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 1752 | pring->ringno, |
875fbdfe JSEC |
1753 | irsp->un.ulpWord[0], |
1754 | irsp->un.ulpWord[1], | |
1755 | irsp->un.ulpWord[2], | |
1756 | irsp->un.ulpWord[3], | |
1757 | irsp->un.ulpWord[4], | |
1758 | irsp->un.ulpWord[5], | |
1759 | *(((uint32_t *) irsp) + 6), | |
1760 | *(((uint32_t *) irsp) + 7)); | |
1761 | } | |
1762 | ||
1763 | switch (type) { | |
1764 | case LPFC_ABORT_IOCB: | |
1765 | case LPFC_SOL_IOCB: | |
1766 | /* | |
1767 | * Idle exchange closed via ABTS from port. No iocb | |
1768 | * resources need to be recovered. | |
1769 | */ | |
1770 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 1771 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
1772 | "0314 IOCB cmd 0x%x " |
1773 | "processed. Skipping " | |
1774 | "completion", | |
dca9479b | 1775 | irsp->ulpCommand); |
875fbdfe JSEC |
1776 | break; |
1777 | } | |
1778 | ||
2e0fef85 | 1779 | spin_lock_irqsave(&phba->hbalock, iflags); |
875fbdfe JSEC |
1780 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
1781 | &rspiocbq); | |
2e0fef85 | 1782 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
875fbdfe JSEC |
1783 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
1784 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
1785 | &rspiocbq); | |
1786 | } | |
1787 | break; | |
1788 | default: | |
1789 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
1790 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
1791 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
1792 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
1793 | MAX_MSG_DATA); | |
898eb71c JP |
1794 | dev_warn(&((phba->pcidev)->dev), |
1795 | "lpfc%d: %s\n", | |
875fbdfe JSEC |
1796 | phba->brd_no, adaptermsg); |
1797 | } else { | |
1798 | /* Unknown IOCB command */ | |
1799 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1800 | "0321 Unknown IOCB command " |
875fbdfe | 1801 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 1802 | type, irsp->ulpCommand, |
875fbdfe JSEC |
1803 | irsp->ulpStatus, |
1804 | irsp->ulpIoTag, | |
1805 | irsp->ulpContext); | |
1806 | } | |
1807 | break; | |
1808 | } | |
1809 | ||
1810 | /* | |
1811 | * The response IOCB has been processed. Update the ring | |
1812 | * pointer in SLIM. If the port response put pointer has not | |
1813 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
1814 | * response put pointer. | |
1815 | */ | |
ed957684 | 1816 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
875fbdfe JSEC |
1817 | |
1818 | if (pring->rspidx == portRspPut) | |
1819 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
1820 | } | |
1821 | ||
1822 | ha_copy = readl(phba->HAregaddr); | |
1823 | ha_copy >>= (LPFC_FCP_RING * 4); | |
1824 | ||
1825 | if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { | |
2e0fef85 | 1826 | spin_lock_irqsave(&phba->hbalock, iflags); |
875fbdfe JSEC |
1827 | pring->stats.iocb_rsp_full++; |
1828 | status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); | |
1829 | writel(status, phba->CAregaddr); | |
1830 | readl(phba->CAregaddr); | |
2e0fef85 | 1831 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
875fbdfe JSEC |
1832 | } |
1833 | if ((ha_copy & HA_R0CE_RSP) && | |
1834 | (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2e0fef85 | 1835 | spin_lock_irqsave(&phba->hbalock, iflags); |
875fbdfe JSEC |
1836 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
1837 | pring->stats.iocb_cmd_empty++; | |
1838 | ||
1839 | /* Force update of the local copy of cmdGetInx */ | |
1840 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
1841 | lpfc_sli_resume_iocb(phba, pring); | |
1842 | ||
1843 | if ((pring->lpfc_sli_cmd_available)) | |
1844 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
1845 | ||
2e0fef85 | 1846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
875fbdfe JSEC |
1847 | } |
1848 | ||
1849 | return; | |
1850 | } | |
1851 | ||
e59058c4 JS |
1852 | /** |
1853 | * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring. | |
1854 | * @phba: Pointer to HBA context object. | |
1855 | * @pring: Pointer to driver SLI ring object. | |
1856 | * @mask: Host attention register mask for this ring. | |
1857 | * | |
1858 | * This function is called from the interrupt context when there is a ring | |
1859 | * event for the fcp ring. The caller does not hold any lock. | |
1860 | * The function processes each response iocb in the response ring until it | |
1861 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
1862 | * LE bit set. The function will call the completion handler of the command iocb | |
1863 | * if the response iocb indicates a completion for a command iocb or it is | |
1864 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
1865 | * function if this is an unsolicited iocb. | |
dea3101e | 1866 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
e59058c4 JS |
1867 | * to check it explicitly. This function always returns 1. |
1868 | **/ | |
dea3101e | 1869 | static int |
2e0fef85 JS |
1870 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
1871 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 1872 | { |
ed957684 JS |
1873 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
1874 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : | |
1875 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; | |
dea3101e | 1876 | IOCB_t *irsp = NULL; |
87f6eaff | 1877 | IOCB_t *entry = NULL; |
dea3101e JB |
1878 | struct lpfc_iocbq *cmdiocbq = NULL; |
1879 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
1880 | uint32_t status; |
1881 | uint32_t portRspPut, portRspMax; | |
1882 | int rc = 1; | |
1883 | lpfc_iocb_type type; | |
1884 | unsigned long iflag; | |
1885 | uint32_t rsp_cmpl = 0; | |
dea3101e | 1886 | |
2e0fef85 | 1887 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
1888 | pring->stats.iocb_event++; |
1889 | ||
dea3101e JB |
1890 | /* |
1891 | * The next available response entry should never exceed the maximum | |
1892 | * entries. If it does, treat it as an adapter hardware error. | |
1893 | */ | |
1894 | portRspMax = pring->numRiocb; | |
1895 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
1896 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 1897 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 1898 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
1899 | return 1; |
1900 | } | |
1901 | ||
1902 | rmb(); | |
1903 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
1904 | /* |
1905 | * Fetch an entry off the ring and copy it into a local data | |
1906 | * structure. The copy involves a byte-swap since the | |
1907 | * network byte order and pci byte orders are different. | |
1908 | */ | |
ed957684 | 1909 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 1910 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
1911 | |
1912 | if (++pring->rspidx >= portRspMax) | |
1913 | pring->rspidx = 0; | |
1914 | ||
87f6eaff JSEC |
1915 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
1916 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 1917 | phba->iocb_rsp_size); |
a4bc3379 | 1918 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
1919 | irsp = &rspiocbq.iocb; |
1920 | ||
dea3101e JB |
1921 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
1922 | pring->stats.iocb_rsp++; | |
1923 | rsp_cmpl++; | |
1924 | ||
1925 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
1926 | /* |
1927 | * If resource errors reported from HBA, reduce | |
1928 | * queuedepths of the SCSI device. | |
1929 | */ | |
1930 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
1931 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
1932 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
1933 | lpfc_adjust_queue_depth(phba); | |
1934 | spin_lock_irqsave(&phba->hbalock, iflag); | |
1935 | } | |
1936 | ||
dea3101e JB |
1937 | /* Rsp ring <ringno> error: IOCB */ |
1938 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 1939 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 1940 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 1941 | pring->ringno, |
92d7f7b0 JS |
1942 | irsp->un.ulpWord[0], |
1943 | irsp->un.ulpWord[1], | |
1944 | irsp->un.ulpWord[2], | |
1945 | irsp->un.ulpWord[3], | |
1946 | irsp->un.ulpWord[4], | |
1947 | irsp->un.ulpWord[5], | |
1948 | *(((uint32_t *) irsp) + 6), | |
1949 | *(((uint32_t *) irsp) + 7)); | |
dea3101e JB |
1950 | } |
1951 | ||
1952 | switch (type) { | |
1953 | case LPFC_ABORT_IOCB: | |
1954 | case LPFC_SOL_IOCB: | |
1955 | /* | |
1956 | * Idle exchange closed via ABTS from port. No iocb | |
1957 | * resources need to be recovered. | |
1958 | */ | |
1959 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 1960 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 1961 | "0333 IOCB cmd 0x%x" |
dca9479b | 1962 | " processed. Skipping" |
92d7f7b0 | 1963 | " completion\n", |
dca9479b | 1964 | irsp->ulpCommand); |
dea3101e JB |
1965 | break; |
1966 | } | |
1967 | ||
604a3e30 JB |
1968 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
1969 | &rspiocbq); | |
dea3101e | 1970 | if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { |
b808608b JW |
1971 | if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { |
1972 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
1973 | &rspiocbq); | |
1974 | } else { | |
2e0fef85 JS |
1975 | spin_unlock_irqrestore(&phba->hbalock, |
1976 | iflag); | |
b808608b JW |
1977 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
1978 | &rspiocbq); | |
2e0fef85 | 1979 | spin_lock_irqsave(&phba->hbalock, |
b808608b JW |
1980 | iflag); |
1981 | } | |
dea3101e JB |
1982 | } |
1983 | break; | |
a4bc3379 | 1984 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 1985 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 1986 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 1987 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 1988 | break; |
dea3101e JB |
1989 | default: |
1990 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
1991 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
1992 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
1993 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
1994 | MAX_MSG_DATA); | |
898eb71c JP |
1995 | dev_warn(&((phba->pcidev)->dev), |
1996 | "lpfc%d: %s\n", | |
dea3101e JB |
1997 | phba->brd_no, adaptermsg); |
1998 | } else { | |
1999 | /* Unknown IOCB command */ | |
2000 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2001 | "0334 Unknown IOCB command " |
92d7f7b0 | 2002 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2003 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2004 | irsp->ulpStatus, |
2005 | irsp->ulpIoTag, | |
2006 | irsp->ulpContext); | |
dea3101e JB |
2007 | } |
2008 | break; | |
2009 | } | |
2010 | ||
2011 | /* | |
2012 | * The response IOCB has been processed. Update the ring | |
2013 | * pointer in SLIM. If the port response put pointer has not | |
2014 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2015 | * response put pointer. | |
2016 | */ | |
ed957684 | 2017 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e JB |
2018 | |
2019 | if (pring->rspidx == portRspPut) | |
2020 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2021 | } | |
2022 | ||
2023 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2024 | pring->stats.iocb_rsp_full++; | |
2025 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2026 | writel(status, phba->CAregaddr); | |
2027 | readl(phba->CAregaddr); | |
2028 | } | |
2029 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2030 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2031 | pring->stats.iocb_cmd_empty++; | |
2032 | ||
2033 | /* Force update of the local copy of cmdGetInx */ | |
2034 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2035 | lpfc_sli_resume_iocb(phba, pring); | |
2036 | ||
2037 | if ((pring->lpfc_sli_cmd_available)) | |
2038 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2039 | ||
2040 | } | |
2041 | ||
2e0fef85 | 2042 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2043 | return rc; |
2044 | } | |
2045 | ||
e59058c4 JS |
2046 | /** |
2047 | * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings. | |
2048 | * @phba: Pointer to HBA context object. | |
2049 | * @pring: Pointer to driver SLI ring object. | |
2050 | * @mask: Host attention register mask for this ring. | |
2051 | * | |
2052 | * This function is called from the worker thread when there is a ring | |
2053 | * event for non-fcp rings. The caller does not hold any lock . | |
2054 | * The function processes each response iocb in the response ring until it | |
2055 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
2056 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the | |
2057 | * response iocb indicates a completion of a command iocb. The function | |
2058 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited | |
2059 | * iocb. The function frees the resources or calls the completion handler if | |
2060 | * this iocb is an abort completion. The function returns 0 when the allocated | |
2061 | * iocbs are not freed, otherwise returns 1. | |
2062 | **/ | |
dea3101e | 2063 | int |
2e0fef85 JS |
2064 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
2065 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2066 | { |
ed957684 JS |
2067 | struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? |
2068 | &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] : | |
2069 | &phba->slim2p->mbx.us.s2.port[pring->ringno]; | |
dea3101e JB |
2070 | IOCB_t *entry; |
2071 | IOCB_t *irsp = NULL; | |
2072 | struct lpfc_iocbq *rspiocbp = NULL; | |
2073 | struct lpfc_iocbq *next_iocb; | |
2074 | struct lpfc_iocbq *cmdiocbp; | |
2075 | struct lpfc_iocbq *saveq; | |
dea3101e JB |
2076 | uint8_t iocb_cmd_type; |
2077 | lpfc_iocb_type type; | |
2078 | uint32_t status, free_saveq; | |
2079 | uint32_t portRspPut, portRspMax; | |
2080 | int rc = 1; | |
2081 | unsigned long iflag; | |
dea3101e | 2082 | |
2e0fef85 | 2083 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2084 | pring->stats.iocb_event++; |
2085 | ||
dea3101e JB |
2086 | /* |
2087 | * The next available response entry should never exceed the maximum | |
2088 | * entries. If it does, treat it as an adapter hardware error. | |
2089 | */ | |
2090 | portRspMax = pring->numRiocb; | |
2091 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2092 | if (portRspPut >= portRspMax) { | |
2093 | /* | |
2094 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger then | |
2095 | * rsp ring <portRspMax> | |
2096 | */ | |
ed957684 | 2097 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2098 | "0303 Ring %d handler: portRspPut %d " |
dea3101e | 2099 | "is bigger then rsp ring %d\n", |
e8b62011 | 2100 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 2101 | |
2e0fef85 JS |
2102 | phba->link_state = LPFC_HBA_ERROR; |
2103 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
2104 | |
2105 | phba->work_hs = HS_FFER3; | |
2106 | lpfc_handle_eratt(phba); | |
2107 | ||
2108 | return 1; | |
2109 | } | |
2110 | ||
2111 | rmb(); | |
dea3101e JB |
2112 | while (pring->rspidx != portRspPut) { |
2113 | /* | |
2114 | * Build a completion list and call the appropriate handler. | |
2115 | * The process is to get the next available response iocb, get | |
2116 | * a free iocb from the list, copy the response data into the | |
2117 | * free iocb, insert to the continuation list, and update the | |
2118 | * next response index to slim. This process makes response | |
2119 | * iocb's in the ring available to DMA as fast as possible but | |
2120 | * pays a penalty for a copy operation. Since the iocb is | |
2121 | * only 32 bytes, this penalty is considered small relative to | |
2122 | * the PCI reads for register values and a slim write. When | |
2123 | * the ulpLe field is set, the entire Command has been | |
2124 | * received. | |
2125 | */ | |
ed957684 JS |
2126 | entry = lpfc_resp_iocb(phba, pring); |
2127 | ||
858c9f6c | 2128 | phba->last_completion_time = jiffies; |
2e0fef85 | 2129 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2130 | if (rspiocbp == NULL) { |
2131 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 2132 | "completion.\n", __func__); |
dea3101e JB |
2133 | break; |
2134 | } | |
2135 | ||
ed957684 JS |
2136 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
2137 | phba->iocb_rsp_size); | |
dea3101e JB |
2138 | irsp = &rspiocbp->iocb; |
2139 | ||
2140 | if (++pring->rspidx >= portRspMax) | |
2141 | pring->rspidx = 0; | |
2142 | ||
a58cbd52 JS |
2143 | if (pring->ringno == LPFC_ELS_RING) { |
2144 | lpfc_debugfs_slow_ring_trc(phba, | |
2145 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
2146 | *(((uint32_t *) irsp) + 4), | |
2147 | *(((uint32_t *) irsp) + 6), | |
2148 | *(((uint32_t *) irsp) + 7)); | |
2149 | } | |
2150 | ||
ed957684 | 2151 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 2152 | |
9c2face6 | 2153 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
dea3101e JB |
2154 | |
2155 | pring->iocb_continueq_cnt++; | |
2156 | if (irsp->ulpLe) { | |
2157 | /* | |
2158 | * By default, the driver expects to free all resources | |
2159 | * associated with this iocb completion. | |
2160 | */ | |
2161 | free_saveq = 1; | |
2162 | saveq = list_get_first(&pring->iocb_continueq, | |
2163 | struct lpfc_iocbq, list); | |
2164 | irsp = &(saveq->iocb); | |
2165 | list_del_init(&pring->iocb_continueq); | |
2166 | pring->iocb_continueq_cnt = 0; | |
2167 | ||
2168 | pring->stats.iocb_rsp++; | |
2169 | ||
92d7f7b0 JS |
2170 | /* |
2171 | * If resource errors reported from HBA, reduce | |
2172 | * queuedepths of the SCSI device. | |
2173 | */ | |
2174 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2175 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2176 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2177 | lpfc_adjust_queue_depth(phba); | |
2178 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2179 | } | |
2180 | ||
dea3101e JB |
2181 | if (irsp->ulpStatus) { |
2182 | /* Rsp ring <ringno> error: IOCB */ | |
ed957684 | 2183 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2184 | "0328 Rsp Ring %d error: " |
ed957684 JS |
2185 | "IOCB Data: " |
2186 | "x%x x%x x%x x%x " | |
2187 | "x%x x%x x%x x%x " | |
2188 | "x%x x%x x%x x%x " | |
2189 | "x%x x%x x%x x%x\n", | |
ed957684 JS |
2190 | pring->ringno, |
2191 | irsp->un.ulpWord[0], | |
2192 | irsp->un.ulpWord[1], | |
2193 | irsp->un.ulpWord[2], | |
2194 | irsp->un.ulpWord[3], | |
2195 | irsp->un.ulpWord[4], | |
2196 | irsp->un.ulpWord[5], | |
2197 | *(((uint32_t *) irsp) + 6), | |
2198 | *(((uint32_t *) irsp) + 7), | |
2199 | *(((uint32_t *) irsp) + 8), | |
2200 | *(((uint32_t *) irsp) + 9), | |
2201 | *(((uint32_t *) irsp) + 10), | |
2202 | *(((uint32_t *) irsp) + 11), | |
2203 | *(((uint32_t *) irsp) + 12), | |
2204 | *(((uint32_t *) irsp) + 13), | |
2205 | *(((uint32_t *) irsp) + 14), | |
2206 | *(((uint32_t *) irsp) + 15)); | |
dea3101e JB |
2207 | } |
2208 | ||
2209 | /* | |
2210 | * Fetch the IOCB command type and call the correct | |
2211 | * completion routine. Solicited and Unsolicited | |
2212 | * IOCBs on the ELS ring get freed back to the | |
2213 | * lpfc_iocb_list by the discovery kernel thread. | |
2214 | */ | |
2215 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
2216 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
2217 | if (type == LPFC_SOL_IOCB) { | |
9c2face6 | 2218 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2219 | rc = lpfc_sli_process_sol_iocb(phba, pring, |
2e0fef85 JS |
2220 | saveq); |
2221 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e | 2222 | } else if (type == LPFC_UNSOL_IOCB) { |
9c2face6 | 2223 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2224 | rc = lpfc_sli_process_unsol_iocb(phba, pring, |
2e0fef85 JS |
2225 | saveq); |
2226 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9c2face6 JS |
2227 | if (!rc) |
2228 | free_saveq = 0; | |
dea3101e JB |
2229 | } else if (type == LPFC_ABORT_IOCB) { |
2230 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && | |
2231 | ((cmdiocbp = | |
604a3e30 JB |
2232 | lpfc_sli_iocbq_lookup(phba, pring, |
2233 | saveq)))) { | |
dea3101e JB |
2234 | /* Call the specified completion |
2235 | routine */ | |
2236 | if (cmdiocbp->iocb_cmpl) { | |
2237 | spin_unlock_irqrestore( | |
2e0fef85 | 2238 | &phba->hbalock, |
dea3101e JB |
2239 | iflag); |
2240 | (cmdiocbp->iocb_cmpl) (phba, | |
2241 | cmdiocbp, saveq); | |
2242 | spin_lock_irqsave( | |
2e0fef85 | 2243 | &phba->hbalock, |
dea3101e | 2244 | iflag); |
604a3e30 | 2245 | } else |
2e0fef85 | 2246 | __lpfc_sli_release_iocbq(phba, |
604a3e30 | 2247 | cmdiocbp); |
dea3101e JB |
2248 | } |
2249 | } else if (type == LPFC_UNKNOWN_IOCB) { | |
2250 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2251 | ||
2252 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2253 | ||
2254 | memset(adaptermsg, 0, | |
2255 | LPFC_MAX_ADPTMSG); | |
2256 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2257 | MAX_MSG_DATA); | |
2258 | dev_warn(&((phba->pcidev)->dev), | |
898eb71c | 2259 | "lpfc%d: %s\n", |
dea3101e JB |
2260 | phba->brd_no, adaptermsg); |
2261 | } else { | |
2262 | /* Unknown IOCB command */ | |
92d7f7b0 | 2263 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2264 | "0335 Unknown IOCB " |
92d7f7b0 JS |
2265 | "command Data: x%x " |
2266 | "x%x x%x x%x\n", | |
92d7f7b0 JS |
2267 | irsp->ulpCommand, |
2268 | irsp->ulpStatus, | |
2269 | irsp->ulpIoTag, | |
2270 | irsp->ulpContext); | |
dea3101e JB |
2271 | } |
2272 | } | |
2273 | ||
2274 | if (free_saveq) { | |
2e0fef85 JS |
2275 | list_for_each_entry_safe(rspiocbp, next_iocb, |
2276 | &saveq->list, list) { | |
2277 | list_del(&rspiocbp->list); | |
2278 | __lpfc_sli_release_iocbq(phba, | |
2279 | rspiocbp); | |
dea3101e | 2280 | } |
2e0fef85 | 2281 | __lpfc_sli_release_iocbq(phba, saveq); |
dea3101e | 2282 | } |
92d7f7b0 | 2283 | rspiocbp = NULL; |
dea3101e JB |
2284 | } |
2285 | ||
2286 | /* | |
2287 | * If the port response put pointer has not been updated, sync | |
2288 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
2289 | * response put pointer. | |
2290 | */ | |
2291 | if (pring->rspidx == portRspPut) { | |
2292 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2293 | } | |
2294 | } /* while (pring->rspidx != portRspPut) */ | |
2295 | ||
92d7f7b0 | 2296 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
2297 | /* At least one response entry has been freed */ |
2298 | pring->stats.iocb_rsp_full++; | |
2299 | /* SET RxRE_RSP in Chip Att register */ | |
2300 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2301 | writel(status, phba->CAregaddr); | |
2302 | readl(phba->CAregaddr); /* flush */ | |
2303 | } | |
2304 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2305 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2306 | pring->stats.iocb_cmd_empty++; | |
2307 | ||
2308 | /* Force update of the local copy of cmdGetInx */ | |
2309 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2310 | lpfc_sli_resume_iocb(phba, pring); | |
2311 | ||
2312 | if ((pring->lpfc_sli_cmd_available)) | |
2313 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2314 | ||
2315 | } | |
2316 | ||
2e0fef85 | 2317 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2318 | return rc; |
2319 | } | |
2320 | ||
e59058c4 JS |
2321 | /** |
2322 | * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring. | |
2323 | * @phba: Pointer to HBA context object. | |
2324 | * @pring: Pointer to driver SLI ring object. | |
2325 | * | |
2326 | * This function aborts all iocbs in the given ring and frees all the iocb | |
2327 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
2328 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
2329 | * the return of this function. The caller is not required to hold any locks. | |
2330 | **/ | |
2e0fef85 | 2331 | void |
dea3101e JB |
2332 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
2333 | { | |
2534ba75 | 2334 | LIST_HEAD(completions); |
dea3101e | 2335 | struct lpfc_iocbq *iocb, *next_iocb; |
2534ba75 | 2336 | IOCB_t *cmd = NULL; |
dea3101e | 2337 | |
92d7f7b0 JS |
2338 | if (pring->ringno == LPFC_ELS_RING) { |
2339 | lpfc_fabric_abort_hba(phba); | |
2340 | } | |
2341 | ||
dea3101e JB |
2342 | /* Error everything on txq and txcmplq |
2343 | * First do the txq. | |
2344 | */ | |
2e0fef85 | 2345 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 2346 | list_splice_init(&pring->txq, &completions); |
dea3101e | 2347 | pring->txq_cnt = 0; |
dea3101e JB |
2348 | |
2349 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
2350 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
2351 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 2352 | |
2e0fef85 | 2353 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2354 | |
2534ba75 JS |
2355 | while (!list_empty(&completions)) { |
2356 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
2357 | cmd = &iocb->iocb; | |
92d7f7b0 | 2358 | list_del_init(&iocb->list); |
dea3101e | 2359 | |
2e0fef85 JS |
2360 | if (!iocb->iocb_cmpl) |
2361 | lpfc_sli_release_iocbq(phba, iocb); | |
2362 | else { | |
dea3101e JB |
2363 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
2364 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
dea3101e | 2365 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
2e0fef85 | 2366 | } |
dea3101e | 2367 | } |
dea3101e JB |
2368 | } |
2369 | ||
e59058c4 JS |
2370 | /** |
2371 | * lpfc_sli_brdready: Check for host status bits. | |
2372 | * @phba: Pointer to HBA context object. | |
2373 | * @mask: Bit mask to be checked. | |
2374 | * | |
2375 | * This function reads the host status register and compares | |
2376 | * with the provided bit mask to check if HBA completed | |
2377 | * the restart. This function will wait in a loop for the | |
2378 | * HBA to complete restart. If the HBA does not restart within | |
2379 | * 15 iterations, the function will reset the HBA again. The | |
2380 | * function returns 1 when HBA fail to restart otherwise returns | |
2381 | * zero. | |
2382 | **/ | |
41415862 | 2383 | int |
2e0fef85 | 2384 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
dea3101e | 2385 | { |
41415862 JW |
2386 | uint32_t status; |
2387 | int i = 0; | |
2388 | int retval = 0; | |
dea3101e | 2389 | |
41415862 JW |
2390 | /* Read the HBA Host Status Register */ |
2391 | status = readl(phba->HSregaddr); | |
dea3101e | 2392 | |
41415862 JW |
2393 | /* |
2394 | * Check status register every 100ms for 5 retries, then every | |
2395 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
2396 | * every 2.5 sec for 4. | |
2397 | * Break our of the loop if errors occurred during init. | |
2398 | */ | |
2399 | while (((status & mask) != mask) && | |
2400 | !(status & HS_FFERM) && | |
2401 | i++ < 20) { | |
dea3101e | 2402 | |
41415862 JW |
2403 | if (i <= 5) |
2404 | msleep(10); | |
2405 | else if (i <= 10) | |
2406 | msleep(500); | |
2407 | else | |
2408 | msleep(2500); | |
dea3101e | 2409 | |
41415862 | 2410 | if (i == 15) { |
2e0fef85 | 2411 | /* Do post */ |
92d7f7b0 | 2412 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
2413 | lpfc_sli_brdrestart(phba); |
2414 | } | |
2415 | /* Read the HBA Host Status Register */ | |
2416 | status = readl(phba->HSregaddr); | |
2417 | } | |
dea3101e | 2418 | |
41415862 JW |
2419 | /* Check to see if any errors occurred during init */ |
2420 | if ((status & HS_FFERM) || (i >= 20)) { | |
2e0fef85 | 2421 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 2422 | retval = 1; |
dea3101e | 2423 | } |
dea3101e | 2424 | |
41415862 JW |
2425 | return retval; |
2426 | } | |
dea3101e | 2427 | |
9290831f JS |
2428 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
2429 | ||
e59058c4 JS |
2430 | /** |
2431 | * lpfc_reset_barrier: Make HBA ready for HBA reset. | |
2432 | * @phba: Pointer to HBA context object. | |
2433 | * | |
2434 | * This function is called before resetting an HBA. This | |
2435 | * function requests HBA to quiesce DMAs before a reset. | |
2436 | **/ | |
2e0fef85 | 2437 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 2438 | { |
65a29c16 JS |
2439 | uint32_t __iomem *resp_buf; |
2440 | uint32_t __iomem *mbox_buf; | |
9290831f JS |
2441 | volatile uint32_t mbox; |
2442 | uint32_t hc_copy; | |
2443 | int i; | |
2444 | uint8_t hdrtype; | |
2445 | ||
2446 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
2447 | if (hdrtype != 0x80 || | |
2448 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
2449 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
2450 | return; | |
2451 | ||
2452 | /* | |
2453 | * Tell the other part of the chip to suspend temporarily all | |
2454 | * its DMA activity. | |
2455 | */ | |
65a29c16 | 2456 | resp_buf = phba->MBslimaddr; |
9290831f JS |
2457 | |
2458 | /* Disable the error attention */ | |
2459 | hc_copy = readl(phba->HCregaddr); | |
2460 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); | |
2461 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 2462 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f JS |
2463 | |
2464 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
2465 | /* Clear Chip error bit */ | |
2466 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 2467 | phba->pport->stopped = 1; |
9290831f JS |
2468 | } |
2469 | ||
2470 | mbox = 0; | |
2471 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
2472 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
2473 | ||
2474 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 2475 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
2476 | writel(mbox, mbox_buf); |
2477 | ||
2478 | for (i = 0; | |
2479 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) | |
2480 | mdelay(1); | |
2481 | ||
2482 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | |
2483 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || | |
2e0fef85 | 2484 | phba->pport->stopped) |
9290831f JS |
2485 | goto restore_hc; |
2486 | else | |
2487 | goto clear_errat; | |
2488 | } | |
2489 | ||
2490 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
2491 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) | |
2492 | mdelay(1); | |
2493 | ||
2494 | clear_errat: | |
2495 | ||
2496 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) | |
2497 | mdelay(1); | |
2498 | ||
2499 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
2500 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 2501 | phba->pport->stopped = 1; |
9290831f JS |
2502 | } |
2503 | ||
2504 | restore_hc: | |
2e0fef85 | 2505 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
2506 | writel(hc_copy, phba->HCregaddr); |
2507 | readl(phba->HCregaddr); /* flush */ | |
2508 | } | |
2509 | ||
e59058c4 JS |
2510 | /** |
2511 | * lpfc_sli_brdkill: Issue a kill_board mailbox command. | |
2512 | * @phba: Pointer to HBA context object. | |
2513 | * | |
2514 | * This function issues a kill_board mailbox command and waits for | |
2515 | * the error attention interrupt. This function is called for stopping | |
2516 | * the firmware processing. The caller is not required to hold any | |
2517 | * locks. This function calls lpfc_hba_down_post function to free | |
2518 | * any pending commands after the kill. The function will return 1 when it | |
2519 | * fails to kill the board else will return 0. | |
2520 | **/ | |
41415862 | 2521 | int |
2e0fef85 | 2522 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
2523 | { |
2524 | struct lpfc_sli *psli; | |
2525 | LPFC_MBOXQ_t *pmb; | |
2526 | uint32_t status; | |
2527 | uint32_t ha_copy; | |
2528 | int retval; | |
2529 | int i = 0; | |
dea3101e | 2530 | |
41415862 | 2531 | psli = &phba->sli; |
dea3101e | 2532 | |
41415862 | 2533 | /* Kill HBA */ |
ed957684 | 2534 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
2535 | "0329 Kill HBA Data: x%x x%x\n", |
2536 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 2537 | |
98c9ea5c JS |
2538 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
2539 | if (!pmb) | |
41415862 | 2540 | return 1; |
41415862 JW |
2541 | |
2542 | /* Disable the error attention */ | |
2e0fef85 | 2543 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
2544 | status = readl(phba->HCregaddr); |
2545 | status &= ~HC_ERINT_ENA; | |
2546 | writel(status, phba->HCregaddr); | |
2547 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
2548 | phba->link_flag |= LS_IGNORE_ERATT; |
2549 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
2550 | |
2551 | lpfc_kill_board(phba, pmb); | |
2552 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
2553 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
2554 | ||
2555 | if (retval != MBX_SUCCESS) { | |
2556 | if (retval != MBX_BUSY) | |
2557 | mempool_free(pmb, phba->mbox_mem_pool); | |
2e0fef85 JS |
2558 | spin_lock_irq(&phba->hbalock); |
2559 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
2560 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
2561 | return 1; |
2562 | } | |
2563 | ||
9290831f JS |
2564 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
2565 | ||
41415862 JW |
2566 | mempool_free(pmb, phba->mbox_mem_pool); |
2567 | ||
2568 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
2569 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
2570 | * 3 seconds we still set HBA_ERROR state because the status of the | |
2571 | * board is now undefined. | |
2572 | */ | |
2573 | ha_copy = readl(phba->HAregaddr); | |
2574 | ||
2575 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { | |
2576 | mdelay(100); | |
2577 | ha_copy = readl(phba->HAregaddr); | |
2578 | } | |
2579 | ||
2580 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
2581 | if (ha_copy & HA_ERATT) { |
2582 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 2583 | phba->pport->stopped = 1; |
9290831f | 2584 | } |
2e0fef85 | 2585 | spin_lock_irq(&phba->hbalock); |
41415862 | 2586 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 JS |
2587 | phba->link_flag &= ~LS_IGNORE_ERATT; |
2588 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
2589 | |
2590 | psli->mbox_active = NULL; | |
2591 | lpfc_hba_down_post(phba); | |
2e0fef85 | 2592 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 2593 | |
2e0fef85 | 2594 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
2595 | } |
2596 | ||
e59058c4 JS |
2597 | /** |
2598 | * lpfc_sli_brdreset: Reset the HBA. | |
2599 | * @phba: Pointer to HBA context object. | |
2600 | * | |
2601 | * This function resets the HBA by writing HC_INITFF to the control | |
2602 | * register. After the HBA resets, this function resets all the iocb ring | |
2603 | * indices. This function disables PCI layer parity checking during | |
2604 | * the reset. | |
2605 | * This function returns 0 always. | |
2606 | * The caller is not required to hold any locks. | |
2607 | **/ | |
41415862 | 2608 | int |
2e0fef85 | 2609 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 2610 | { |
41415862 | 2611 | struct lpfc_sli *psli; |
dea3101e | 2612 | struct lpfc_sli_ring *pring; |
41415862 | 2613 | uint16_t cfg_value; |
dea3101e | 2614 | int i; |
dea3101e | 2615 | |
41415862 | 2616 | psli = &phba->sli; |
dea3101e | 2617 | |
41415862 JW |
2618 | /* Reset HBA */ |
2619 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 2620 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 2621 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
2622 | |
2623 | /* perform board reset */ | |
2624 | phba->fc_eventTag = 0; | |
2e0fef85 JS |
2625 | phba->pport->fc_myDID = 0; |
2626 | phba->pport->fc_prevDID = 0; | |
dea3101e | 2627 | |
41415862 JW |
2628 | /* Turn off parity checking and serr during the physical reset */ |
2629 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
2630 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
2631 | (cfg_value & | |
2632 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
2633 | ||
1c067a42 | 2634 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); |
41415862 JW |
2635 | /* Now toggle INITFF bit in the Host Control Register */ |
2636 | writel(HC_INITFF, phba->HCregaddr); | |
2637 | mdelay(1); | |
2638 | readl(phba->HCregaddr); /* flush */ | |
2639 | writel(0, phba->HCregaddr); | |
2640 | readl(phba->HCregaddr); /* flush */ | |
2641 | ||
2642 | /* Restore PCI cmd register */ | |
2643 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
2644 | |
2645 | /* Initialize relevant SLI info */ | |
41415862 JW |
2646 | for (i = 0; i < psli->num_rings; i++) { |
2647 | pring = &psli->ring[i]; | |
dea3101e JB |
2648 | pring->flag = 0; |
2649 | pring->rspidx = 0; | |
2650 | pring->next_cmdidx = 0; | |
2651 | pring->local_getidx = 0; | |
2652 | pring->cmdidx = 0; | |
2653 | pring->missbufcnt = 0; | |
2654 | } | |
dea3101e | 2655 | |
2e0fef85 | 2656 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
2657 | return 0; |
2658 | } | |
2659 | ||
e59058c4 JS |
2660 | /** |
2661 | * lpfc_sli_brdrestart: Restart the HBA. | |
2662 | * @phba: Pointer to HBA context object. | |
2663 | * | |
2664 | * This function is called in the SLI initialization code path to | |
2665 | * restart the HBA. The caller is not required to hold any lock. | |
2666 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
2667 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
2668 | * function to free any pending commands. The function enables | |
2669 | * POST only during the first initialization. The function returns zero. | |
2670 | * The function does not guarantee completion of MBX_RESTART mailbox | |
2671 | * command before the return of this function. | |
2672 | **/ | |
41415862 | 2673 | int |
2e0fef85 | 2674 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
41415862 JW |
2675 | { |
2676 | MAILBOX_t *mb; | |
2677 | struct lpfc_sli *psli; | |
2678 | uint16_t skip_post; | |
2679 | volatile uint32_t word0; | |
2680 | void __iomem *to_slim; | |
2681 | ||
2e0fef85 | 2682 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
2683 | |
2684 | psli = &phba->sli; | |
2685 | ||
2686 | /* Restart HBA */ | |
2687 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 2688 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 2689 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
2690 | |
2691 | word0 = 0; | |
2692 | mb = (MAILBOX_t *) &word0; | |
2693 | mb->mbxCommand = MBX_RESTART; | |
2694 | mb->mbxHc = 1; | |
2695 | ||
9290831f JS |
2696 | lpfc_reset_barrier(phba); |
2697 | ||
41415862 JW |
2698 | to_slim = phba->MBslimaddr; |
2699 | writel(*(uint32_t *) mb, to_slim); | |
2700 | readl(to_slim); /* flush */ | |
2701 | ||
2702 | /* Only skip post after fc_ffinit is completed */ | |
2e0fef85 | 2703 | if (phba->pport->port_state) { |
41415862 JW |
2704 | skip_post = 1; |
2705 | word0 = 1; /* This is really setting up word1 */ | |
dea3101e | 2706 | } else { |
41415862 JW |
2707 | skip_post = 0; |
2708 | word0 = 0; /* This is really setting up word1 */ | |
dea3101e | 2709 | } |
65a29c16 | 2710 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
2711 | writel(*(uint32_t *) mb, to_slim); |
2712 | readl(to_slim); /* flush */ | |
dea3101e | 2713 | |
41415862 | 2714 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
2715 | phba->pport->stopped = 0; |
2716 | phba->link_state = LPFC_INIT_START; | |
41415862 | 2717 | |
2e0fef85 | 2718 | spin_unlock_irq(&phba->hbalock); |
41415862 | 2719 | |
64ba8818 JS |
2720 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
2721 | psli->stats_start = get_seconds(); | |
2722 | ||
41415862 JW |
2723 | if (skip_post) |
2724 | mdelay(100); | |
2725 | else | |
2726 | mdelay(2000); | |
2727 | ||
2728 | lpfc_hba_down_post(phba); | |
dea3101e JB |
2729 | |
2730 | return 0; | |
2731 | } | |
2732 | ||
e59058c4 JS |
2733 | /** |
2734 | * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart. | |
2735 | * @phba: Pointer to HBA context object. | |
2736 | * | |
2737 | * This function is called after a HBA restart to wait for successful | |
2738 | * restart of the HBA. Successful restart of the HBA is indicated by | |
2739 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
2740 | * iteration, the function will restart the HBA again. The function returns | |
2741 | * zero if HBA successfully restarted else returns negative error code. | |
2742 | **/ | |
dea3101e JB |
2743 | static int |
2744 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
2745 | { | |
2746 | uint32_t status, i = 0; | |
2747 | ||
2748 | /* Read the HBA Host Status Register */ | |
2749 | status = readl(phba->HSregaddr); | |
2750 | ||
2751 | /* Check status register to see what current state is */ | |
2752 | i = 0; | |
2753 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
2754 | ||
2755 | /* Check every 100ms for 5 retries, then every 500ms for 5, then | |
2756 | * every 2.5 sec for 5, then reset board and every 2.5 sec for | |
2757 | * 4. | |
2758 | */ | |
2759 | if (i++ >= 20) { | |
2760 | /* Adapter failed to init, timeout, status reg | |
2761 | <status> */ | |
ed957684 | 2762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 2763 | "0436 Adapter failed to init, " |
09372820 JS |
2764 | "timeout, status reg x%x, " |
2765 | "FW Data: A8 x%x AC x%x\n", status, | |
2766 | readl(phba->MBslimaddr + 0xa8), | |
2767 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 2768 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2769 | return -ETIMEDOUT; |
2770 | } | |
2771 | ||
2772 | /* Check to see if any errors occurred during init */ | |
2773 | if (status & HS_FFERM) { | |
2774 | /* ERROR: During chipset initialization */ | |
2775 | /* Adapter failed to init, chipset, status reg | |
2776 | <status> */ | |
ed957684 | 2777 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 2778 | "0437 Adapter failed to init, " |
09372820 JS |
2779 | "chipset, status reg x%x, " |
2780 | "FW Data: A8 x%x AC x%x\n", status, | |
2781 | readl(phba->MBslimaddr + 0xa8), | |
2782 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 2783 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2784 | return -EIO; |
2785 | } | |
2786 | ||
2787 | if (i <= 5) { | |
2788 | msleep(10); | |
2789 | } else if (i <= 10) { | |
2790 | msleep(500); | |
2791 | } else { | |
2792 | msleep(2500); | |
2793 | } | |
2794 | ||
2795 | if (i == 15) { | |
2e0fef85 | 2796 | /* Do post */ |
92d7f7b0 | 2797 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 2798 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
2799 | } |
2800 | /* Read the HBA Host Status Register */ | |
2801 | status = readl(phba->HSregaddr); | |
2802 | } | |
2803 | ||
2804 | /* Check to see if any errors occurred during init */ | |
2805 | if (status & HS_FFERM) { | |
2806 | /* ERROR: During chipset initialization */ | |
2807 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 2808 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 2809 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
2810 | "status reg x%x, " |
2811 | "FW Data: A8 x%x AC x%x\n", status, | |
2812 | readl(phba->MBslimaddr + 0xa8), | |
2813 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 2814 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2815 | return -EIO; |
2816 | } | |
2817 | ||
2818 | /* Clear all interrupt enable conditions */ | |
2819 | writel(0, phba->HCregaddr); | |
2820 | readl(phba->HCregaddr); /* flush */ | |
2821 | ||
2822 | /* setup host attn register */ | |
2823 | writel(0xffffffff, phba->HAregaddr); | |
2824 | readl(phba->HAregaddr); /* flush */ | |
2825 | return 0; | |
2826 | } | |
2827 | ||
e59058c4 JS |
2828 | /** |
2829 | * lpfc_sli_hbq_count: Get the number of HBQs to be configured. | |
2830 | * | |
2831 | * This function calculates and returns the number of HBQs required to be | |
2832 | * configured. | |
2833 | **/ | |
78b2d852 | 2834 | int |
ed957684 JS |
2835 | lpfc_sli_hbq_count(void) |
2836 | { | |
92d7f7b0 | 2837 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
2838 | } |
2839 | ||
e59058c4 JS |
2840 | /** |
2841 | * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries. | |
2842 | * | |
2843 | * This function adds the number of hbq entries in every HBQ to get | |
2844 | * the total number of hbq entries required for the HBA and returns | |
2845 | * the total count. | |
2846 | **/ | |
ed957684 JS |
2847 | static int |
2848 | lpfc_sli_hbq_entry_count(void) | |
2849 | { | |
2850 | int hbq_count = lpfc_sli_hbq_count(); | |
2851 | int count = 0; | |
2852 | int i; | |
2853 | ||
2854 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 2855 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
2856 | return count; |
2857 | } | |
2858 | ||
e59058c4 JS |
2859 | /** |
2860 | * lpfc_sli_hbq_size: Calculate memory required for all hbq entries. | |
2861 | * | |
2862 | * This function calculates amount of memory required for all hbq entries | |
2863 | * to be configured and returns the total memory required. | |
2864 | **/ | |
dea3101e | 2865 | int |
ed957684 JS |
2866 | lpfc_sli_hbq_size(void) |
2867 | { | |
2868 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
2869 | } | |
2870 | ||
e59058c4 JS |
2871 | /** |
2872 | * lpfc_sli_hbq_setup: configure and initialize HBQs. | |
2873 | * @phba: Pointer to HBA context object. | |
2874 | * | |
2875 | * This function is called during the SLI initialization to configure | |
2876 | * all the HBQs and post buffers to the HBQ. The caller is not | |
2877 | * required to hold any locks. This function will return zero if successful | |
2878 | * else it will return negative error code. | |
2879 | **/ | |
ed957684 JS |
2880 | static int |
2881 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
2882 | { | |
2883 | int hbq_count = lpfc_sli_hbq_count(); | |
2884 | LPFC_MBOXQ_t *pmb; | |
2885 | MAILBOX_t *pmbox; | |
2886 | uint32_t hbqno; | |
2887 | uint32_t hbq_entry_index; | |
ed957684 | 2888 | |
92d7f7b0 JS |
2889 | /* Get a Mailbox buffer to setup mailbox |
2890 | * commands for HBA initialization | |
2891 | */ | |
ed957684 JS |
2892 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
2893 | ||
2894 | if (!pmb) | |
2895 | return -ENOMEM; | |
2896 | ||
2897 | pmbox = &pmb->mb; | |
2898 | ||
2899 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
2900 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 2901 | phba->hbq_in_use = 1; |
ed957684 JS |
2902 | |
2903 | hbq_entry_index = 0; | |
2904 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
2905 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
2906 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
2907 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
2908 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 2909 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
2910 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
2911 | hbq_entry_index, pmb); | |
ed957684 JS |
2912 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
2913 | ||
2914 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
2915 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
2916 | mbxStatus <status>, ring <num> */ | |
2917 | ||
2918 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 2919 | LOG_SLI | LOG_VPORT, |
e8b62011 | 2920 | "1805 Adapter failed to init. " |
ed957684 | 2921 | "Data: x%x x%x x%x\n", |
e8b62011 | 2922 | pmbox->mbxCommand, |
ed957684 JS |
2923 | pmbox->mbxStatus, hbqno); |
2924 | ||
2925 | phba->link_state = LPFC_HBA_ERROR; | |
2926 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 JS |
2927 | return ENXIO; |
2928 | } | |
2929 | } | |
2930 | phba->hbq_count = hbq_count; | |
2931 | ||
ed957684 JS |
2932 | mempool_free(pmb, phba->mbox_mem_pool); |
2933 | ||
92d7f7b0 JS |
2934 | /* Initially populate or replenish the HBQs */ |
2935 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
2936 | if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno)) | |
2937 | return -ENOMEM; | |
2938 | } | |
ed957684 JS |
2939 | return 0; |
2940 | } | |
2941 | ||
e59058c4 JS |
2942 | /** |
2943 | * lpfc_do_config_port: Issue config port mailbox command. | |
2944 | * @phba: Pointer to HBA context object. | |
2945 | * @sli_mode: sli mode - 2/3 | |
2946 | * | |
2947 | * This function is called by the sli intialization code path | |
2948 | * to issue config_port mailbox command. This function restarts the | |
2949 | * HBA firmware and issues a config_port mailbox command to configure | |
2950 | * the SLI interface in the sli mode specified by sli_mode | |
2951 | * variable. The caller is not required to hold any locks. | |
2952 | * The function returns 0 if successful, else returns negative error | |
2953 | * code. | |
2954 | **/ | |
ed957684 JS |
2955 | static int |
2956 | lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
2957 | { |
2958 | LPFC_MBOXQ_t *pmb; | |
2959 | uint32_t resetcount = 0, rc = 0, done = 0; | |
2960 | ||
2961 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2962 | if (!pmb) { | |
2e0fef85 | 2963 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2964 | return -ENOMEM; |
2965 | } | |
2966 | ||
ed957684 | 2967 | phba->sli_rev = sli_mode; |
dea3101e | 2968 | while (resetcount < 2 && !done) { |
2e0fef85 | 2969 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 2970 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 2971 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 2972 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 2973 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
2974 | msleep(2500); |
2975 | rc = lpfc_sli_chipset_init(phba); | |
2976 | if (rc) | |
2977 | break; | |
2978 | ||
2e0fef85 | 2979 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 2980 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 2981 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
2982 | resetcount++; |
2983 | ||
ed957684 JS |
2984 | /* Call pre CONFIG_PORT mailbox command initialization. A |
2985 | * value of 0 means the call was successful. Any other | |
2986 | * nonzero value is a failure, but if ERESTART is returned, | |
2987 | * the driver may reset the HBA and try again. | |
2988 | */ | |
dea3101e JB |
2989 | rc = lpfc_config_port_prep(phba); |
2990 | if (rc == -ERESTART) { | |
ed957684 | 2991 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e JB |
2992 | continue; |
2993 | } else if (rc) { | |
2994 | break; | |
2995 | } | |
2996 | ||
2e0fef85 | 2997 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
2998 | lpfc_config_port(phba, pmb); |
2999 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
ed957684 | 3000 | if (rc != MBX_SUCCESS) { |
dea3101e | 3001 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 3002 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 3003 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
e8b62011 | 3004 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); |
2e0fef85 | 3005 | spin_lock_irq(&phba->hbalock); |
dea3101e | 3006 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; |
2e0fef85 JS |
3007 | spin_unlock_irq(&phba->hbalock); |
3008 | rc = -ENXIO; | |
ed957684 JS |
3009 | } else { |
3010 | done = 1; | |
92d7f7b0 JS |
3011 | phba->max_vpi = (phba->max_vpi && |
3012 | pmb->mb.un.varCfgPort.gmv) != 0 | |
3013 | ? pmb->mb.un.varCfgPort.max_vpi | |
3014 | : 0; | |
dea3101e JB |
3015 | } |
3016 | } | |
ed957684 JS |
3017 | |
3018 | if (!done) { | |
3019 | rc = -EINVAL; | |
3020 | goto do_prep_failed; | |
3021 | } | |
3022 | ||
3023 | if ((pmb->mb.un.varCfgPort.sli_mode == 3) && | |
92d7f7b0 | 3024 | (!pmb->mb.un.varCfgPort.cMA)) { |
ed957684 | 3025 | rc = -ENXIO; |
ed957684 | 3026 | } |
ed957684 | 3027 | |
92d7f7b0 | 3028 | do_prep_failed: |
ed957684 JS |
3029 | mempool_free(pmb, phba->mbox_mem_pool); |
3030 | return rc; | |
3031 | } | |
3032 | ||
e59058c4 JS |
3033 | |
3034 | /** | |
3035 | * lpfc_sli_hba_setup: SLI intialization function. | |
3036 | * @phba: Pointer to HBA context object. | |
3037 | * | |
3038 | * This function is the main SLI intialization function. This function | |
3039 | * is called by the HBA intialization code, HBA reset code and HBA | |
3040 | * error attention handler code. Caller is not required to hold any | |
3041 | * locks. This function issues config_port mailbox command to configure | |
3042 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
3043 | * calls the config_port_post function to issue init_link mailbox | |
3044 | * command and to start the discovery. The function will return zero | |
3045 | * if successful, else it will return negative error code. | |
3046 | **/ | |
ed957684 JS |
3047 | int |
3048 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
3049 | { | |
3050 | uint32_t rc; | |
92d7f7b0 | 3051 | int mode = 3; |
ed957684 JS |
3052 | |
3053 | switch (lpfc_sli_mode) { | |
3054 | case 2: | |
78b2d852 | 3055 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 3056 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 3057 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 3058 | "parameter (%d) to auto (0).\n", |
e8b62011 | 3059 | lpfc_sli_mode); |
92d7f7b0 JS |
3060 | break; |
3061 | } | |
ed957684 JS |
3062 | mode = 2; |
3063 | break; | |
3064 | case 0: | |
3065 | case 3: | |
3066 | break; | |
3067 | default: | |
92d7f7b0 | 3068 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
3069 | "1819 Unrecognized lpfc_sli_mode " |
3070 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
3071 | |
3072 | break; | |
3073 | } | |
3074 | ||
3075 | rc = lpfc_do_config_port(phba, mode); | |
3076 | if (rc && lpfc_sli_mode == 3) | |
92d7f7b0 | 3077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
3078 | "1820 Unable to select SLI-3. " |
3079 | "Not supported by adapter.\n"); | |
ed957684 JS |
3080 | if (rc && mode != 2) |
3081 | rc = lpfc_do_config_port(phba, 2); | |
3082 | if (rc) | |
dea3101e JB |
3083 | goto lpfc_sli_hba_setup_error; |
3084 | ||
ed957684 JS |
3085 | if (phba->sli_rev == 3) { |
3086 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
3087 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
3088 | phba->sli3_options |= LPFC_SLI3_ENABLED; | |
3089 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; | |
3090 | ||
3091 | } else { | |
3092 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
3093 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 3094 | phba->sli3_options = 0; |
ed957684 JS |
3095 | } |
3096 | ||
3097 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
3098 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
3099 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 3100 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
3101 | |
3102 | if (rc) | |
3103 | goto lpfc_sli_hba_setup_error; | |
3104 | ||
92d7f7b0 | 3105 | /* Init HBQs */ |
ed957684 JS |
3106 | |
3107 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { | |
3108 | rc = lpfc_sli_hbq_setup(phba); | |
3109 | if (rc) | |
3110 | goto lpfc_sli_hba_setup_error; | |
3111 | } | |
3112 | ||
dea3101e JB |
3113 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
3114 | ||
3115 | rc = lpfc_config_port_post(phba); | |
3116 | if (rc) | |
3117 | goto lpfc_sli_hba_setup_error; | |
3118 | ||
ed957684 JS |
3119 | return rc; |
3120 | ||
92d7f7b0 | 3121 | lpfc_sli_hba_setup_error: |
2e0fef85 | 3122 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 | 3123 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 3124 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
3125 | return rc; |
3126 | } | |
3127 | ||
e59058c4 JS |
3128 | |
3129 | /** | |
3130 | * lpfc_mbox_timeout: Timeout call back function for mbox timer. | |
3131 | * @ptr: context object - pointer to hba structure. | |
dea3101e | 3132 | * |
e59058c4 JS |
3133 | * This is the callback function for mailbox timer. The mailbox |
3134 | * timer is armed when a new mailbox command is issued and the timer | |
3135 | * is deleted when the mailbox complete. The function is called by | |
3136 | * the kernel timer code when a mailbox does not complete within | |
3137 | * expected time. This function wakes up the worker thread to | |
3138 | * process the mailbox timeout and returns. All the processing is | |
3139 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
3140 | **/ | |
dea3101e JB |
3141 | void |
3142 | lpfc_mbox_timeout(unsigned long ptr) | |
3143 | { | |
92d7f7b0 | 3144 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
dea3101e | 3145 | unsigned long iflag; |
2e0fef85 | 3146 | uint32_t tmo_posted; |
dea3101e | 3147 | |
2e0fef85 | 3148 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
92d7f7b0 | 3149 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
2e0fef85 JS |
3150 | if (!tmo_posted) |
3151 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
3152 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
3153 | ||
5e9d9b82 JS |
3154 | if (!tmo_posted) |
3155 | lpfc_worker_wake_up(phba); | |
3156 | return; | |
dea3101e JB |
3157 | } |
3158 | ||
e59058c4 JS |
3159 | |
3160 | /** | |
3161 | * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout. | |
3162 | * @phba: Pointer to HBA context object. | |
3163 | * | |
3164 | * This function is called from worker thread when a mailbox command times out. | |
3165 | * The caller is not required to hold any locks. This function will reset the | |
3166 | * HBA and recover all the pending commands. | |
3167 | **/ | |
dea3101e JB |
3168 | void |
3169 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
3170 | { | |
2e0fef85 JS |
3171 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
3172 | MAILBOX_t *mb = &pmbox->mb; | |
1dcb58e5 JS |
3173 | struct lpfc_sli *psli = &phba->sli; |
3174 | struct lpfc_sli_ring *pring; | |
dea3101e | 3175 | |
2e0fef85 | 3176 | if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) { |
dea3101e JB |
3177 | return; |
3178 | } | |
3179 | ||
dea3101e | 3180 | /* Mbox cmd <mbxCommand> timeout */ |
ed957684 | 3181 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 3182 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", |
92d7f7b0 JS |
3183 | mb->mbxCommand, |
3184 | phba->pport->port_state, | |
3185 | phba->sli.sli_flag, | |
3186 | phba->sli.mbox_active); | |
dea3101e | 3187 | |
1dcb58e5 JS |
3188 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
3189 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
3190 | * it to fail all oustanding SCSI IO. | |
3191 | */ | |
2e0fef85 JS |
3192 | spin_lock_irq(&phba->pport->work_port_lock); |
3193 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
3194 | spin_unlock_irq(&phba->pport->work_port_lock); | |
3195 | spin_lock_irq(&phba->hbalock); | |
3196 | phba->link_state = LPFC_LINK_UNKNOWN; | |
1dcb58e5 | 3197 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
2e0fef85 | 3198 | spin_unlock_irq(&phba->hbalock); |
1dcb58e5 JS |
3199 | |
3200 | pring = &psli->ring[psli->fcp_ring]; | |
3201 | lpfc_sli_abort_iocb_ring(phba, pring); | |
3202 | ||
3203 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
76bb24ef | 3204 | "0345 Resetting board due to mailbox timeout\n"); |
1dcb58e5 JS |
3205 | /* |
3206 | * lpfc_offline calls lpfc_sli_hba_down which will clean up | |
3207 | * on oustanding mailbox commands. | |
3208 | */ | |
13815c83 JS |
3209 | /* If resets are disabled then set error state and return. */ |
3210 | if (!phba->cfg_enable_hba_reset) { | |
3211 | phba->link_state = LPFC_HBA_ERROR; | |
3212 | return; | |
3213 | } | |
1dcb58e5 JS |
3214 | lpfc_offline_prep(phba); |
3215 | lpfc_offline(phba); | |
3216 | lpfc_sli_brdrestart(phba); | |
58da1ffb | 3217 | lpfc_online(phba); |
1dcb58e5 | 3218 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
3219 | return; |
3220 | } | |
3221 | ||
e59058c4 JS |
3222 | /** |
3223 | * lpfc_sli_issue_mbox: Issue a mailbox command to firmware. | |
3224 | * @phba: Pointer to HBA context object. | |
3225 | * @pmbox: Pointer to mailbox object. | |
3226 | * @flag: Flag indicating how the mailbox need to be processed. | |
3227 | * | |
3228 | * This function is called by discovery code and HBA management code | |
3229 | * to submit a mailbox command to firmware. This function gets the | |
3230 | * hbalock to protect the data structures. | |
3231 | * The mailbox command can be submitted in polling mode, in which case | |
3232 | * this function will wait in a polling loop for the completion of the | |
3233 | * mailbox. | |
3234 | * If the mailbox is submitted in no_wait mode (not polling) the | |
3235 | * function will submit the command and returns immediately without waiting | |
3236 | * for the mailbox completion. The no_wait is supported only when HBA | |
3237 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
3238 | * The SLI interface allows only one mailbox pending at a time. If the | |
3239 | * mailbox is issued in polling mode and there is already a mailbox | |
3240 | * pending, then the function will return an error. If the mailbox is issued | |
3241 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
3242 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
3243 | * The sli layer owns the mailbox object until the completion of mailbox | |
3244 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
3245 | * return codes the caller owns the mailbox command after the return of | |
3246 | * the function. | |
3247 | **/ | |
dea3101e | 3248 | int |
2e0fef85 | 3249 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
dea3101e | 3250 | { |
dea3101e | 3251 | MAILBOX_t *mb; |
2e0fef85 | 3252 | struct lpfc_sli *psli = &phba->sli; |
dea3101e JB |
3253 | uint32_t status, evtctr; |
3254 | uint32_t ha_copy; | |
3255 | int i; | |
09372820 | 3256 | unsigned long timeout; |
dea3101e JB |
3257 | unsigned long drvr_flag = 0; |
3258 | volatile uint32_t word0, ldata; | |
3259 | void __iomem *to_slim; | |
58da1ffb JS |
3260 | int processing_queue = 0; |
3261 | ||
3262 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
3263 | if (!pmbox) { | |
3264 | /* processing mbox queue from intr_handler */ | |
3265 | processing_queue = 1; | |
3266 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
3267 | pmbox = lpfc_mbox_get(phba); | |
3268 | if (!pmbox) { | |
3269 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
3270 | return MBX_SUCCESS; | |
3271 | } | |
3272 | } | |
dea3101e | 3273 | |
ed957684 | 3274 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 3275 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 3276 | if(!pmbox->vport) { |
58da1ffb | 3277 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 3278 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 3279 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 3280 | "1806 Mbox x%x failed. No vport\n", |
ed957684 JS |
3281 | pmbox->mb.mbxCommand); |
3282 | dump_stack(); | |
58da1ffb | 3283 | goto out_not_finished; |
ed957684 JS |
3284 | } |
3285 | } | |
3286 | ||
8d63f375 | 3287 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
3288 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
3289 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
3290 | goto out_not_finished; | |
3291 | } | |
8d63f375 | 3292 | |
dea3101e | 3293 | psli = &phba->sli; |
92d7f7b0 | 3294 | |
dea3101e JB |
3295 | mb = &pmbox->mb; |
3296 | status = MBX_SUCCESS; | |
3297 | ||
2e0fef85 JS |
3298 | if (phba->link_state == LPFC_HBA_ERROR) { |
3299 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
3300 | |
3301 | /* Mbox command <mbxCommand> cannot issue */ | |
7f5f3d0d | 3302 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
58da1ffb | 3303 | goto out_not_finished; |
41415862 JW |
3304 | } |
3305 | ||
9290831f JS |
3306 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
3307 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | |
2e0fef85 | 3308 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
7f5f3d0d | 3309 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
58da1ffb | 3310 | goto out_not_finished; |
9290831f JS |
3311 | } |
3312 | ||
dea3101e JB |
3313 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
3314 | /* Polling for a mbox command when another one is already active | |
3315 | * is not allowed in SLI. Also, the driver must have established | |
3316 | * SLI2 mode to queue and process multiple mbox commands. | |
3317 | */ | |
3318 | ||
3319 | if (flag & MBX_POLL) { | |
2e0fef85 | 3320 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
3321 | |
3322 | /* Mbox command <mbxCommand> cannot issue */ | |
92d7f7b0 | 3323 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
58da1ffb | 3324 | goto out_not_finished; |
dea3101e JB |
3325 | } |
3326 | ||
3327 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { | |
2e0fef85 | 3328 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 3329 | /* Mbox command <mbxCommand> cannot issue */ |
92d7f7b0 | 3330 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
58da1ffb | 3331 | goto out_not_finished; |
dea3101e JB |
3332 | } |
3333 | ||
dea3101e JB |
3334 | /* Another mailbox command is still being processed, queue this |
3335 | * command to be processed later. | |
3336 | */ | |
3337 | lpfc_mbox_put(phba, pmbox); | |
3338 | ||
3339 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 3340 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 3341 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 3342 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
3343 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
3344 | mb->mbxCommand, phba->pport->port_state, | |
3345 | psli->sli_flag, flag); | |
dea3101e JB |
3346 | |
3347 | psli->slistat.mbox_busy++; | |
2e0fef85 | 3348 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 3349 | |
858c9f6c JS |
3350 | if (pmbox->vport) { |
3351 | lpfc_debugfs_disc_trc(pmbox->vport, | |
3352 | LPFC_DISC_TRC_MBOX_VPORT, | |
3353 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
3354 | (uint32_t)mb->mbxCommand, | |
3355 | mb->un.varWords[0], mb->un.varWords[1]); | |
3356 | } | |
3357 | else { | |
3358 | lpfc_debugfs_disc_trc(phba->pport, | |
3359 | LPFC_DISC_TRC_MBOX, | |
3360 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
3361 | (uint32_t)mb->mbxCommand, | |
3362 | mb->un.varWords[0], mb->un.varWords[1]); | |
3363 | } | |
3364 | ||
2e0fef85 | 3365 | return MBX_BUSY; |
dea3101e JB |
3366 | } |
3367 | ||
dea3101e JB |
3368 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
3369 | ||
3370 | /* If we are not polling, we MUST be in SLI2 mode */ | |
3371 | if (flag != MBX_POLL) { | |
41415862 JW |
3372 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && |
3373 | (mb->mbxCommand != MBX_KILL_BOARD)) { | |
dea3101e | 3374 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 3375 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 3376 | /* Mbox command <mbxCommand> cannot issue */ |
92d7f7b0 | 3377 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); |
58da1ffb | 3378 | goto out_not_finished; |
dea3101e JB |
3379 | } |
3380 | /* timeout active mbox command */ | |
a309a6b6 JS |
3381 | mod_timer(&psli->mbox_tmo, (jiffies + |
3382 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e JB |
3383 | } |
3384 | ||
3385 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 3386 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 3387 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 3388 | "x%x\n", |
e8b62011 | 3389 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
3390 | mb->mbxCommand, phba->pport->port_state, |
3391 | psli->sli_flag, flag); | |
dea3101e | 3392 | |
858c9f6c JS |
3393 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
3394 | if (pmbox->vport) { | |
3395 | lpfc_debugfs_disc_trc(pmbox->vport, | |
3396 | LPFC_DISC_TRC_MBOX_VPORT, | |
3397 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
3398 | (uint32_t)mb->mbxCommand, | |
3399 | mb->un.varWords[0], mb->un.varWords[1]); | |
3400 | } | |
3401 | else { | |
3402 | lpfc_debugfs_disc_trc(phba->pport, | |
3403 | LPFC_DISC_TRC_MBOX, | |
3404 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
3405 | (uint32_t)mb->mbxCommand, | |
3406 | mb->un.varWords[0], mb->un.varWords[1]); | |
3407 | } | |
3408 | } | |
3409 | ||
dea3101e JB |
3410 | psli->slistat.mbox_cmd++; |
3411 | evtctr = psli->slistat.mbox_event; | |
3412 | ||
3413 | /* next set own bit for the adapter and copy over command word */ | |
3414 | mb->mbxOwner = OWN_CHIP; | |
3415 | ||
3416 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | |
dea3101e | 3417 | /* First copy command data to host SLIM area */ |
4cc2da1d | 3418 | lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE); |
dea3101e | 3419 | } else { |
9290831f | 3420 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 3421 | /* copy command data into host mbox for cmpl */ |
4cc2da1d | 3422 | lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, |
92d7f7b0 | 3423 | MAILBOX_CMD_SIZE); |
dea3101e JB |
3424 | } |
3425 | ||
3426 | /* First copy mbox command data to HBA SLIM, skip past first | |
3427 | word */ | |
3428 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
3429 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
3430 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
3431 | ||
3432 | /* Next copy over first word, with mbxOwner set */ | |
3433 | ldata = *((volatile uint32_t *)mb); | |
3434 | to_slim = phba->MBslimaddr; | |
3435 | writel(ldata, to_slim); | |
3436 | readl(to_slim); /* flush */ | |
3437 | ||
3438 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
3439 | /* switch over to host mailbox */ | |
3440 | psli->sli_flag |= LPFC_SLI2_ACTIVE; | |
3441 | } | |
3442 | } | |
3443 | ||
3444 | wmb(); | |
dea3101e JB |
3445 | |
3446 | switch (flag) { | |
3447 | case MBX_NOWAIT: | |
09372820 | 3448 | /* Set up reference to mailbox command */ |
dea3101e | 3449 | psli->mbox_active = pmbox; |
09372820 JS |
3450 | /* Interrupt board to do it */ |
3451 | writel(CA_MBATT, phba->CAregaddr); | |
3452 | readl(phba->CAregaddr); /* flush */ | |
3453 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
3454 | break; |
3455 | ||
3456 | case MBX_POLL: | |
09372820 | 3457 | /* Set up null reference to mailbox command */ |
dea3101e | 3458 | psli->mbox_active = NULL; |
09372820 JS |
3459 | /* Interrupt board to do it */ |
3460 | writel(CA_MBATT, phba->CAregaddr); | |
3461 | readl(phba->CAregaddr); /* flush */ | |
3462 | ||
dea3101e JB |
3463 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { |
3464 | /* First read mbox status word */ | |
4cc2da1d | 3465 | word0 = *((volatile uint32_t *)&phba->slim2p->mbx); |
dea3101e JB |
3466 | word0 = le32_to_cpu(word0); |
3467 | } else { | |
3468 | /* First read mbox status word */ | |
3469 | word0 = readl(phba->MBslimaddr); | |
3470 | } | |
3471 | ||
3472 | /* Read the HBA Host Attention Register */ | |
3473 | ha_copy = readl(phba->HAregaddr); | |
09372820 JS |
3474 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
3475 | mb->mbxCommand) * | |
3476 | 1000) + jiffies; | |
3477 | i = 0; | |
dea3101e | 3478 | /* Wait for command to complete */ |
41415862 JW |
3479 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
3480 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 3481 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 3482 | if (time_after(jiffies, timeout)) { |
dea3101e | 3483 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 3484 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 3485 | drvr_flag); |
58da1ffb | 3486 | goto out_not_finished; |
dea3101e JB |
3487 | } |
3488 | ||
3489 | /* Check if we took a mbox interrupt while we were | |
3490 | polling */ | |
3491 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
3492 | && (evtctr != psli->slistat.mbox_event)) | |
3493 | break; | |
3494 | ||
09372820 JS |
3495 | if (i++ > 10) { |
3496 | spin_unlock_irqrestore(&phba->hbalock, | |
3497 | drvr_flag); | |
3498 | msleep(1); | |
3499 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
3500 | } | |
dea3101e JB |
3501 | |
3502 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | |
3503 | /* First copy command data */ | |
4cc2da1d JSEC |
3504 | word0 = *((volatile uint32_t *) |
3505 | &phba->slim2p->mbx); | |
dea3101e JB |
3506 | word0 = le32_to_cpu(word0); |
3507 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
3508 | MAILBOX_t *slimmb; | |
3509 | volatile uint32_t slimword0; | |
3510 | /* Check real SLIM for any errors */ | |
3511 | slimword0 = readl(phba->MBslimaddr); | |
3512 | slimmb = (MAILBOX_t *) & slimword0; | |
3513 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
3514 | && slimmb->mbxStatus) { | |
3515 | psli->sli_flag &= | |
3516 | ~LPFC_SLI2_ACTIVE; | |
3517 | word0 = slimword0; | |
3518 | } | |
3519 | } | |
3520 | } else { | |
3521 | /* First copy command data */ | |
3522 | word0 = readl(phba->MBslimaddr); | |
3523 | } | |
3524 | /* Read the HBA Host Attention Register */ | |
3525 | ha_copy = readl(phba->HAregaddr); | |
3526 | } | |
3527 | ||
3528 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | |
dea3101e | 3529 | /* copy results back to user */ |
4cc2da1d | 3530 | lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb, |
92d7f7b0 | 3531 | MAILBOX_CMD_SIZE); |
dea3101e JB |
3532 | } else { |
3533 | /* First copy command data */ | |
3534 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
3535 | MAILBOX_CMD_SIZE); | |
3536 | if ((mb->mbxCommand == MBX_DUMP_MEMORY) && | |
3537 | pmbox->context2) { | |
92d7f7b0 | 3538 | lpfc_memcpy_from_slim((void *)pmbox->context2, |
dea3101e JB |
3539 | phba->MBslimaddr + DMP_RSP_OFFSET, |
3540 | mb->un.varDmp.word_cnt); | |
3541 | } | |
3542 | } | |
3543 | ||
3544 | writel(HA_MBATT, phba->HAregaddr); | |
3545 | readl(phba->HAregaddr); /* flush */ | |
3546 | ||
3547 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
3548 | status = mb->mbxStatus; | |
3549 | } | |
3550 | ||
2e0fef85 JS |
3551 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3552 | return status; | |
58da1ffb JS |
3553 | |
3554 | out_not_finished: | |
3555 | if (processing_queue) { | |
3556 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; | |
3557 | lpfc_mbox_cmpl_put(phba, pmbox); | |
3558 | } | |
3559 | return MBX_NOT_FINISHED; | |
dea3101e JB |
3560 | } |
3561 | ||
e59058c4 JS |
3562 | /** |
3563 | * __lpfc_sli_ringtx_put: Add an iocb to the txq. | |
3564 | * @phba: Pointer to HBA context object. | |
3565 | * @pring: Pointer to driver SLI ring object. | |
3566 | * @piocb: Pointer to address of newly added command iocb. | |
3567 | * | |
3568 | * This function is called with hbalock held to add a command | |
3569 | * iocb to the txq when SLI layer cannot submit the command iocb | |
3570 | * to the ring. | |
3571 | **/ | |
858c9f6c | 3572 | static void |
92d7f7b0 | 3573 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 3574 | struct lpfc_iocbq *piocb) |
dea3101e JB |
3575 | { |
3576 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
3577 | list_add_tail(&piocb->list, &pring->txq); | |
3578 | pring->txq_cnt++; | |
dea3101e JB |
3579 | } |
3580 | ||
e59058c4 JS |
3581 | /** |
3582 | * lpfc_sli_next_iocb: Get the next iocb in the txq. | |
3583 | * @phba: Pointer to HBA context object. | |
3584 | * @pring: Pointer to driver SLI ring object. | |
3585 | * @piocb: Pointer to address of newly added command iocb. | |
3586 | * | |
3587 | * This function is called with hbalock held before a new | |
3588 | * iocb is submitted to the firmware. This function checks | |
3589 | * txq to flush the iocbs in txq to Firmware before | |
3590 | * submitting new iocbs to the Firmware. | |
3591 | * If there are iocbs in the txq which need to be submitted | |
3592 | * to firmware, lpfc_sli_next_iocb returns the first element | |
3593 | * of the txq after dequeuing it from txq. | |
3594 | * If there is no iocb in the txq then the function will return | |
3595 | * *piocb and *piocb is set to NULL. Caller needs to check | |
3596 | * *piocb to find if there are more commands in the txq. | |
3597 | **/ | |
dea3101e JB |
3598 | static struct lpfc_iocbq * |
3599 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 3600 | struct lpfc_iocbq **piocb) |
dea3101e JB |
3601 | { |
3602 | struct lpfc_iocbq * nextiocb; | |
3603 | ||
3604 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
3605 | if (!nextiocb) { | |
3606 | nextiocb = *piocb; | |
3607 | *piocb = NULL; | |
3608 | } | |
3609 | ||
3610 | return nextiocb; | |
3611 | } | |
3612 | ||
e59058c4 JS |
3613 | /** |
3614 | * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb. | |
3615 | * @phba: Pointer to HBA context object. | |
3616 | * @pring: Pointer to driver SLI ring object. | |
3617 | * @piocb: Pointer to command iocb. | |
3618 | * @flag: Flag indicating if this command can be put into txq. | |
3619 | * | |
3620 | * __lpfc_sli_issue_iocb is used by other functions in the driver | |
3621 | * to issue an iocb command to the HBA. If the PCI slot is recovering | |
3622 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
3623 | * flag is turned on, the function returns IOCB_ERROR. | |
3624 | * When the link is down, this function allows only iocbs for | |
3625 | * posting buffers. | |
3626 | * This function finds next available slot in the command ring and | |
3627 | * posts the command to the available slot and writes the port | |
3628 | * attention register to request HBA start processing new iocb. | |
3629 | * If there is no slot available in the ring and | |
3630 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the | |
3631 | * txq, otherwise the function returns IOCB_BUSY. | |
3632 | * | |
3633 | * This function is called with hbalock held. | |
3634 | * The function will return success after it successfully submit the | |
3635 | * iocb to firmware or after adding to the txq. | |
3636 | **/ | |
98c9ea5c | 3637 | static int |
92d7f7b0 | 3638 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
3639 | struct lpfc_iocbq *piocb, uint32_t flag) |
3640 | { | |
3641 | struct lpfc_iocbq *nextiocb; | |
3642 | IOCB_t *iocb; | |
3643 | ||
92d7f7b0 JS |
3644 | if (piocb->iocb_cmpl && (!piocb->vport) && |
3645 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
3646 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
3647 | lpfc_printf_log(phba, KERN_ERR, | |
3648 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 3649 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
3650 | piocb->iocb.ulpCommand); |
3651 | dump_stack(); | |
3652 | return IOCB_ERROR; | |
3653 | } | |
3654 | ||
3655 | ||
8d63f375 LV |
3656 | /* If the PCI channel is in offline state, do not post iocbs. */ |
3657 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
3658 | return IOCB_ERROR; | |
3659 | ||
dea3101e JB |
3660 | /* |
3661 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
3662 | */ | |
2e0fef85 | 3663 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
3664 | return IOCB_ERROR; |
3665 | ||
3666 | /* | |
3667 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 3668 | * outstanding event. |
dea3101e | 3669 | */ |
0b727fea | 3670 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
3671 | goto iocb_busy; |
3672 | ||
2e0fef85 | 3673 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 3674 | /* |
2680eeaa | 3675 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
3676 | * can be issued if the link is not up. |
3677 | */ | |
3678 | switch (piocb->iocb.ulpCommand) { | |
3679 | case CMD_QUE_RING_BUF_CN: | |
3680 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
3681 | /* |
3682 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
3683 | * completion, iocb_cmpl MUST be 0. | |
3684 | */ | |
3685 | if (piocb->iocb_cmpl) | |
3686 | piocb->iocb_cmpl = NULL; | |
3687 | /*FALLTHROUGH*/ | |
3688 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
3689 | case CMD_CLOSE_XRI_CN: |
3690 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
3691 | break; |
3692 | default: | |
3693 | goto iocb_busy; | |
3694 | } | |
3695 | ||
3696 | /* | |
3697 | * For FCP commands, we must be in a state where we can process link | |
3698 | * attention events. | |
3699 | */ | |
3700 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 3701 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 3702 | goto iocb_busy; |
92d7f7b0 | 3703 | } |
dea3101e | 3704 | |
dea3101e JB |
3705 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
3706 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
3707 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
3708 | ||
3709 | if (iocb) | |
3710 | lpfc_sli_update_ring(phba, pring); | |
3711 | else | |
3712 | lpfc_sli_update_full_ring(phba, pring); | |
3713 | ||
3714 | if (!piocb) | |
3715 | return IOCB_SUCCESS; | |
3716 | ||
3717 | goto out_busy; | |
3718 | ||
3719 | iocb_busy: | |
3720 | pring->stats.iocb_cmd_delay++; | |
3721 | ||
3722 | out_busy: | |
3723 | ||
3724 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 3725 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
3726 | return IOCB_SUCCESS; |
3727 | } | |
3728 | ||
3729 | return IOCB_BUSY; | |
3730 | } | |
3731 | ||
92d7f7b0 | 3732 | |
e59058c4 JS |
3733 | /** |
3734 | * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb. | |
3735 | * @phba: Pointer to HBA context object. | |
3736 | * @pring: Pointer to driver SLI ring object. | |
3737 | * @piocb: Pointer to command iocb. | |
3738 | * @flag: Flag indicating if this command can be put into txq. | |
3739 | * | |
3740 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
3741 | * function. This function gets the hbalock and calls | |
3742 | * __lpfc_sli_issue_iocb function and will return the error returned | |
3743 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
3744 | * functions which do not hold hbalock. | |
3745 | **/ | |
92d7f7b0 JS |
3746 | int |
3747 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3748 | struct lpfc_iocbq *piocb, uint32_t flag) | |
3749 | { | |
3750 | unsigned long iflags; | |
3751 | int rc; | |
3752 | ||
3753 | spin_lock_irqsave(&phba->hbalock, iflags); | |
3754 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); | |
3755 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
3756 | ||
3757 | return rc; | |
3758 | } | |
3759 | ||
e59058c4 JS |
3760 | /** |
3761 | * lpfc_extra_ring_setup: Extra ring setup function. | |
3762 | * @phba: Pointer to HBA context object. | |
3763 | * | |
3764 | * This function is called while driver attaches with the | |
3765 | * HBA to setup the extra ring. The extra ring is used | |
3766 | * only when driver needs to support target mode functionality | |
3767 | * or IP over FC functionalities. | |
3768 | * | |
3769 | * This function is called with no lock held. | |
3770 | **/ | |
cf5bf97e JW |
3771 | static int |
3772 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
3773 | { | |
3774 | struct lpfc_sli *psli; | |
3775 | struct lpfc_sli_ring *pring; | |
3776 | ||
3777 | psli = &phba->sli; | |
3778 | ||
3779 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
a4bc3379 JS |
3780 | |
3781 | /* Take some away from the FCP ring */ | |
cf5bf97e JW |
3782 | pring = &psli->ring[psli->fcp_ring]; |
3783 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
3784 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
3785 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
3786 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
3787 | ||
a4bc3379 JS |
3788 | /* and give them to the extra ring */ |
3789 | pring = &psli->ring[psli->extra_ring]; | |
3790 | ||
cf5bf97e JW |
3791 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
3792 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
3793 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
3794 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
3795 | ||
3796 | /* Setup default profile for this ring */ | |
3797 | pring->iotag_max = 4096; | |
3798 | pring->num_mask = 1; | |
3799 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
3800 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
3801 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
3802 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
3803 | return 0; | |
3804 | } | |
3805 | ||
e59058c4 JS |
3806 | /** |
3807 | * lpfc_sli_async_event_handler: ASYNC iocb handler function. | |
3808 | * @phba: Pointer to HBA context object. | |
3809 | * @pring: Pointer to driver SLI ring object. | |
3810 | * @iocbq: Pointer to iocb object. | |
3811 | * | |
3812 | * This function is called by the slow ring event handler | |
3813 | * function when there is an ASYNC event iocb in the ring. | |
3814 | * This function is called with no lock held. | |
3815 | * Currently this function handles only temperature related | |
3816 | * ASYNC events. The function decodes the temperature sensor | |
3817 | * event message and posts events for the management applications. | |
3818 | **/ | |
98c9ea5c | 3819 | static void |
57127f15 JS |
3820 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
3821 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
3822 | { | |
3823 | IOCB_t *icmd; | |
3824 | uint16_t evt_code; | |
3825 | uint16_t temp; | |
3826 | struct temp_event temp_event_data; | |
3827 | struct Scsi_Host *shost; | |
3828 | ||
3829 | icmd = &iocbq->iocb; | |
3830 | evt_code = icmd->un.asyncstat.evt_code; | |
3831 | temp = icmd->ulpContext; | |
3832 | ||
3833 | if ((evt_code != ASYNC_TEMP_WARN) && | |
3834 | (evt_code != ASYNC_TEMP_SAFE)) { | |
3835 | lpfc_printf_log(phba, | |
3836 | KERN_ERR, | |
3837 | LOG_SLI, | |
76bb24ef | 3838 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
57127f15 JS |
3839 | " evt_code 0x%x\n", |
3840 | pring->ringno, | |
3841 | icmd->un.asyncstat.evt_code); | |
3842 | return; | |
3843 | } | |
3844 | temp_event_data.data = (uint32_t)temp; | |
3845 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
3846 | if (evt_code == ASYNC_TEMP_WARN) { | |
3847 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
3848 | lpfc_printf_log(phba, | |
09372820 | 3849 | KERN_ERR, |
57127f15 | 3850 | LOG_TEMP, |
76bb24ef | 3851 | "0347 Adapter is very hot, please take " |
57127f15 JS |
3852 | "corrective action. temperature : %d Celsius\n", |
3853 | temp); | |
3854 | } | |
3855 | if (evt_code == ASYNC_TEMP_SAFE) { | |
3856 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
3857 | lpfc_printf_log(phba, | |
09372820 | 3858 | KERN_ERR, |
57127f15 JS |
3859 | LOG_TEMP, |
3860 | "0340 Adapter temperature is OK now. " | |
3861 | "temperature : %d Celsius\n", | |
3862 | temp); | |
3863 | } | |
3864 | ||
3865 | /* Send temperature change event to applications */ | |
3866 | shost = lpfc_shost_from_vport(phba->pport); | |
3867 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
3868 | sizeof(temp_event_data), (char *) &temp_event_data, | |
3869 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
3870 | ||
3871 | } | |
3872 | ||
3873 | ||
e59058c4 JS |
3874 | /** |
3875 | * lpfc_sli_setup: SLI ring setup function. | |
3876 | * @phba: Pointer to HBA context object. | |
3877 | * | |
3878 | * lpfc_sli_setup sets up rings of the SLI interface with | |
3879 | * number of iocbs per ring and iotags. This function is | |
3880 | * called while driver attach to the HBA and before the | |
3881 | * interrupts are enabled. So there is no need for locking. | |
3882 | * | |
3883 | * This function always returns 0. | |
3884 | **/ | |
dea3101e JB |
3885 | int |
3886 | lpfc_sli_setup(struct lpfc_hba *phba) | |
3887 | { | |
ed957684 | 3888 | int i, totiocbsize = 0; |
dea3101e JB |
3889 | struct lpfc_sli *psli = &phba->sli; |
3890 | struct lpfc_sli_ring *pring; | |
3891 | ||
3892 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
3893 | psli->sli_flag = 0; | |
3894 | psli->fcp_ring = LPFC_FCP_RING; | |
3895 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 3896 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 3897 | |
604a3e30 JB |
3898 | psli->iocbq_lookup = NULL; |
3899 | psli->iocbq_lookup_len = 0; | |
3900 | psli->last_iotag = 0; | |
3901 | ||
dea3101e JB |
3902 | for (i = 0; i < psli->num_rings; i++) { |
3903 | pring = &psli->ring[i]; | |
3904 | switch (i) { | |
3905 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
3906 | /* numCiocb and numRiocb are used in config_port */ | |
3907 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
3908 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
3909 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
3910 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
3911 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
3912 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 3913 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3914 | SLI3_IOCB_CMD_SIZE : |
3915 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 3916 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3917 | SLI3_IOCB_RSP_SIZE : |
3918 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
3919 | pring->iotag_ctr = 0; |
3920 | pring->iotag_max = | |
92d7f7b0 | 3921 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
3922 | pring->fast_iotag = pring->iotag_max; |
3923 | pring->num_mask = 0; | |
3924 | break; | |
a4bc3379 | 3925 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e JB |
3926 | /* numCiocb and numRiocb are used in config_port */ |
3927 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
3928 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 3929 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3930 | SLI3_IOCB_CMD_SIZE : |
3931 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 3932 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3933 | SLI3_IOCB_RSP_SIZE : |
3934 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 3935 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
3936 | pring->num_mask = 0; |
3937 | break; | |
3938 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
3939 | /* numCiocb and numRiocb are used in config_port */ | |
3940 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
3941 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 3942 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3943 | SLI3_IOCB_CMD_SIZE : |
3944 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 3945 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
3946 | SLI3_IOCB_RSP_SIZE : |
3947 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
3948 | pring->fast_iotag = 0; |
3949 | pring->iotag_ctr = 0; | |
3950 | pring->iotag_max = 4096; | |
57127f15 JS |
3951 | pring->lpfc_sli_rcv_async_status = |
3952 | lpfc_sli_async_event_handler; | |
dea3101e JB |
3953 | pring->num_mask = 4; |
3954 | pring->prt[0].profile = 0; /* Mask 0 */ | |
3955 | pring->prt[0].rctl = FC_ELS_REQ; | |
3956 | pring->prt[0].type = FC_ELS_DATA; | |
3957 | pring->prt[0].lpfc_sli_rcv_unsol_event = | |
92d7f7b0 | 3958 | lpfc_els_unsol_event; |
dea3101e JB |
3959 | pring->prt[1].profile = 0; /* Mask 1 */ |
3960 | pring->prt[1].rctl = FC_ELS_RSP; | |
3961 | pring->prt[1].type = FC_ELS_DATA; | |
3962 | pring->prt[1].lpfc_sli_rcv_unsol_event = | |
92d7f7b0 | 3963 | lpfc_els_unsol_event; |
dea3101e JB |
3964 | pring->prt[2].profile = 0; /* Mask 2 */ |
3965 | /* NameServer Inquiry */ | |
3966 | pring->prt[2].rctl = FC_UNSOL_CTL; | |
3967 | /* NameServer */ | |
3968 | pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; | |
3969 | pring->prt[2].lpfc_sli_rcv_unsol_event = | |
92d7f7b0 | 3970 | lpfc_ct_unsol_event; |
dea3101e JB |
3971 | pring->prt[3].profile = 0; /* Mask 3 */ |
3972 | /* NameServer response */ | |
3973 | pring->prt[3].rctl = FC_SOL_CTL; | |
3974 | /* NameServer */ | |
3975 | pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; | |
3976 | pring->prt[3].lpfc_sli_rcv_unsol_event = | |
92d7f7b0 | 3977 | lpfc_ct_unsol_event; |
dea3101e JB |
3978 | break; |
3979 | } | |
ed957684 | 3980 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 3981 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 3982 | } |
ed957684 | 3983 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 3984 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
3985 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
3986 | "SLI2 SLIM Data: x%x x%lx\n", | |
3987 | phba->brd_no, totiocbsize, | |
3988 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 3989 | } |
cf5bf97e JW |
3990 | if (phba->cfg_multi_ring_support == 2) |
3991 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
3992 | |
3993 | return 0; | |
3994 | } | |
3995 | ||
e59058c4 JS |
3996 | /** |
3997 | * lpfc_sli_queue_setup: Queue initialization function. | |
3998 | * @phba: Pointer to HBA context object. | |
3999 | * | |
4000 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
4001 | * ring. This function also initializes ring indices of each ring. | |
4002 | * This function is called during the initialization of the SLI | |
4003 | * interface of an HBA. | |
4004 | * This function is called with no lock held and always returns | |
4005 | * 1. | |
4006 | **/ | |
dea3101e | 4007 | int |
2e0fef85 | 4008 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
4009 | { |
4010 | struct lpfc_sli *psli; | |
4011 | struct lpfc_sli_ring *pring; | |
604a3e30 | 4012 | int i; |
dea3101e JB |
4013 | |
4014 | psli = &phba->sli; | |
2e0fef85 | 4015 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4016 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 4017 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
4018 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
4019 | for (i = 0; i < psli->num_rings; i++) { | |
4020 | pring = &psli->ring[i]; | |
4021 | pring->ringno = i; | |
4022 | pring->next_cmdidx = 0; | |
4023 | pring->local_getidx = 0; | |
4024 | pring->cmdidx = 0; | |
4025 | INIT_LIST_HEAD(&pring->txq); | |
4026 | INIT_LIST_HEAD(&pring->txcmplq); | |
4027 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 4028 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 4029 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 4030 | } |
2e0fef85 JS |
4031 | spin_unlock_irq(&phba->hbalock); |
4032 | return 1; | |
dea3101e JB |
4033 | } |
4034 | ||
e59058c4 JS |
4035 | /** |
4036 | * lpfc_sli_host_down: Vport cleanup function. | |
4037 | * @vport: Pointer to virtual port object. | |
4038 | * | |
4039 | * lpfc_sli_host_down is called to clean up the resources | |
4040 | * associated with a vport before destroying virtual | |
4041 | * port data structures. | |
4042 | * This function does following operations: | |
4043 | * - Free discovery resources associated with this virtual | |
4044 | * port. | |
4045 | * - Free iocbs associated with this virtual port in | |
4046 | * the txq. | |
4047 | * - Send abort for all iocb commands associated with this | |
4048 | * vport in txcmplq. | |
4049 | * | |
4050 | * This function is called with no lock held and always returns 1. | |
4051 | **/ | |
92d7f7b0 JS |
4052 | int |
4053 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
4054 | { | |
858c9f6c | 4055 | LIST_HEAD(completions); |
92d7f7b0 JS |
4056 | struct lpfc_hba *phba = vport->phba; |
4057 | struct lpfc_sli *psli = &phba->sli; | |
4058 | struct lpfc_sli_ring *pring; | |
4059 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
4060 | int i; |
4061 | unsigned long flags = 0; | |
4062 | uint16_t prev_pring_flag; | |
4063 | ||
4064 | lpfc_cleanup_discovery_resources(vport); | |
4065 | ||
4066 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
4067 | for (i = 0; i < psli->num_rings; i++) { |
4068 | pring = &psli->ring[i]; | |
4069 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
4070 | /* Only slow rings */ |
4071 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 4072 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
4073 | /* Set the lpfc data pending flag */ |
4074 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
4075 | } | |
92d7f7b0 JS |
4076 | /* |
4077 | * Error everything on the txq since these iocbs have not been | |
4078 | * given to the FW yet. | |
4079 | */ | |
92d7f7b0 JS |
4080 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
4081 | if (iocb->vport != vport) | |
4082 | continue; | |
858c9f6c | 4083 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 4084 | pring->txq_cnt--; |
92d7f7b0 JS |
4085 | } |
4086 | ||
4087 | /* Next issue ABTS for everything on the txcmplq */ | |
4088 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
4089 | list) { | |
4090 | if (iocb->vport != vport) | |
4091 | continue; | |
4092 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
4093 | } | |
4094 | ||
4095 | pring->flag = prev_pring_flag; | |
4096 | } | |
4097 | ||
4098 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
4099 | ||
858c9f6c JS |
4100 | while (!list_empty(&completions)) { |
4101 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); | |
4102 | ||
4103 | if (!iocb->iocb_cmpl) | |
4104 | lpfc_sli_release_iocbq(phba, iocb); | |
4105 | else { | |
4106 | iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
4107 | iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN; | |
4108 | (iocb->iocb_cmpl) (phba, iocb, iocb); | |
4109 | } | |
4110 | } | |
92d7f7b0 JS |
4111 | return 1; |
4112 | } | |
4113 | ||
e59058c4 JS |
4114 | /** |
4115 | * lpfc_sli_hba_down: Resource cleanup function for the HBA. | |
4116 | * @phba: Pointer to HBA context object. | |
4117 | * | |
4118 | * This function cleans up all iocb, buffers, mailbox commands | |
4119 | * while shutting down the HBA. This function is called with no | |
4120 | * lock held and always returns 1. | |
4121 | * This function does the following to cleanup driver resources: | |
4122 | * - Free discovery resources for each virtual port | |
4123 | * - Cleanup any pending fabric iocbs | |
4124 | * - Iterate through the iocb txq and free each entry | |
4125 | * in the list. | |
4126 | * - Free up any buffer posted to the HBA | |
4127 | * - Free mailbox commands in the mailbox queue. | |
4128 | **/ | |
dea3101e | 4129 | int |
2e0fef85 | 4130 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 4131 | { |
2534ba75 | 4132 | LIST_HEAD(completions); |
2e0fef85 | 4133 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 4134 | struct lpfc_sli_ring *pring; |
0ff10d46 | 4135 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 4136 | LPFC_MBOXQ_t *pmb; |
2534ba75 JS |
4137 | struct lpfc_iocbq *iocb; |
4138 | IOCB_t *cmd = NULL; | |
dea3101e JB |
4139 | int i; |
4140 | unsigned long flags = 0; | |
4141 | ||
dea3101e JB |
4142 | lpfc_hba_down_prep(phba); |
4143 | ||
92d7f7b0 JS |
4144 | lpfc_fabric_abort_hba(phba); |
4145 | ||
2e0fef85 | 4146 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
4147 | for (i = 0; i < psli->num_rings; i++) { |
4148 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
4149 | /* Only slow rings */ |
4150 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 4151 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
4152 | /* Set the lpfc data pending flag */ |
4153 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
4154 | } | |
dea3101e JB |
4155 | |
4156 | /* | |
4157 | * Error everything on the txq since these iocbs have not been | |
4158 | * given to the FW yet. | |
4159 | */ | |
2534ba75 | 4160 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
4161 | pring->txq_cnt = 0; |
4162 | ||
2534ba75 | 4163 | } |
2e0fef85 | 4164 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 4165 | |
2534ba75 | 4166 | while (!list_empty(&completions)) { |
92d7f7b0 | 4167 | list_remove_head(&completions, iocb, struct lpfc_iocbq, list); |
2534ba75 | 4168 | cmd = &iocb->iocb; |
dea3101e | 4169 | |
2e0fef85 JS |
4170 | if (!iocb->iocb_cmpl) |
4171 | lpfc_sli_release_iocbq(phba, iocb); | |
4172 | else { | |
2534ba75 JS |
4173 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
4174 | cmd->un.ulpWord[4] = IOERR_SLI_DOWN; | |
4175 | (iocb->iocb_cmpl) (phba, iocb, iocb); | |
2e0fef85 | 4176 | } |
dea3101e JB |
4177 | } |
4178 | ||
0ff10d46 JS |
4179 | spin_lock_irqsave(&phba->hbalock, flags); |
4180 | list_splice_init(&phba->elsbuf, &completions); | |
4181 | phba->elsbuf_cnt = 0; | |
4182 | phba->elsbuf_prev_cnt = 0; | |
4183 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
4184 | ||
4185 | while (!list_empty(&completions)) { | |
4186 | list_remove_head(&completions, buf_ptr, | |
4187 | struct lpfc_dmabuf, list); | |
4188 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
4189 | kfree(buf_ptr); | |
4190 | } | |
4191 | ||
dea3101e JB |
4192 | /* Return any active mbox cmds */ |
4193 | del_timer_sync(&psli->mbox_tmo); | |
92d7f7b0 | 4194 | spin_lock_irqsave(&phba->hbalock, flags); |
2e0fef85 | 4195 | |
92d7f7b0 | 4196 | spin_lock(&phba->pport->work_port_lock); |
2e0fef85 | 4197 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
92d7f7b0 | 4198 | spin_unlock(&phba->pport->work_port_lock); |
2e0fef85 | 4199 | |
97eab634 JS |
4200 | /* Return any pending or completed mbox cmds */ |
4201 | list_splice_init(&phba->sli.mboxq, &completions); | |
92d7f7b0 JS |
4202 | if (psli->mbox_active) { |
4203 | list_add_tail(&psli->mbox_active->list, &completions); | |
2e0fef85 | 4204 | psli->mbox_active = NULL; |
2e0fef85 | 4205 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
dea3101e | 4206 | } |
92d7f7b0 | 4207 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
92d7f7b0 JS |
4208 | spin_unlock_irqrestore(&phba->hbalock, flags); |
4209 | ||
4210 | while (!list_empty(&completions)) { | |
4211 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
dea3101e | 4212 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; |
97eab634 | 4213 | if (pmb->mbox_cmpl) |
dea3101e | 4214 | pmb->mbox_cmpl(phba,pmb); |
dea3101e | 4215 | } |
dea3101e JB |
4216 | return 1; |
4217 | } | |
4218 | ||
e59058c4 JS |
4219 | /** |
4220 | * lpfc_sli_pcimem_bcopy: SLI memory copy function. | |
4221 | * @srcp: Source memory pointer. | |
4222 | * @destp: Destination memory pointer. | |
4223 | * @cnt: Number of words required to be copied. | |
4224 | * | |
4225 | * This function is used for copying data between driver memory | |
4226 | * and the SLI memory. This function also changes the endianness | |
4227 | * of each word if native endianness is different from SLI | |
4228 | * endianness. This function can be called with or without | |
4229 | * lock. | |
4230 | **/ | |
dea3101e JB |
4231 | void |
4232 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
4233 | { | |
4234 | uint32_t *src = srcp; | |
4235 | uint32_t *dest = destp; | |
4236 | uint32_t ldata; | |
4237 | int i; | |
4238 | ||
4239 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
4240 | ldata = *src; | |
4241 | ldata = le32_to_cpu(ldata); | |
4242 | *dest = ldata; | |
4243 | src++; | |
4244 | dest++; | |
4245 | } | |
4246 | } | |
4247 | ||
e59058c4 JS |
4248 | |
4249 | /** | |
4250 | * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq. | |
4251 | * @phba: Pointer to HBA context object. | |
4252 | * @pring: Pointer to driver SLI ring object. | |
4253 | * @mp: Pointer to driver buffer object. | |
4254 | * | |
4255 | * This function is called with no lock held. | |
4256 | * It always return zero after adding the buffer to the postbufq | |
4257 | * buffer list. | |
4258 | **/ | |
dea3101e | 4259 | int |
2e0fef85 JS |
4260 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
4261 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
4262 | { |
4263 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
4264 | later */ | |
2e0fef85 | 4265 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4266 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 4267 | pring->postbufq_cnt++; |
2e0fef85 | 4268 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4269 | return 0; |
4270 | } | |
4271 | ||
e59058c4 JS |
4272 | /** |
4273 | * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted | |
4274 | * using CMD_QUE_XRI64_CX iocb. | |
4275 | * @phba: Pointer to HBA context object. | |
4276 | * | |
4277 | * When HBQ is enabled, buffers are searched based on tags. This function | |
4278 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
4279 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
4280 | * does not conflict with tags of buffer posted for unsolicited events. | |
4281 | * The function returns the allocated tag. The function is called with | |
4282 | * no locks held. | |
4283 | **/ | |
76bb24ef JS |
4284 | uint32_t |
4285 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
4286 | { | |
4287 | spin_lock_irq(&phba->hbalock); | |
4288 | phba->buffer_tag_count++; | |
4289 | /* | |
4290 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
4291 | * a tag assigned by HBQ. | |
4292 | */ | |
4293 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
4294 | spin_unlock_irq(&phba->hbalock); | |
4295 | return phba->buffer_tag_count; | |
4296 | } | |
4297 | ||
e59058c4 JS |
4298 | /** |
4299 | * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with | |
4300 | * posted using CMD_QUE_XRI64_CX iocb. | |
4301 | * @phba: Pointer to HBA context object. | |
4302 | * @pring: Pointer to driver SLI ring object. | |
4303 | * @tag: Buffer tag. | |
4304 | * | |
4305 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
4306 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
4307 | * iocb is posted to the response ring with the tag of the buffer. | |
4308 | * This function searches the pring->postbufq list using the tag | |
4309 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
4310 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
4311 | * buffer is returned to the caller else NULL is returned. | |
4312 | * This function is called with no lock held. | |
4313 | **/ | |
76bb24ef JS |
4314 | struct lpfc_dmabuf * |
4315 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
4316 | uint32_t tag) | |
4317 | { | |
4318 | struct lpfc_dmabuf *mp, *next_mp; | |
4319 | struct list_head *slp = &pring->postbufq; | |
4320 | ||
4321 | /* Search postbufq, from the begining, looking for a match on tag */ | |
4322 | spin_lock_irq(&phba->hbalock); | |
4323 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
4324 | if (mp->buffer_tag == tag) { | |
4325 | list_del_init(&mp->list); | |
4326 | pring->postbufq_cnt--; | |
4327 | spin_unlock_irq(&phba->hbalock); | |
4328 | return mp; | |
4329 | } | |
4330 | } | |
4331 | ||
4332 | spin_unlock_irq(&phba->hbalock); | |
4333 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4334 | "0410 Cannot find virtual addr for buffer tag on " | |
4335 | "ring %d Data x%lx x%p x%p x%x\n", | |
4336 | pring->ringno, (unsigned long) tag, | |
4337 | slp->next, slp->prev, pring->postbufq_cnt); | |
4338 | ||
4339 | return NULL; | |
4340 | } | |
dea3101e | 4341 | |
e59058c4 JS |
4342 | /** |
4343 | * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for | |
4344 | * unsolicited ct and els events. | |
4345 | * @phba: Pointer to HBA context object. | |
4346 | * @pring: Pointer to driver SLI ring object. | |
4347 | * @phys: DMA address of the buffer. | |
4348 | * | |
4349 | * This function searches the buffer list using the dma_address | |
4350 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
4351 | * corresponding to the dma_address. The function returns the | |
4352 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
4353 | * This function is called by the ct and els unsolicited event | |
4354 | * handlers to get the buffer associated with the unsolicited | |
4355 | * event. | |
4356 | * | |
4357 | * This function is called with no lock held. | |
4358 | **/ | |
dea3101e JB |
4359 | struct lpfc_dmabuf * |
4360 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
4361 | dma_addr_t phys) | |
4362 | { | |
4363 | struct lpfc_dmabuf *mp, *next_mp; | |
4364 | struct list_head *slp = &pring->postbufq; | |
4365 | ||
4366 | /* Search postbufq, from the begining, looking for a match on phys */ | |
2e0fef85 | 4367 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
4368 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
4369 | if (mp->phys == phys) { | |
4370 | list_del_init(&mp->list); | |
4371 | pring->postbufq_cnt--; | |
2e0fef85 | 4372 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4373 | return mp; |
4374 | } | |
4375 | } | |
4376 | ||
2e0fef85 | 4377 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4378 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4379 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 4380 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 4381 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
4382 | slp->next, slp->prev, pring->postbufq_cnt); |
4383 | return NULL; | |
4384 | } | |
4385 | ||
e59058c4 JS |
4386 | /** |
4387 | * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs. | |
4388 | * @phba: Pointer to HBA context object. | |
4389 | * @cmdiocb: Pointer to driver command iocb object. | |
4390 | * @rspiocb: Pointer to driver response iocb object. | |
4391 | * | |
4392 | * This function is the completion handler for the abort iocbs for | |
4393 | * ELS commands. This function is called from the ELS ring event | |
4394 | * handler with no lock held. This function frees memory resources | |
4395 | * associated with the abort iocb. | |
4396 | **/ | |
dea3101e | 4397 | static void |
2e0fef85 JS |
4398 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
4399 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 4400 | { |
2e0fef85 | 4401 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 4402 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 4403 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
4404 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
4405 | ||
4406 | abort_iocb = NULL; | |
2680eeaa JS |
4407 | |
4408 | if (irsp->ulpStatus) { | |
4409 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
4410 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
4411 | ||
2e0fef85 | 4412 | spin_lock_irq(&phba->hbalock); |
2680eeaa JS |
4413 | if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) |
4414 | abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; | |
4415 | ||
92d7f7b0 | 4416 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI, |
e8b62011 | 4417 | "0327 Cannot abort els iocb %p " |
92d7f7b0 JS |
4418 | "with tag %x context %x, abort status %x, " |
4419 | "abort code %x\n", | |
e8b62011 JS |
4420 | abort_iocb, abort_iotag, abort_context, |
4421 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa | 4422 | |
58da1ffb JS |
4423 | /* |
4424 | * If the iocb is not found in Firmware queue the iocb | |
4425 | * might have completed already. Do not free it again. | |
4426 | */ | |
9b379605 | 4427 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
58da1ffb JS |
4428 | spin_unlock_irq(&phba->hbalock); |
4429 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
4430 | return; | |
4431 | } | |
2680eeaa JS |
4432 | /* |
4433 | * make sure we have the right iocbq before taking it | |
4434 | * off the txcmplq and try to call completion routine. | |
4435 | */ | |
2e0fef85 JS |
4436 | if (!abort_iocb || |
4437 | abort_iocb->iocb.ulpContext != abort_context || | |
4438 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
4439 | spin_unlock_irq(&phba->hbalock); | |
4440 | else { | |
92d7f7b0 | 4441 | list_del_init(&abort_iocb->list); |
2680eeaa | 4442 | pring->txcmplq_cnt--; |
2e0fef85 | 4443 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 4444 | |
0ff10d46 JS |
4445 | /* Firmware could still be in progress of DMAing |
4446 | * payload, so don't free data buffer till after | |
4447 | * a hbeat. | |
4448 | */ | |
4449 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
4450 | ||
92d7f7b0 JS |
4451 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
4452 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
4453 | abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; | |
4454 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); | |
2680eeaa JS |
4455 | } |
4456 | } | |
4457 | ||
604a3e30 | 4458 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
4459 | return; |
4460 | } | |
4461 | ||
e59058c4 JS |
4462 | /** |
4463 | * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command. | |
4464 | * @phba: Pointer to HBA context object. | |
4465 | * @cmdiocb: Pointer to driver command iocb object. | |
4466 | * @rspiocb: Pointer to driver response iocb object. | |
4467 | * | |
4468 | * The function is called from SLI ring event handler with no | |
4469 | * lock held. This function is the completion handler for ELS commands | |
4470 | * which are aborted. The function frees memory resources used for | |
4471 | * the aborted ELS commands. | |
4472 | **/ | |
92d7f7b0 JS |
4473 | static void |
4474 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
4475 | struct lpfc_iocbq *rspiocb) | |
4476 | { | |
4477 | IOCB_t *irsp = &rspiocb->iocb; | |
4478 | ||
4479 | /* ELS cmd tag <ulpIoTag> completes */ | |
4480 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
e8b62011 | 4481 | "0133 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 4482 | "x%x x%x x%x\n", |
e8b62011 | 4483 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 4484 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
4485 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
4486 | lpfc_ct_free_iocb(phba, cmdiocb); | |
4487 | else | |
4488 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
4489 | return; |
4490 | } | |
4491 | ||
e59058c4 JS |
4492 | /** |
4493 | * lpfc_sli_issue_abort_iotag: Abort function for a command iocb. | |
4494 | * @phba: Pointer to HBA context object. | |
4495 | * @pring: Pointer to driver SLI ring object. | |
4496 | * @cmdiocb: Pointer to driver command iocb object. | |
4497 | * | |
4498 | * This function issues an abort iocb for the provided command | |
4499 | * iocb. This function is called with hbalock held. | |
4500 | * The function returns 0 when it fails due to memory allocation | |
4501 | * failure or when the command iocb is an abort request. | |
4502 | **/ | |
dea3101e | 4503 | int |
2e0fef85 JS |
4504 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
4505 | struct lpfc_iocbq *cmdiocb) | |
dea3101e | 4506 | { |
2e0fef85 | 4507 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 4508 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
4509 | IOCB_t *icmd = NULL; |
4510 | IOCB_t *iabt = NULL; | |
07951076 JS |
4511 | int retval = IOCB_ERROR; |
4512 | ||
92d7f7b0 JS |
4513 | /* |
4514 | * There are certain command types we don't want to abort. And we | |
4515 | * don't want to abort commands that are already in the process of | |
4516 | * being aborted. | |
07951076 JS |
4517 | */ |
4518 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 4519 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
4520 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
4521 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
4522 | return 0; |
4523 | ||
858c9f6c JS |
4524 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
4525 | * callback so that nothing happens when it finishes. | |
07951076 | 4526 | */ |
858c9f6c JS |
4527 | if ((vport->load_flag & FC_UNLOADING) && |
4528 | (pring->ringno == LPFC_ELS_RING)) { | |
92d7f7b0 JS |
4529 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
4530 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
4531 | else | |
4532 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
07951076 | 4533 | goto abort_iotag_exit; |
92d7f7b0 | 4534 | } |
dea3101e JB |
4535 | |
4536 | /* issue ABTS for this IOCB based on iotag */ | |
92d7f7b0 | 4537 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
4538 | if (abtsiocbp == NULL) |
4539 | return 0; | |
dea3101e | 4540 | |
07951076 JS |
4541 | /* This signals the response to set the correct status |
4542 | * before calling the completion handler. | |
4543 | */ | |
4544 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
4545 | ||
dea3101e | 4546 | iabt = &abtsiocbp->iocb; |
07951076 JS |
4547 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
4548 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
4549 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
4550 | iabt->ulpLe = 1; | |
4551 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 4552 | |
2e0fef85 | 4553 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
4554 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
4555 | else | |
4556 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 4557 | |
07951076 | 4558 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 4559 | |
e8b62011 JS |
4560 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
4561 | "0339 Abort xri x%x, original iotag x%x, " | |
4562 | "abort cmd iotag x%x\n", | |
4563 | iabt->un.acxri.abortContextTag, | |
4564 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); | |
92d7f7b0 | 4565 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); |
dea3101e | 4566 | |
07951076 | 4567 | abort_iotag_exit: |
2e0fef85 JS |
4568 | /* |
4569 | * Caller to this routine should check for IOCB_ERROR | |
4570 | * and handle it properly. This routine no longer removes | |
4571 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 4572 | */ |
2e0fef85 | 4573 | return retval; |
dea3101e JB |
4574 | } |
4575 | ||
e59058c4 JS |
4576 | /** |
4577 | * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands | |
4578 | * associated with a vport/SCSI target/lun. | |
4579 | * @iocbq: Pointer to driver iocb object. | |
4580 | * @vport: Pointer to driver virtual port object. | |
4581 | * @tgt_id: SCSI ID of the target. | |
4582 | * @lun_id: LUN ID of the scsi device. | |
4583 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
4584 | * | |
4585 | * This function acts as iocb filter for functions which abort or count | |
4586 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return | |
4587 | * 0 if the filtering criteria is met for the given iocb and will return | |
4588 | * 1 if the filtering criteria is not met. | |
4589 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
4590 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
4591 | * lun_id parameter. | |
4592 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
4593 | * given iocb is for the SCSI target specified by vport and tgt_id | |
4594 | * parameters. | |
4595 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
4596 | * given iocb is for the SCSI host associated with the given vport. | |
4597 | * This function is called with no locks held. | |
4598 | **/ | |
dea3101e | 4599 | static int |
51ef4c26 JS |
4600 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
4601 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 4602 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 4603 | { |
0bd4ca25 | 4604 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
4605 | int rc = 1; |
4606 | ||
0bd4ca25 JSEC |
4607 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
4608 | return rc; | |
4609 | ||
51ef4c26 JS |
4610 | if (iocbq->vport != vport) |
4611 | return rc; | |
4612 | ||
0bd4ca25 | 4613 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 4614 | |
495a714c | 4615 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
4616 | return rc; |
4617 | ||
4618 | switch (ctx_cmd) { | |
4619 | case LPFC_CTX_LUN: | |
495a714c JS |
4620 | if ((lpfc_cmd->rdata->pnode) && |
4621 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
4622 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
4623 | rc = 0; |
4624 | break; | |
4625 | case LPFC_CTX_TGT: | |
495a714c JS |
4626 | if ((lpfc_cmd->rdata->pnode) && |
4627 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
4628 | rc = 0; |
4629 | break; | |
dea3101e JB |
4630 | case LPFC_CTX_HOST: |
4631 | rc = 0; | |
4632 | break; | |
4633 | default: | |
4634 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 4635 | __func__, ctx_cmd); |
dea3101e JB |
4636 | break; |
4637 | } | |
4638 | ||
4639 | return rc; | |
4640 | } | |
4641 | ||
e59058c4 JS |
4642 | /** |
4643 | * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending. | |
4644 | * @vport: Pointer to virtual port. | |
4645 | * @tgt_id: SCSI ID of the target. | |
4646 | * @lun_id: LUN ID of the scsi device. | |
4647 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
4648 | * | |
4649 | * This function returns number of FCP commands pending for the vport. | |
4650 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
4651 | * commands pending on the vport associated with SCSI device specified | |
4652 | * by tgt_id and lun_id parameters. | |
4653 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
4654 | * commands pending on the vport associated with SCSI target specified | |
4655 | * by tgt_id parameter. | |
4656 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
4657 | * commands pending on the vport. | |
4658 | * This function returns the number of iocbs which satisfy the filter. | |
4659 | * This function is called without any lock held. | |
4660 | **/ | |
dea3101e | 4661 | int |
51ef4c26 JS |
4662 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
4663 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 4664 | { |
51ef4c26 | 4665 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
4666 | struct lpfc_iocbq *iocbq; |
4667 | int sum, i; | |
dea3101e | 4668 | |
0bd4ca25 JSEC |
4669 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
4670 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 4671 | |
51ef4c26 JS |
4672 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
4673 | ctx_cmd) == 0) | |
0bd4ca25 | 4674 | sum++; |
dea3101e | 4675 | } |
0bd4ca25 | 4676 | |
dea3101e JB |
4677 | return sum; |
4678 | } | |
4679 | ||
e59058c4 JS |
4680 | /** |
4681 | * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted | |
4682 | * FCP iocb. | |
4683 | * @phba: Pointer to HBA context object | |
4684 | * @cmdiocb: Pointer to command iocb object. | |
4685 | * @rspiocb: Pointer to response iocb object. | |
4686 | * | |
4687 | * This function is called when an aborted FCP iocb completes. This | |
4688 | * function is called by the ring event handler with no lock held. | |
4689 | * This function frees the iocb. | |
4690 | **/ | |
5eb95af0 | 4691 | void |
2e0fef85 JS |
4692 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
4693 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 4694 | { |
604a3e30 | 4695 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
4696 | return; |
4697 | } | |
4698 | ||
e59058c4 JS |
4699 | /** |
4700 | * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands | |
4701 | * pending on a SCSI host(vport)/target/lun. | |
4702 | * @vport: Pointer to virtual port. | |
4703 | * @pring: Pointer to driver SLI ring object. | |
4704 | * @tgt_id: SCSI ID of the target. | |
4705 | * @lun_id: LUN ID of the scsi device. | |
4706 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
4707 | * | |
4708 | * This function sends an abort command for every SCSI command | |
4709 | * associated with the given virtual port pending on the ring | |
4710 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
4711 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
4712 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
4713 | * parameters | |
4714 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
4715 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
4716 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
4717 | * FCP iocbs associated with virtual port. | |
4718 | * This function returns number of iocbs it failed to abort. | |
4719 | * This function is called with no locks held. | |
4720 | **/ | |
dea3101e | 4721 | int |
51ef4c26 JS |
4722 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
4723 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 4724 | { |
51ef4c26 | 4725 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
4726 | struct lpfc_iocbq *iocbq; |
4727 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 4728 | IOCB_t *cmd = NULL; |
dea3101e | 4729 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 4730 | int i; |
dea3101e | 4731 | |
0bd4ca25 JSEC |
4732 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
4733 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 4734 | |
51ef4c26 | 4735 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 4736 | abort_cmd) != 0) |
dea3101e JB |
4737 | continue; |
4738 | ||
4739 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 4740 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
4741 | if (abtsiocb == NULL) { |
4742 | errcnt++; | |
4743 | continue; | |
4744 | } | |
dea3101e | 4745 | |
0bd4ca25 | 4746 | cmd = &iocbq->iocb; |
dea3101e JB |
4747 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
4748 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
4749 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
4750 | abtsiocb->iocb.ulpLe = 1; | |
4751 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 4752 | abtsiocb->vport = phba->pport; |
dea3101e | 4753 | |
2e0fef85 | 4754 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
4755 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
4756 | else | |
4757 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
4758 | ||
5eb95af0 JSEC |
4759 | /* Setup callback routine and issue the command. */ |
4760 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
dea3101e JB |
4761 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); |
4762 | if (ret_val == IOCB_ERROR) { | |
604a3e30 | 4763 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
4764 | errcnt++; |
4765 | continue; | |
4766 | } | |
4767 | } | |
4768 | ||
4769 | return errcnt; | |
4770 | } | |
4771 | ||
e59058c4 JS |
4772 | /** |
4773 | * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using | |
4774 | * lpfc_sli_issue_iocb_wait. | |
4775 | * @phba: Pointer to HBA context object. | |
4776 | * @cmdiocbq: Pointer to command iocb. | |
4777 | * @rspiocbq: Pointer to response iocb. | |
4778 | * | |
4779 | * This function is the completion handler for iocbs issued using | |
4780 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
4781 | * ring event handler function without any lock held. This function | |
4782 | * can be called from both worker thread context and interrupt | |
4783 | * context. This function also can be called from other thread which | |
4784 | * cleans up the SLI layer objects. | |
4785 | * This function copy the contents of the response iocb to the | |
4786 | * response iocb memory object provided by the caller of | |
4787 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
4788 | * sleeps for the iocb completion. | |
4789 | **/ | |
68876920 JSEC |
4790 | static void |
4791 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
4792 | struct lpfc_iocbq *cmdiocbq, | |
4793 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 4794 | { |
68876920 JSEC |
4795 | wait_queue_head_t *pdone_q; |
4796 | unsigned long iflags; | |
dea3101e | 4797 | |
2e0fef85 | 4798 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
4799 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
4800 | if (cmdiocbq->context2 && rspiocbq) | |
4801 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
4802 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
4803 | ||
4804 | pdone_q = cmdiocbq->context_un.wait_queue; | |
68876920 JSEC |
4805 | if (pdone_q) |
4806 | wake_up(pdone_q); | |
858c9f6c | 4807 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
4808 | return; |
4809 | } | |
4810 | ||
e59058c4 JS |
4811 | /** |
4812 | * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands. | |
4813 | * @phba: Pointer to HBA context object.. | |
4814 | * @pring: Pointer to sli ring. | |
4815 | * @piocb: Pointer to command iocb. | |
4816 | * @prspiocbq: Pointer to response iocb. | |
4817 | * @timeout: Timeout in number of seconds. | |
4818 | * | |
4819 | * This function issues the iocb to firmware and waits for the | |
4820 | * iocb to complete. If the iocb command is not | |
4821 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
4822 | * Caller should not free the iocb resources if this function | |
4823 | * returns IOCB_TIMEDOUT. | |
4824 | * The function waits for the iocb completion using an | |
4825 | * non-interruptible wait. | |
4826 | * This function will sleep while waiting for iocb completion. | |
4827 | * So, this function should not be called from any context which | |
4828 | * does not allow sleeping. Due to the same reason, this function | |
4829 | * cannot be called with interrupt disabled. | |
4830 | * This function assumes that the iocb completions occur while | |
4831 | * this function sleep. So, this function cannot be called from | |
4832 | * the thread which process iocb completion for this ring. | |
4833 | * This function clears the iocb_flag of the iocb object before | |
4834 | * issuing the iocb and the iocb completion handler sets this | |
4835 | * flag and wakes this thread when the iocb completes. | |
4836 | * The contents of the response iocb will be copied to prspiocbq | |
4837 | * by the completion handler when the command completes. | |
4838 | * This function returns IOCB_SUCCESS when success. | |
4839 | * This function is called with no lock held. | |
4840 | **/ | |
dea3101e | 4841 | int |
2e0fef85 JS |
4842 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
4843 | struct lpfc_sli_ring *pring, | |
4844 | struct lpfc_iocbq *piocb, | |
4845 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 4846 | uint32_t timeout) |
dea3101e | 4847 | { |
7259f0d0 | 4848 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
4849 | long timeleft, timeout_req = 0; |
4850 | int retval = IOCB_SUCCESS; | |
875fbdfe | 4851 | uint32_t creg_val; |
dea3101e JB |
4852 | |
4853 | /* | |
68876920 JSEC |
4854 | * If the caller has provided a response iocbq buffer, then context2 |
4855 | * is NULL or its an error. | |
dea3101e | 4856 | */ |
68876920 JSEC |
4857 | if (prspiocbq) { |
4858 | if (piocb->context2) | |
4859 | return IOCB_ERROR; | |
4860 | piocb->context2 = prspiocbq; | |
dea3101e JB |
4861 | } |
4862 | ||
68876920 JSEC |
4863 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
4864 | piocb->context_un.wait_queue = &done_q; | |
4865 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 4866 | |
875fbdfe JSEC |
4867 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
4868 | creg_val = readl(phba->HCregaddr); | |
4869 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
4870 | writel(creg_val, phba->HCregaddr); | |
4871 | readl(phba->HCregaddr); /* flush */ | |
4872 | } | |
4873 | ||
68876920 JSEC |
4874 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); |
4875 | if (retval == IOCB_SUCCESS) { | |
4876 | timeout_req = timeout * HZ; | |
68876920 JSEC |
4877 | timeleft = wait_event_timeout(done_q, |
4878 | piocb->iocb_flag & LPFC_IO_WAKE, | |
4879 | timeout_req); | |
dea3101e | 4880 | |
7054a606 JS |
4881 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
4882 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 4883 | "0331 IOCB wake signaled\n"); |
7054a606 | 4884 | } else if (timeleft == 0) { |
68876920 | 4885 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
4886 | "0338 IOCB wait timeout error - no " |
4887 | "wake response Data x%x\n", timeout); | |
68876920 | 4888 | retval = IOCB_TIMEDOUT; |
7054a606 | 4889 | } else { |
68876920 | 4890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
4891 | "0330 IOCB wake NOT set, " |
4892 | "Data x%x x%lx\n", | |
68876920 JSEC |
4893 | timeout, (timeleft / jiffies)); |
4894 | retval = IOCB_TIMEDOUT; | |
dea3101e | 4895 | } |
68876920 JSEC |
4896 | } else { |
4897 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 JS |
4898 | ":0332 IOCB wait issue failed, Data x%x\n", |
4899 | retval); | |
68876920 | 4900 | retval = IOCB_ERROR; |
dea3101e JB |
4901 | } |
4902 | ||
875fbdfe JSEC |
4903 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
4904 | creg_val = readl(phba->HCregaddr); | |
4905 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
4906 | writel(creg_val, phba->HCregaddr); | |
4907 | readl(phba->HCregaddr); /* flush */ | |
4908 | } | |
4909 | ||
68876920 JSEC |
4910 | if (prspiocbq) |
4911 | piocb->context2 = NULL; | |
4912 | ||
4913 | piocb->context_un.wait_queue = NULL; | |
4914 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
4915 | return retval; |
4916 | } | |
68876920 | 4917 | |
e59058c4 JS |
4918 | /** |
4919 | * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox. | |
4920 | * @phba: Pointer to HBA context object. | |
4921 | * @pmboxq: Pointer to driver mailbox object. | |
4922 | * @timeout: Timeout in number of seconds. | |
4923 | * | |
4924 | * This function issues the mailbox to firmware and waits for the | |
4925 | * mailbox command to complete. If the mailbox command is not | |
4926 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
4927 | * The function waits for the mailbox completion using an | |
4928 | * interruptible wait. If the thread is woken up due to a | |
4929 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
4930 | * should not free the mailbox resources, if this function returns | |
4931 | * MBX_TIMEOUT. | |
4932 | * This function will sleep while waiting for mailbox completion. | |
4933 | * So, this function should not be called from any context which | |
4934 | * does not allow sleeping. Due to the same reason, this function | |
4935 | * cannot be called with interrupt disabled. | |
4936 | * This function assumes that the mailbox completion occurs while | |
4937 | * this function sleep. So, this function cannot be called from | |
4938 | * the worker thread which processes mailbox completion. | |
4939 | * This function is called in the context of HBA management | |
4940 | * applications. | |
4941 | * This function returns MBX_SUCCESS when successful. | |
4942 | * This function is called with no lock held. | |
4943 | **/ | |
dea3101e | 4944 | int |
2e0fef85 | 4945 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
4946 | uint32_t timeout) |
4947 | { | |
7259f0d0 | 4948 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 4949 | int retval; |
858c9f6c | 4950 | unsigned long flag; |
dea3101e JB |
4951 | |
4952 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 4953 | if (pmboxq->context1) |
2e0fef85 | 4954 | return MBX_NOT_FINISHED; |
dea3101e | 4955 | |
495a714c | 4956 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
4957 | /* setup wake call as IOCB callback */ |
4958 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
4959 | /* setup context field to pass wait_queue pointer to wake function */ | |
4960 | pmboxq->context1 = &done_q; | |
4961 | ||
dea3101e JB |
4962 | /* now issue the command */ |
4963 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
4964 | ||
4965 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
4966 | wait_event_interruptible_timeout(done_q, |
4967 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
4968 | timeout * HZ); | |
4969 | ||
858c9f6c | 4970 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 4971 | pmboxq->context1 = NULL; |
7054a606 JS |
4972 | /* |
4973 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
4974 | * else do not free the resources. | |
4975 | */ | |
4976 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) | |
dea3101e | 4977 | retval = MBX_SUCCESS; |
858c9f6c | 4978 | else { |
7054a606 | 4979 | retval = MBX_TIMEOUT; |
858c9f6c JS |
4980 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
4981 | } | |
4982 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
4983 | } |
4984 | ||
dea3101e JB |
4985 | return retval; |
4986 | } | |
4987 | ||
e59058c4 JS |
4988 | /** |
4989 | * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function. | |
4990 | * @phba: Pointer to HBA context. | |
4991 | * | |
4992 | * This function is called to cleanup any pending mailbox | |
4993 | * objects in the driver queue before bringing the HBA offline. | |
4994 | * This function is called while resetting the HBA. | |
4995 | * The function is called without any lock held. The function | |
4996 | * takes hbalock to update SLI data structure. | |
4997 | * This function returns 1 when there is an active mailbox | |
4998 | * command pending else returns 0. | |
4999 | **/ | |
b4c02652 JS |
5000 | int |
5001 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) | |
5002 | { | |
2e0fef85 | 5003 | struct lpfc_vport *vport = phba->pport; |
b4c02652 | 5004 | int i = 0; |
ed957684 | 5005 | uint32_t ha_copy; |
b4c02652 | 5006 | |
2e0fef85 | 5007 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { |
b4c02652 JS |
5008 | if (i++ > LPFC_MBOX_TMO * 1000) |
5009 | return 1; | |
5010 | ||
ed957684 JS |
5011 | /* |
5012 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd | |
5013 | * did finish. This way we won't get the misleading | |
5014 | * "Stray Mailbox Interrupt" message. | |
5015 | */ | |
5016 | spin_lock_irq(&phba->hbalock); | |
5017 | ha_copy = phba->work_ha; | |
5018 | phba->work_ha &= ~HA_MBATT; | |
5019 | spin_unlock_irq(&phba->hbalock); | |
5020 | ||
5021 | if (ha_copy & HA_MBATT) | |
5022 | if (lpfc_sli_handle_mb_event(phba) == 0) | |
5023 | i = 0; | |
b4c02652 JS |
5024 | |
5025 | msleep(1); | |
5026 | } | |
5027 | ||
5028 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; | |
5029 | } | |
5030 | ||
e59058c4 JS |
5031 | /** |
5032 | * lpfc_intr_handler: The interrupt handler of lpfc driver. | |
5033 | * @irq: Interrupt number. | |
5034 | * @dev_id: The device context pointer. | |
5035 | * | |
5036 | * This function is called from the PCI layer when there is | |
5037 | * an event in the HBA which requires driver attention. When | |
5038 | * the PCI slot is in error recovery or the HBA is undergoing | |
5039 | * initialization the interrupt handler will not process the | |
5040 | * interrupt. | |
5041 | * The error attention, link attention and els ring attention | |
5042 | * events are handled by the worker thread. The interrupt | |
5043 | * handler signals the worker thread and returns for these | |
5044 | * events. | |
5045 | * The SCSI ring event and mailbox events are handled in the | |
5046 | * interrupt context. | |
5047 | * This function is called without any lock held. It gets the | |
5048 | * hbalock to access and update SLI data structures. | |
5049 | * This function returns IRQ_HANDLED when interrupt is handled | |
5050 | * else it returns IRQ_NONE. | |
5051 | **/ | |
dea3101e | 5052 | irqreturn_t |
7d12e780 | 5053 | lpfc_intr_handler(int irq, void *dev_id) |
dea3101e | 5054 | { |
2e0fef85 | 5055 | struct lpfc_hba *phba; |
dea3101e JB |
5056 | uint32_t ha_copy; |
5057 | uint32_t work_ha_copy; | |
5058 | unsigned long status; | |
dea3101e JB |
5059 | uint32_t control; |
5060 | ||
92d7f7b0 | 5061 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
5062 | struct lpfc_vport *vport; |
5063 | struct lpfc_nodelist *ndlp; | |
5064 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
5065 | LPFC_MBOXQ_t *pmb; |
5066 | int rc; | |
5067 | ||
dea3101e JB |
5068 | /* |
5069 | * Get the driver's phba structure from the dev_id and | |
5070 | * assume the HBA is not interrupting. | |
5071 | */ | |
5072 | phba = (struct lpfc_hba *) dev_id; | |
5073 | ||
5074 | if (unlikely(!phba)) | |
5075 | return IRQ_NONE; | |
5076 | ||
8d63f375 LV |
5077 | /* If the pci channel is offline, ignore all the interrupts. */ |
5078 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
5079 | return IRQ_NONE; | |
5080 | ||
dea3101e JB |
5081 | phba->sli.slistat.sli_intr++; |
5082 | ||
5083 | /* | |
5084 | * Call the HBA to see if it is interrupting. If not, don't claim | |
5085 | * the interrupt | |
5086 | */ | |
5087 | ||
5088 | /* Ignore all interrupts during initialization. */ | |
2e0fef85 | 5089 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
5090 | return IRQ_NONE; |
5091 | ||
5092 | /* | |
5093 | * Read host attention register to determine interrupt source | |
5094 | * Clear Attention Sources, except Error Attention (to | |
5095 | * preserve status) and Link Attention | |
5096 | */ | |
2e0fef85 | 5097 | spin_lock(&phba->hbalock); |
dea3101e | 5098 | ha_copy = readl(phba->HAregaddr); |
ebdbe65f JS |
5099 | /* If somebody is waiting to handle an eratt don't process it |
5100 | * here. The brdkill function will do this. | |
5101 | */ | |
2e0fef85 | 5102 | if (phba->link_flag & LS_IGNORE_ERATT) |
ebdbe65f | 5103 | ha_copy &= ~HA_ERATT; |
dea3101e JB |
5104 | writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
5105 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 5106 | spin_unlock(&phba->hbalock); |
dea3101e JB |
5107 | |
5108 | if (unlikely(!ha_copy)) | |
5109 | return IRQ_NONE; | |
5110 | ||
5111 | work_ha_copy = ha_copy & phba->work_ha_mask; | |
5112 | ||
5113 | if (unlikely(work_ha_copy)) { | |
5114 | if (work_ha_copy & HA_LATT) { | |
5115 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
5116 | /* | |
5117 | * Turn off Link Attention interrupts | |
5118 | * until CLEAR_LA done | |
5119 | */ | |
2e0fef85 | 5120 | spin_lock(&phba->hbalock); |
dea3101e JB |
5121 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
5122 | control = readl(phba->HCregaddr); | |
5123 | control &= ~HC_LAINT_ENA; | |
5124 | writel(control, phba->HCregaddr); | |
5125 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 5126 | spin_unlock(&phba->hbalock); |
dea3101e JB |
5127 | } |
5128 | else | |
5129 | work_ha_copy &= ~HA_LATT; | |
5130 | } | |
5131 | ||
5132 | if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) { | |
858c9f6c JS |
5133 | /* |
5134 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
5135 | * the only slow ring. | |
5136 | */ | |
5137 | status = (work_ha_copy & | |
5138 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
5139 | status >>= (4*LPFC_ELS_RING); | |
5140 | if (status & HA_RXMASK) { | |
5141 | spin_lock(&phba->hbalock); | |
5142 | control = readl(phba->HCregaddr); | |
a58cbd52 JS |
5143 | |
5144 | lpfc_debugfs_slow_ring_trc(phba, | |
5145 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
5146 | control, status, | |
5147 | (uint32_t)phba->sli.slistat.sli_intr); | |
5148 | ||
858c9f6c | 5149 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
5150 | lpfc_debugfs_slow_ring_trc(phba, |
5151 | "ISR Disable ring:" | |
5152 | "pwork:x%x hawork:x%x wait:x%x", | |
5153 | phba->work_ha, work_ha_copy, | |
5154 | (uint32_t)((unsigned long) | |
5e9d9b82 | 5155 | &phba->work_waitq)); |
a58cbd52 | 5156 | |
858c9f6c JS |
5157 | control &= |
5158 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
5159 | writel(control, phba->HCregaddr); |
5160 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 5161 | } |
a58cbd52 JS |
5162 | else { |
5163 | lpfc_debugfs_slow_ring_trc(phba, | |
5164 | "ISR slow ring: pwork:" | |
5165 | "x%x hawork:x%x wait:x%x", | |
5166 | phba->work_ha, work_ha_copy, | |
5167 | (uint32_t)((unsigned long) | |
5e9d9b82 | 5168 | &phba->work_waitq)); |
a58cbd52 | 5169 | } |
858c9f6c | 5170 | spin_unlock(&phba->hbalock); |
dea3101e JB |
5171 | } |
5172 | } | |
5173 | ||
5174 | if (work_ha_copy & HA_ERATT) { | |
dea3101e JB |
5175 | /* |
5176 | * There was a link/board error. Read the | |
5177 | * status register to retrieve the error event | |
5178 | * and process it. | |
5179 | */ | |
5180 | phba->sli.slistat.err_attn_event++; | |
5181 | /* Save status info */ | |
5182 | phba->work_hs = readl(phba->HSregaddr); | |
5183 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); | |
5184 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
5185 | ||
5186 | /* Clear Chip error bit */ | |
5187 | writel(HA_ERATT, phba->HAregaddr); | |
5188 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 5189 | phba->pport->stopped = 1; |
dea3101e JB |
5190 | } |
5191 | ||
97eab634 | 5192 | spin_lock(&phba->hbalock); |
92d7f7b0 JS |
5193 | if ((work_ha_copy & HA_MBATT) && |
5194 | (phba->sli.mbox_active)) { | |
5195 | pmb = phba->sli.mbox_active; | |
5196 | pmbox = &pmb->mb; | |
5197 | mbox = &phba->slim2p->mbx; | |
858c9f6c | 5198 | vport = pmb->vport; |
92d7f7b0 JS |
5199 | |
5200 | /* First check out the status word */ | |
5201 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
5202 | if (pmbox->mbxOwner != OWN_HOST) { | |
97eab634 | 5203 | spin_unlock(&phba->hbalock); |
92d7f7b0 JS |
5204 | /* |
5205 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
5206 | * mbxStatus <status> | |
5207 | */ | |
09372820 | 5208 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 5209 | LOG_SLI, |
e8b62011 | 5210 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
5211 | "Interrupt mbxCommand x%x " |
5212 | "mbxStatus x%x\n", | |
e8b62011 | 5213 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
5214 | pmbox->mbxCommand, |
5215 | pmbox->mbxStatus); | |
09372820 JS |
5216 | /* clear mailbox attention bit */ |
5217 | work_ha_copy &= ~HA_MBATT; | |
5218 | } else { | |
97eab634 JS |
5219 | phba->sli.mbox_active = NULL; |
5220 | spin_unlock(&phba->hbalock); | |
09372820 JS |
5221 | phba->last_completion_time = jiffies; |
5222 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
5223 | if (pmb->mbox_cmpl) { |
5224 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
5225 | MAILBOX_CMD_SIZE); | |
5226 | } | |
5227 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
5228 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
5229 | ||
5230 | lpfc_debugfs_disc_trc(vport, | |
5231 | LPFC_DISC_TRC_MBOX_VPORT, | |
5232 | "MBOX dflt rpi: : " | |
5233 | "status:x%x rpi:x%x", | |
5234 | (uint32_t)pmbox->mbxStatus, | |
5235 | pmbox->un.varWords[0], 0); | |
5236 | ||
5237 | if (!pmbox->mbxStatus) { | |
5238 | mp = (struct lpfc_dmabuf *) | |
5239 | (pmb->context1); | |
5240 | ndlp = (struct lpfc_nodelist *) | |
5241 | pmb->context2; | |
5242 | ||
5243 | /* Reg_LOGIN of dflt RPI was | |
5244 | * successful. new lets get | |
5245 | * rid of the RPI using the | |
5246 | * same mbox buffer. | |
5247 | */ | |
5248 | lpfc_unreg_login(phba, | |
5249 | vport->vpi, | |
5250 | pmbox->un.varWords[0], | |
5251 | pmb); | |
5252 | pmb->mbox_cmpl = | |
5253 | lpfc_mbx_cmpl_dflt_rpi; | |
5254 | pmb->context1 = mp; | |
5255 | pmb->context2 = ndlp; | |
5256 | pmb->vport = vport; | |
58da1ffb JS |
5257 | rc = lpfc_sli_issue_mbox(phba, |
5258 | pmb, | |
5259 | MBX_NOWAIT); | |
5260 | if (rc != MBX_BUSY) | |
5261 | lpfc_printf_log(phba, | |
5262 | KERN_ERR, | |
5263 | LOG_MBOX | LOG_SLI, | |
5264 | "0306 rc should have" | |
5265 | "been MBX_BUSY"); | |
09372820 JS |
5266 | goto send_current_mbox; |
5267 | } | |
858c9f6c | 5268 | } |
09372820 JS |
5269 | spin_lock(&phba->pport->work_port_lock); |
5270 | phba->pport->work_port_events &= | |
5271 | ~WORKER_MBOX_TMO; | |
5272 | spin_unlock(&phba->pport->work_port_lock); | |
5273 | lpfc_mbox_cmpl_put(phba, pmb); | |
858c9f6c | 5274 | } |
97eab634 JS |
5275 | } else |
5276 | spin_unlock(&phba->hbalock); | |
92d7f7b0 JS |
5277 | if ((work_ha_copy & HA_MBATT) && |
5278 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 5279 | send_current_mbox: |
92d7f7b0 | 5280 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
5281 | do { |
5282 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
5283 | MBX_NOWAIT); | |
5284 | } while (rc == MBX_NOT_FINISHED); | |
5285 | if (rc != MBX_SUCCESS) | |
5286 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
5287 | LOG_SLI, "0349 rc should be " | |
5288 | "MBX_SUCCESS"); | |
92d7f7b0 JS |
5289 | } |
5290 | ||
2e0fef85 | 5291 | spin_lock(&phba->hbalock); |
dea3101e | 5292 | phba->work_ha |= work_ha_copy; |
2e0fef85 | 5293 | spin_unlock(&phba->hbalock); |
5e9d9b82 | 5294 | lpfc_worker_wake_up(phba); |
dea3101e JB |
5295 | } |
5296 | ||
5297 | ha_copy &= ~(phba->work_ha_mask); | |
5298 | ||
5299 | /* | |
5300 | * Process all events on FCP ring. Take the optimized path for | |
5301 | * FCP IO. Any other IO is slow path and is handled by | |
5302 | * the worker thread. | |
5303 | */ | |
5304 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
5305 | status >>= (4*LPFC_FCP_RING); | |
858c9f6c | 5306 | if (status & HA_RXMASK) |
dea3101e JB |
5307 | lpfc_sli_handle_fast_ring_event(phba, |
5308 | &phba->sli.ring[LPFC_FCP_RING], | |
5309 | status); | |
a4bc3379 JS |
5310 | |
5311 | if (phba->cfg_multi_ring_support == 2) { | |
5312 | /* | |
5313 | * Process all events on extra ring. Take the optimized path | |
5314 | * for extra ring IO. Any other IO is slow path and is handled | |
5315 | * by the worker thread. | |
5316 | */ | |
5317 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
5318 | status >>= (4*LPFC_EXTRA_RING); | |
858c9f6c | 5319 | if (status & HA_RXMASK) { |
a4bc3379 JS |
5320 | lpfc_sli_handle_fast_ring_event(phba, |
5321 | &phba->sli.ring[LPFC_EXTRA_RING], | |
5322 | status); | |
5323 | } | |
5324 | } | |
dea3101e JB |
5325 | return IRQ_HANDLED; |
5326 | ||
5327 | } /* lpfc_intr_handler */ |