Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
d8e93df1 | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 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 | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | ||
f888ba3c JSEC |
26 | #include <scsi/scsi_device.h> |
27 | #include <scsi/scsi_transport_fc.h> | |
28 | ||
91886523 JSEC |
29 | #include <scsi/scsi.h> |
30 | ||
da0436e9 | 31 | #include "lpfc_hw4.h" |
dea3101e | 32 | #include "lpfc_hw.h" |
33 | #include "lpfc_sli.h" | |
da0436e9 | 34 | #include "lpfc_sli4.h" |
ea2151b4 | 35 | #include "lpfc_nl.h" |
dea3101e | 36 | #include "lpfc_disc.h" |
37 | #include "lpfc_scsi.h" | |
38 | #include "lpfc.h" | |
39 | #include "lpfc_logmsg.h" | |
40 | #include "lpfc_crtn.h" | |
41 | #include "lpfc_compat.h" | |
42 | ||
21e9a0a5 JS |
43 | /** |
44 | * lpfc_dump_static_vport - Dump HBA's static vport information. | |
45 | * @phba: pointer to lpfc hba data structure. | |
46 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
47 | * @offset: offset for dumping vport info. | |
48 | * | |
49 | * The dump mailbox command provides a method for the device driver to obtain | |
50 | * various types of information from the HBA device. | |
51 | * | |
52 | * This routine prepares the mailbox command for dumping list of static | |
53 | * vports to be created. | |
54 | **/ | |
1c6834a7 | 55 | int |
21e9a0a5 JS |
56 | lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
57 | uint16_t offset) | |
58 | { | |
59 | MAILBOX_t *mb; | |
1c6834a7 | 60 | struct lpfc_dmabuf *mp; |
21e9a0a5 JS |
61 | |
62 | mb = &pmb->u.mb; | |
21e9a0a5 JS |
63 | |
64 | /* Setup to dump vport info region */ | |
65 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
66 | mb->mbxCommand = MBX_DUMP_MEMORY; | |
21e9a0a5 JS |
67 | mb->un.varDmp.type = DMP_NV_PARAMS; |
68 | mb->un.varDmp.entry_index = offset; | |
69 | mb->un.varDmp.region_id = DMP_REGION_VPORT; | |
21e9a0a5 JS |
70 | mb->mbxOwner = OWN_HOST; |
71 | ||
1c6834a7 JS |
72 | /* For SLI3 HBAs data is embedded in mailbox */ |
73 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
74 | mb->un.varDmp.cv = 1; | |
75 | mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); | |
76 | return 0; | |
77 | } | |
78 | ||
79 | /* For SLI4 HBAs driver need to allocate memory */ | |
80 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
81 | if (mp) | |
82 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
83 | ||
84 | if (!mp || !mp->virt) { | |
85 | kfree(mp); | |
86 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
87 | "2605 lpfc_dump_static_vport: memory" | |
88 | " allocation failed\n"); | |
89 | return 1; | |
90 | } | |
91 | memset(mp->virt, 0, LPFC_BPL_SIZE); | |
92 | INIT_LIST_HEAD(&mp->list); | |
93 | /* save address for completion */ | |
94 | pmb->context2 = (uint8_t *) mp; | |
95 | mb->un.varWords[3] = putPaddrLow(mp->phys); | |
96 | mb->un.varWords[4] = putPaddrHigh(mp->phys); | |
97 | mb->un.varDmp.sli4_length = sizeof(struct static_vport_info); | |
98 | ||
99 | return 0; | |
21e9a0a5 JS |
100 | } |
101 | ||
e59058c4 | 102 | /** |
a0c87cbd | 103 | * lpfc_down_link - Bring down HBAs link. |
e59058c4 JS |
104 | * @phba: pointer to lpfc hba data structure. |
105 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
a0c87cbd JS |
106 | * |
107 | * This routine prepares a mailbox command to bring down HBA link. | |
108 | **/ | |
109 | void | |
110 | lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
111 | { | |
112 | MAILBOX_t *mb; | |
113 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
114 | mb = &pmb->u.mb; | |
115 | mb->mbxCommand = MBX_DOWN_LINK; | |
116 | mb->mbxOwner = OWN_HOST; | |
117 | } | |
118 | ||
119 | /** | |
120 | * lpfc_dump_mem - Prepare a mailbox command for reading a region. | |
121 | * @phba: pointer to lpfc hba data structure. | |
122 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
123 | * @offset: offset into the region. | |
124 | * @region_id: config region id. | |
e59058c4 JS |
125 | * |
126 | * The dump mailbox command provides a method for the device driver to obtain | |
127 | * various types of information from the HBA device. | |
128 | * | |
a0c87cbd | 129 | * This routine prepares the mailbox command for dumping HBA's config region. |
e59058c4 | 130 | **/ |
dea3101e | 131 | void |
a0c87cbd JS |
132 | lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, |
133 | uint16_t region_id) | |
dea3101e | 134 | { |
135 | MAILBOX_t *mb; | |
136 | void *ctx; | |
137 | ||
04c68496 | 138 | mb = &pmb->u.mb; |
dea3101e | 139 | ctx = pmb->context2; |
140 | ||
141 | /* Setup to dump VPD region */ | |
142 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); | |
143 | mb->mbxCommand = MBX_DUMP_MEMORY; | |
144 | mb->un.varDmp.cv = 1; | |
145 | mb->un.varDmp.type = DMP_NV_PARAMS; | |
146 | mb->un.varDmp.entry_index = offset; | |
a0c87cbd | 147 | mb->un.varDmp.region_id = region_id; |
dea3101e | 148 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
149 | mb->un.varDmp.co = 0; | |
150 | mb->un.varDmp.resp_offset = 0; | |
151 | pmb->context2 = ctx; | |
152 | mb->mbxOwner = OWN_HOST; | |
153 | return; | |
154 | } | |
155 | ||
97207482 | 156 | /** |
3621a710 | 157 | * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params |
97207482 JS |
158 | * @phba: pointer to lpfc hba data structure. |
159 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
3621a710 | 160 | * |
97207482 JS |
161 | * This function create a dump memory mailbox command to dump wake up |
162 | * parameters. | |
163 | */ | |
164 | void | |
165 | lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
166 | { | |
167 | MAILBOX_t *mb; | |
168 | void *ctx; | |
169 | ||
04c68496 | 170 | mb = &pmb->u.mb; |
97207482 JS |
171 | /* Save context so that we can restore after memset */ |
172 | ctx = pmb->context2; | |
173 | ||
174 | /* Setup to dump VPD region */ | |
175 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
176 | mb->mbxCommand = MBX_DUMP_MEMORY; | |
177 | mb->mbxOwner = OWN_HOST; | |
178 | mb->un.varDmp.cv = 1; | |
179 | mb->un.varDmp.type = DMP_NV_PARAMS; | |
180 | mb->un.varDmp.entry_index = 0; | |
181 | mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; | |
182 | mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; | |
183 | mb->un.varDmp.co = 0; | |
184 | mb->un.varDmp.resp_offset = 0; | |
185 | pmb->context2 = ctx; | |
186 | return; | |
187 | } | |
188 | ||
e59058c4 | 189 | /** |
3621a710 | 190 | * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param |
e59058c4 JS |
191 | * @phba: pointer to lpfc hba data structure. |
192 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
193 | * | |
194 | * The read NVRAM mailbox command returns the HBA's non-volatile parameters | |
195 | * that are used as defaults when the Fibre Channel link is brought on-line. | |
196 | * | |
197 | * This routine prepares the mailbox command for reading information stored | |
198 | * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. | |
199 | **/ | |
dea3101e | 200 | void |
201 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
202 | { | |
203 | MAILBOX_t *mb; | |
204 | ||
04c68496 | 205 | mb = &pmb->u.mb; |
dea3101e | 206 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
207 | mb->mbxCommand = MBX_READ_NV; | |
208 | mb->mbxOwner = OWN_HOST; | |
209 | return; | |
210 | } | |
211 | ||
e59058c4 | 212 | /** |
3621a710 | 213 | * lpfc_config_async - Prepare a mailbox command for enabling HBA async event |
e59058c4 JS |
214 | * @phba: pointer to lpfc hba data structure. |
215 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
216 | * @ring: ring number for the asynchronous event to be configured. | |
217 | * | |
218 | * The asynchronous event enable mailbox command is used to enable the | |
219 | * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and | |
220 | * specifies the default ring to which events are posted. | |
221 | * | |
222 | * This routine prepares the mailbox command for enabling HBA asynchronous | |
223 | * event support on a IOCB ring. | |
224 | **/ | |
57127f15 JS |
225 | void |
226 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, | |
227 | uint32_t ring) | |
228 | { | |
229 | MAILBOX_t *mb; | |
230 | ||
04c68496 | 231 | mb = &pmb->u.mb; |
57127f15 JS |
232 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
233 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; | |
234 | mb->un.varCfgAsyncEvent.ring = ring; | |
235 | mb->mbxOwner = OWN_HOST; | |
236 | return; | |
237 | } | |
238 | ||
e59058c4 | 239 | /** |
3621a710 | 240 | * lpfc_heart_beat - Prepare a mailbox command for heart beat |
e59058c4 JS |
241 | * @phba: pointer to lpfc hba data structure. |
242 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
243 | * | |
244 | * The heart beat mailbox command is used to detect an unresponsive HBA, which | |
245 | * is defined as any device where no error attention is sent and both mailbox | |
246 | * and rings are not processed. | |
247 | * | |
248 | * This routine prepares the mailbox command for issuing a heart beat in the | |
249 | * form of mailbox command to the HBA. The timely completion of the heart | |
250 | * beat mailbox command indicates the health of the HBA. | |
251 | **/ | |
858c9f6c JS |
252 | void |
253 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
254 | { | |
255 | MAILBOX_t *mb; | |
256 | ||
04c68496 | 257 | mb = &pmb->u.mb; |
858c9f6c JS |
258 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
259 | mb->mbxCommand = MBX_HEARTBEAT; | |
260 | mb->mbxOwner = OWN_HOST; | |
261 | return; | |
262 | } | |
263 | ||
e59058c4 | 264 | /** |
3621a710 | 265 | * lpfc_read_la - Prepare a mailbox command for reading HBA link attention |
e59058c4 JS |
266 | * @phba: pointer to lpfc hba data structure. |
267 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
268 | * @mp: DMA buffer memory for reading the link attention information into. | |
269 | * | |
270 | * The read link attention mailbox command is issued to read the Link Event | |
271 | * Attention information indicated by the HBA port when the Link Event bit | |
272 | * of the Host Attention (HSTATT) register is set to 1. A Link Event | |
273 | * Attention occurs based on an exception detected at the Fibre Channel link | |
274 | * interface. | |
275 | * | |
276 | * This routine prepares the mailbox command for reading HBA link attention | |
277 | * information. A DMA memory has been set aside and address passed to the | |
278 | * HBA through @mp for the HBA to DMA link attention information into the | |
279 | * memory as part of the execution of the mailbox command. | |
280 | * | |
281 | * Return codes | |
282 | * 0 - Success (currently always return 0) | |
283 | **/ | |
dea3101e | 284 | int |
285 | lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp) | |
286 | { | |
287 | MAILBOX_t *mb; | |
288 | struct lpfc_sli *psli; | |
289 | ||
290 | psli = &phba->sli; | |
04c68496 | 291 | mb = &pmb->u.mb; |
dea3101e | 292 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
293 | ||
294 | INIT_LIST_HEAD(&mp->list); | |
295 | mb->mbxCommand = MBX_READ_LA64; | |
296 | mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128; | |
297 | mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys); | |
298 | mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys); | |
299 | ||
300 | /* Save address for later completion and set the owner to host so that | |
301 | * the FW knows this mailbox is available for processing. | |
302 | */ | |
303 | pmb->context1 = (uint8_t *) mp; | |
304 | mb->mbxOwner = OWN_HOST; | |
92d7f7b0 | 305 | return (0); |
dea3101e | 306 | } |
307 | ||
e59058c4 | 308 | /** |
3621a710 | 309 | * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention |
e59058c4 JS |
310 | * @phba: pointer to lpfc hba data structure. |
311 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
312 | * | |
313 | * The clear link attention mailbox command is issued to clear the link event | |
314 | * attention condition indicated by the Link Event bit of the Host Attention | |
315 | * (HSTATT) register. The link event attention condition is cleared only if | |
316 | * the event tag specified matches that of the current link event counter. | |
317 | * The current event tag is read using the read link attention event mailbox | |
318 | * command. | |
319 | * | |
320 | * This routine prepares the mailbox command for clearing HBA link attention | |
321 | * information. | |
322 | **/ | |
dea3101e | 323 | void |
324 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
325 | { | |
326 | MAILBOX_t *mb; | |
327 | ||
04c68496 | 328 | mb = &pmb->u.mb; |
dea3101e | 329 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
330 | ||
331 | mb->un.varClearLA.eventTag = phba->fc_eventTag; | |
332 | mb->mbxCommand = MBX_CLEAR_LA; | |
333 | mb->mbxOwner = OWN_HOST; | |
334 | return; | |
335 | } | |
336 | ||
e59058c4 | 337 | /** |
3621a710 | 338 | * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA |
e59058c4 JS |
339 | * @phba: pointer to lpfc hba data structure. |
340 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
341 | * | |
342 | * The configure link mailbox command is used before the initialize link | |
343 | * mailbox command to override default value and to configure link-oriented | |
344 | * parameters such as DID address and various timers. Typically, this | |
345 | * command would be used after an F_Port login to set the returned DID address | |
346 | * and the fabric timeout values. This command is not valid before a configure | |
347 | * port command has configured the HBA port. | |
348 | * | |
349 | * This routine prepares the mailbox command for configuring link on a HBA. | |
350 | **/ | |
dea3101e | 351 | void |
352 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
353 | { | |
2e0fef85 | 354 | struct lpfc_vport *vport = phba->pport; |
04c68496 | 355 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 356 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
357 | ||
358 | /* NEW_FEATURE | |
359 | * SLI-2, Coalescing Response Feature. | |
360 | */ | |
361 | if (phba->cfg_cr_delay) { | |
362 | mb->un.varCfgLnk.cr = 1; | |
363 | mb->un.varCfgLnk.ci = 1; | |
364 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; | |
365 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; | |
366 | } | |
367 | ||
2e0fef85 | 368 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
dea3101e | 369 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
370 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; | |
371 | mb->un.varCfgLnk.ratov = phba->fc_ratov; | |
372 | mb->un.varCfgLnk.rttov = phba->fc_rttov; | |
373 | mb->un.varCfgLnk.altov = phba->fc_altov; | |
374 | mb->un.varCfgLnk.crtov = phba->fc_crtov; | |
375 | mb->un.varCfgLnk.citov = phba->fc_citov; | |
376 | ||
377 | if (phba->cfg_ack0) | |
378 | mb->un.varCfgLnk.ack0_enable = 1; | |
379 | ||
380 | mb->mbxCommand = MBX_CONFIG_LINK; | |
381 | mb->mbxOwner = OWN_HOST; | |
382 | return; | |
383 | } | |
384 | ||
9399627f | 385 | /** |
3621a710 | 386 | * lpfc_config_msi - Prepare a mailbox command for configuring msi-x |
9399627f JS |
387 | * @phba: pointer to lpfc hba data structure. |
388 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
389 | * | |
390 | * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 | |
391 | * MSI-X multi-message interrupt vector association to interrupt attention | |
392 | * conditions. | |
393 | * | |
394 | * Return codes | |
395 | * 0 - Success | |
396 | * -EINVAL - Failure | |
397 | **/ | |
398 | int | |
399 | lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |
400 | { | |
04c68496 | 401 | MAILBOX_t *mb = &pmb->u.mb; |
9399627f JS |
402 | uint32_t attentionConditions[2]; |
403 | ||
404 | /* Sanity check */ | |
405 | if (phba->cfg_use_msi != 2) { | |
406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
407 | "0475 Not configured for supporting MSI-X " | |
408 | "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); | |
409 | return -EINVAL; | |
410 | } | |
411 | ||
412 | if (phba->sli_rev < 3) { | |
413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
414 | "0476 HBA not supporting SLI-3 or later " | |
415 | "SLI Revision: 0x%x\n", phba->sli_rev); | |
416 | return -EINVAL; | |
417 | } | |
418 | ||
419 | /* Clear mailbox command fields */ | |
420 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
421 | ||
422 | /* | |
423 | * SLI-3, Message Signaled Interrupt Fearure. | |
424 | */ | |
425 | ||
426 | /* Multi-message attention configuration */ | |
427 | attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | | |
428 | HA_LATT | HA_MBATT); | |
429 | attentionConditions[1] = 0; | |
430 | ||
431 | mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; | |
432 | mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; | |
433 | ||
434 | /* | |
435 | * Set up message number to HA bit association | |
436 | */ | |
437 | #ifdef __BIG_ENDIAN_BITFIELD | |
438 | /* RA0 (FCP Ring) */ | |
439 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; | |
440 | /* RA1 (Other Protocol Extra Ring) */ | |
441 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; | |
442 | #else /* __LITTLE_ENDIAN_BITFIELD */ | |
443 | /* RA0 (FCP Ring) */ | |
444 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; | |
445 | /* RA1 (Other Protocol Extra Ring) */ | |
446 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; | |
447 | #endif | |
448 | /* Multi-message interrupt autoclear configuration*/ | |
449 | mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; | |
450 | mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; | |
451 | ||
452 | /* For now, HBA autoclear does not work reliably, disable it */ | |
453 | mb->un.varCfgMSI.autoClearHA[0] = 0; | |
454 | mb->un.varCfgMSI.autoClearHA[1] = 0; | |
455 | ||
456 | /* Set command and owner bit */ | |
457 | mb->mbxCommand = MBX_CONFIG_MSI; | |
458 | mb->mbxOwner = OWN_HOST; | |
459 | ||
460 | return 0; | |
461 | } | |
462 | ||
e59058c4 | 463 | /** |
3621a710 | 464 | * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA |
e59058c4 JS |
465 | * @phba: pointer to lpfc hba data structure. |
466 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
467 | * @topology: the link topology for the link to be initialized to. | |
468 | * @linkspeed: the link speed for the link to be initialized to. | |
469 | * | |
470 | * The initialize link mailbox command is used to initialize the Fibre | |
471 | * Channel link. This command must follow a configure port command that | |
472 | * establishes the mode of operation. | |
473 | * | |
474 | * This routine prepares the mailbox command for initializing link on a HBA | |
475 | * with the specified link topology and speed. | |
476 | **/ | |
dea3101e | 477 | void |
478 | lpfc_init_link(struct lpfc_hba * phba, | |
479 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) | |
480 | { | |
481 | lpfc_vpd_t *vpd; | |
482 | struct lpfc_sli *psli; | |
483 | MAILBOX_t *mb; | |
484 | ||
04c68496 | 485 | mb = &pmb->u.mb; |
dea3101e | 486 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
487 | ||
488 | psli = &phba->sli; | |
489 | switch (topology) { | |
490 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: | |
491 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; | |
492 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; | |
493 | break; | |
494 | case FLAGS_TOPOLOGY_MODE_PT_PT: | |
495 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; | |
496 | break; | |
497 | case FLAGS_TOPOLOGY_MODE_LOOP: | |
498 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; | |
499 | break; | |
500 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: | |
501 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; | |
502 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; | |
503 | break; | |
367c2713 JW |
504 | case FLAGS_LOCAL_LB: |
505 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; | |
506 | break; | |
dea3101e | 507 | } |
508 | ||
4b0b91d4 JS |
509 | /* Enable asynchronous ABTS responses from firmware */ |
510 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; | |
511 | ||
dea3101e | 512 | /* NEW_FEATURE |
513 | * Setting up the link speed | |
514 | */ | |
515 | vpd = &phba->vpd; | |
516 | if (vpd->rev.feaLevelHigh >= 0x02){ | |
92d7f7b0 | 517 | switch(linkspeed){ |
dea3101e | 518 | case LINK_SPEED_1G: |
519 | case LINK_SPEED_2G: | |
520 | case LINK_SPEED_4G: | |
b87eab38 | 521 | case LINK_SPEED_8G: |
dea3101e | 522 | mb->un.varInitLnk.link_flags |= |
523 | FLAGS_LINK_SPEED; | |
524 | mb->un.varInitLnk.link_speed = linkspeed; | |
525 | break; | |
526 | case LINK_SPEED_AUTO: | |
527 | default: | |
528 | mb->un.varInitLnk.link_speed = | |
529 | LINK_SPEED_AUTO; | |
530 | break; | |
531 | } | |
532 | ||
533 | } | |
534 | else | |
535 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; | |
536 | ||
537 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; | |
538 | mb->mbxOwner = OWN_HOST; | |
539 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; | |
540 | return; | |
541 | } | |
542 | ||
e59058c4 | 543 | /** |
3621a710 | 544 | * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters |
e59058c4 JS |
545 | * @phba: pointer to lpfc hba data structure. |
546 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
547 | * @vpi: virtual N_Port identifier. | |
548 | * | |
549 | * The read service parameter mailbox command is used to read the HBA port | |
550 | * service parameters. The service parameters are read into the buffer | |
551 | * specified directly by a BDE in the mailbox command. These service | |
552 | * parameters may then be used to build the payload of an N_Port/F_POrt | |
553 | * login request and reply (LOGI/ACC). | |
554 | * | |
555 | * This routine prepares the mailbox command for reading HBA port service | |
556 | * parameters. The DMA memory is allocated in this function and the addresses | |
557 | * are populated into the mailbox command for the HBA to DMA the service | |
558 | * parameters into. | |
559 | * | |
560 | * Return codes | |
561 | * 0 - Success | |
562 | * 1 - DMA memory allocation failed | |
563 | **/ | |
dea3101e | 564 | int |
92d7f7b0 | 565 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
dea3101e | 566 | { |
567 | struct lpfc_dmabuf *mp; | |
568 | MAILBOX_t *mb; | |
569 | struct lpfc_sli *psli; | |
570 | ||
571 | psli = &phba->sli; | |
04c68496 | 572 | mb = &pmb->u.mb; |
dea3101e | 573 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
574 | ||
575 | mb->mbxOwner = OWN_HOST; | |
576 | ||
577 | /* Get a buffer to hold the HBAs Service Parameters */ | |
578 | ||
98c9ea5c JS |
579 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
580 | if (mp) | |
581 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
582 | if (!mp || !mp->virt) { | |
c9475cb0 | 583 | kfree(mp); |
dea3101e | 584 | mb->mbxCommand = MBX_READ_SPARM64; |
585 | /* READ_SPARAM: no buffers */ | |
e8b62011 JS |
586 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
587 | "0301 READ_SPARAM: no buffers\n"); | |
92d7f7b0 | 588 | return (1); |
dea3101e | 589 | } |
590 | INIT_LIST_HEAD(&mp->list); | |
591 | mb->mbxCommand = MBX_READ_SPARM64; | |
592 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); | |
593 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); | |
594 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); | |
04c68496 | 595 | mb->un.varRdSparm.vpi = vpi + phba->vpi_base; |
dea3101e | 596 | |
597 | /* save address for completion */ | |
598 | pmb->context1 = mp; | |
599 | ||
92d7f7b0 | 600 | return (0); |
dea3101e | 601 | } |
602 | ||
e59058c4 | 603 | /** |
3621a710 | 604 | * lpfc_unreg_did - Prepare a mailbox command for unregistering DID |
e59058c4 JS |
605 | * @phba: pointer to lpfc hba data structure. |
606 | * @vpi: virtual N_Port identifier. | |
607 | * @did: remote port identifier. | |
608 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
609 | * | |
610 | * The unregister DID mailbox command is used to unregister an N_Port/F_Port | |
611 | * login for an unknown RPI by specifying the DID of a remote port. This | |
612 | * command frees an RPI context in the HBA port. This has the effect of | |
613 | * performing an implicit N_Port/F_Port logout. | |
614 | * | |
615 | * This routine prepares the mailbox command for unregistering a remote | |
616 | * N_Port/F_Port (DID) login. | |
617 | **/ | |
dea3101e | 618 | void |
92d7f7b0 JS |
619 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
620 | LPFC_MBOXQ_t * pmb) | |
dea3101e | 621 | { |
622 | MAILBOX_t *mb; | |
623 | ||
04c68496 | 624 | mb = &pmb->u.mb; |
dea3101e | 625 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
626 | ||
627 | mb->un.varUnregDID.did = did; | |
04c68496 JS |
628 | if (vpi != 0xffff) |
629 | vpi += phba->vpi_base; | |
92d7f7b0 | 630 | mb->un.varUnregDID.vpi = vpi; |
dea3101e | 631 | |
632 | mb->mbxCommand = MBX_UNREG_D_ID; | |
633 | mb->mbxOwner = OWN_HOST; | |
634 | return; | |
635 | } | |
636 | ||
e59058c4 | 637 | /** |
3621a710 | 638 | * lpfc_read_config - Prepare a mailbox command for reading HBA configuration |
e59058c4 JS |
639 | * @phba: pointer to lpfc hba data structure. |
640 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
641 | * | |
642 | * The read configuration mailbox command is used to read the HBA port | |
643 | * configuration parameters. This mailbox command provides a method for | |
644 | * seeing any parameters that may have changed via various configuration | |
645 | * mailbox commands. | |
646 | * | |
647 | * This routine prepares the mailbox command for reading out HBA configuration | |
648 | * parameters. | |
649 | **/ | |
dea3101e | 650 | void |
651 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
652 | { | |
653 | MAILBOX_t *mb; | |
654 | ||
04c68496 | 655 | mb = &pmb->u.mb; |
dea3101e | 656 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
657 | ||
658 | mb->mbxCommand = MBX_READ_CONFIG; | |
659 | mb->mbxOwner = OWN_HOST; | |
660 | return; | |
661 | } | |
662 | ||
e59058c4 | 663 | /** |
3621a710 | 664 | * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats |
e59058c4 JS |
665 | * @phba: pointer to lpfc hba data structure. |
666 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
667 | * | |
668 | * The read link status mailbox command is used to read the link status from | |
669 | * the HBA. Link status includes all link-related error counters. These | |
670 | * counters are maintained by the HBA and originated in the link hardware | |
671 | * unit. Note that all of these counters wrap. | |
672 | * | |
673 | * This routine prepares the mailbox command for reading out HBA link status. | |
674 | **/ | |
7bb3b137 JW |
675 | void |
676 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
677 | { | |
678 | MAILBOX_t *mb; | |
679 | ||
04c68496 | 680 | mb = &pmb->u.mb; |
7bb3b137 JW |
681 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
682 | ||
683 | mb->mbxCommand = MBX_READ_LNK_STAT; | |
684 | mb->mbxOwner = OWN_HOST; | |
685 | return; | |
686 | } | |
687 | ||
e59058c4 | 688 | /** |
04c68496 | 689 | * lpfc_reg_rpi - Prepare a mailbox command for registering remote login |
e59058c4 JS |
690 | * @phba: pointer to lpfc hba data structure. |
691 | * @vpi: virtual N_Port identifier. | |
692 | * @did: remote port identifier. | |
693 | * @param: pointer to memory holding the server parameters. | |
694 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
695 | * @flag: action flag to be passed back for the complete function. | |
696 | * | |
697 | * The registration login mailbox command is used to register an N_Port or | |
698 | * F_Port login. This registration allows the HBA to cache the remote N_Port | |
699 | * service parameters internally and thereby make the appropriate FC-2 | |
700 | * decisions. The remote port service parameters are handed off by the driver | |
701 | * to the HBA using a descriptor entry that directly identifies a buffer in | |
702 | * host memory. In exchange, the HBA returns an RPI identifier. | |
703 | * | |
704 | * This routine prepares the mailbox command for registering remote port login. | |
705 | * The function allocates DMA buffer for passing the service parameters to the | |
706 | * HBA with the mailbox command. | |
707 | * | |
708 | * Return codes | |
709 | * 0 - Success | |
710 | * 1 - DMA memory allocation failed | |
711 | **/ | |
dea3101e | 712 | int |
04c68496 | 713 | lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
92d7f7b0 | 714 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) |
dea3101e | 715 | { |
04c68496 | 716 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 717 | uint8_t *sparam; |
718 | struct lpfc_dmabuf *mp; | |
dea3101e | 719 | |
dea3101e | 720 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
721 | ||
722 | mb->un.varRegLogin.rpi = 0; | |
04c68496 JS |
723 | if (phba->sli_rev == LPFC_SLI_REV4) { |
724 | mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba); | |
725 | if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR) | |
726 | return 1; | |
727 | } | |
728 | ||
729 | mb->un.varRegLogin.vpi = vpi + phba->vpi_base; | |
dea3101e | 730 | mb->un.varRegLogin.did = did; |
731 | mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */ | |
732 | ||
733 | mb->mbxOwner = OWN_HOST; | |
734 | ||
735 | /* Get a buffer to hold NPorts Service Parameters */ | |
98c9ea5c JS |
736 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
737 | if (mp) | |
738 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
739 | if (!mp || !mp->virt) { | |
c9475cb0 | 740 | kfree(mp); |
dea3101e | 741 | mb->mbxCommand = MBX_REG_LOGIN64; |
742 | /* REG_LOGIN: no buffers */ | |
92d7f7b0 | 743 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
e8b62011 JS |
744 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
745 | "flag x%x\n", vpi, did, flag); | |
92d7f7b0 | 746 | return (1); |
dea3101e | 747 | } |
748 | INIT_LIST_HEAD(&mp->list); | |
749 | sparam = mp->virt; | |
750 | ||
751 | /* Copy param's into a new buffer */ | |
752 | memcpy(sparam, param, sizeof (struct serv_parm)); | |
753 | ||
754 | /* save address for completion */ | |
755 | pmb->context1 = (uint8_t *) mp; | |
756 | ||
757 | mb->mbxCommand = MBX_REG_LOGIN64; | |
758 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); | |
759 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); | |
760 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); | |
761 | ||
92d7f7b0 | 762 | return (0); |
dea3101e | 763 | } |
764 | ||
e59058c4 | 765 | /** |
3621a710 | 766 | * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login |
e59058c4 JS |
767 | * @phba: pointer to lpfc hba data structure. |
768 | * @vpi: virtual N_Port identifier. | |
769 | * @rpi: remote port identifier | |
770 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
771 | * | |
772 | * The unregistration login mailbox command is used to unregister an N_Port | |
773 | * or F_Port login. This command frees an RPI context in the HBA. It has the | |
774 | * effect of performing an implicit N_Port/F_Port logout. | |
775 | * | |
776 | * This routine prepares the mailbox command for unregistering remote port | |
777 | * login. | |
778 | **/ | |
dea3101e | 779 | void |
92d7f7b0 JS |
780 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
781 | LPFC_MBOXQ_t * pmb) | |
dea3101e | 782 | { |
783 | MAILBOX_t *mb; | |
784 | ||
04c68496 | 785 | mb = &pmb->u.mb; |
dea3101e | 786 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
787 | ||
788 | mb->un.varUnregLogin.rpi = (uint16_t) rpi; | |
789 | mb->un.varUnregLogin.rsvd1 = 0; | |
04c68496 | 790 | mb->un.varUnregLogin.vpi = vpi + phba->vpi_base; |
dea3101e | 791 | |
792 | mb->mbxCommand = MBX_UNREG_LOGIN; | |
793 | mb->mbxOwner = OWN_HOST; | |
04c68496 | 794 | |
dea3101e | 795 | return; |
796 | } | |
797 | ||
e59058c4 | 798 | /** |
3621a710 | 799 | * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier |
e59058c4 JS |
800 | * @phba: pointer to lpfc hba data structure. |
801 | * @vpi: virtual N_Port identifier. | |
802 | * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). | |
803 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
804 | * | |
805 | * The registration vport identifier mailbox command is used to activate a | |
806 | * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the | |
807 | * N_Port_ID against the information in the selected virtual N_Port context | |
808 | * block and marks it active to allow normal processing of IOCB commands and | |
809 | * received unsolicited exchanges. | |
810 | * | |
811 | * This routine prepares the mailbox command for registering a virtual N_Port. | |
812 | **/ | |
92d7f7b0 | 813 | void |
04c68496 | 814 | lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) |
92d7f7b0 | 815 | { |
04c68496 | 816 | MAILBOX_t *mb = &pmb->u.mb; |
92d7f7b0 JS |
817 | |
818 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); | |
819 | ||
04c68496 JS |
820 | mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base; |
821 | mb->un.varRegVpi.sid = vport->fc_myDID; | |
822 | mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; | |
92d7f7b0 JS |
823 | |
824 | mb->mbxCommand = MBX_REG_VPI; | |
825 | mb->mbxOwner = OWN_HOST; | |
826 | return; | |
827 | ||
828 | } | |
829 | ||
e59058c4 | 830 | /** |
3621a710 | 831 | * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id |
e59058c4 JS |
832 | * @phba: pointer to lpfc hba data structure. |
833 | * @vpi: virtual N_Port identifier. | |
834 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
835 | * | |
836 | * The unregistration vport identifier mailbox command is used to inactivate | |
837 | * a virtual N_Port. The driver must have logged out and unregistered all | |
838 | * remote N_Ports to abort any activity on the virtual N_Port. The HBA will | |
839 | * unregisters any default RPIs associated with the specified vpi, aborting | |
840 | * any active exchanges. The HBA will post the mailbox response after making | |
841 | * the virtual N_Port inactive. | |
842 | * | |
843 | * This routine prepares the mailbox command for unregistering a virtual | |
844 | * N_Port. | |
845 | **/ | |
92d7f7b0 JS |
846 | void |
847 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) | |
848 | { | |
04c68496 | 849 | MAILBOX_t *mb = &pmb->u.mb; |
92d7f7b0 JS |
850 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
851 | ||
04c68496 | 852 | mb->un.varUnregVpi.vpi = vpi + phba->vpi_base; |
92d7f7b0 JS |
853 | |
854 | mb->mbxCommand = MBX_UNREG_VPI; | |
855 | mb->mbxOwner = OWN_HOST; | |
856 | return; | |
857 | ||
858 | } | |
859 | ||
e59058c4 | 860 | /** |
3621a710 | 861 | * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) |
e59058c4 JS |
862 | * @phba: pointer to lpfc hba data structure. |
863 | * | |
864 | * This routine sets up and initializes the IOCB rings in the Port Control | |
865 | * Block (PCB). | |
866 | **/ | |
dea3101e | 867 | static void |
868 | lpfc_config_pcb_setup(struct lpfc_hba * phba) | |
869 | { | |
870 | struct lpfc_sli *psli = &phba->sli; | |
871 | struct lpfc_sli_ring *pring; | |
34b02dcd | 872 | PCB_t *pcbp = phba->pcb; |
dea3101e | 873 | dma_addr_t pdma_addr; |
874 | uint32_t offset; | |
2e0fef85 | 875 | uint32_t iocbCnt = 0; |
dea3101e | 876 | int i; |
877 | ||
dea3101e | 878 | pcbp->maxRing = (psli->num_rings - 1); |
879 | ||
dea3101e | 880 | for (i = 0; i < psli->num_rings; i++) { |
881 | pring = &psli->ring[i]; | |
2e0fef85 | 882 | |
ed957684 | 883 | pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE: |
92d7f7b0 | 884 | SLI2_IOCB_CMD_SIZE; |
ed957684 | 885 | pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE: |
92d7f7b0 | 886 | SLI2_IOCB_RSP_SIZE; |
dea3101e | 887 | /* A ring MUST have both cmd and rsp entries defined to be |
888 | valid */ | |
889 | if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) { | |
890 | pcbp->rdsc[i].cmdEntries = 0; | |
891 | pcbp->rdsc[i].rspEntries = 0; | |
892 | pcbp->rdsc[i].cmdAddrHigh = 0; | |
893 | pcbp->rdsc[i].rspAddrHigh = 0; | |
894 | pcbp->rdsc[i].cmdAddrLow = 0; | |
895 | pcbp->rdsc[i].rspAddrLow = 0; | |
896 | pring->cmdringaddr = NULL; | |
897 | pring->rspringaddr = NULL; | |
898 | continue; | |
899 | } | |
900 | /* Command ring setup for ring */ | |
34b02dcd | 901 | pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; |
dea3101e | 902 | pcbp->rdsc[i].cmdEntries = pring->numCiocb; |
903 | ||
34b02dcd JS |
904 | offset = (uint8_t *) &phba->IOCBs[iocbCnt] - |
905 | (uint8_t *) phba->slim2p.virt; | |
906 | pdma_addr = phba->slim2p.phys + offset; | |
dea3101e | 907 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
908 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); | |
909 | iocbCnt += pring->numCiocb; | |
910 | ||
911 | /* Response ring setup for ring */ | |
34b02dcd | 912 | pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt]; |
dea3101e | 913 | |
914 | pcbp->rdsc[i].rspEntries = pring->numRiocb; | |
34b02dcd JS |
915 | offset = (uint8_t *)&phba->IOCBs[iocbCnt] - |
916 | (uint8_t *)phba->slim2p.virt; | |
917 | pdma_addr = phba->slim2p.phys + offset; | |
dea3101e | 918 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
919 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); | |
920 | iocbCnt += pring->numRiocb; | |
921 | } | |
922 | } | |
923 | ||
e59058c4 | 924 | /** |
3621a710 | 925 | * lpfc_read_rev - Prepare a mailbox command for reading HBA revision |
e59058c4 JS |
926 | * @phba: pointer to lpfc hba data structure. |
927 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
928 | * | |
929 | * The read revision mailbox command is used to read the revision levels of | |
930 | * the HBA components. These components include hardware units, resident | |
931 | * firmware, and available firmware. HBAs that supports SLI-3 mode of | |
932 | * operation provide different response information depending on the version | |
933 | * requested by the driver. | |
934 | * | |
935 | * This routine prepares the mailbox command for reading HBA revision | |
936 | * information. | |
937 | **/ | |
dea3101e | 938 | void |
939 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
940 | { | |
04c68496 | 941 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 942 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
943 | mb->un.varRdRev.cv = 1; | |
ed957684 | 944 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
dea3101e | 945 | mb->mbxCommand = MBX_READ_REV; |
946 | mb->mbxOwner = OWN_HOST; | |
947 | return; | |
948 | } | |
949 | ||
e59058c4 | 950 | /** |
3621a710 | 951 | * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 |
e59058c4 JS |
952 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
953 | * @hbq_desc: pointer to the HBQ selection profile descriptor. | |
954 | * | |
955 | * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA | |
956 | * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs | |
957 | * the Sequence Length Test using the fields in the Selection Profile 2 | |
958 | * extension in words 20:31. | |
959 | **/ | |
ed957684 JS |
960 | static void |
961 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, | |
962 | struct lpfc_hbq_init *hbq_desc) | |
963 | { | |
964 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; | |
965 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; | |
966 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; | |
967 | } | |
968 | ||
e59058c4 | 969 | /** |
3621a710 | 970 | * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 |
e59058c4 JS |
971 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
972 | * @hbq_desc: pointer to the HBQ selection profile descriptor. | |
973 | * | |
974 | * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA | |
975 | * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs | |
976 | * the Sequence Length Test and Byte Field Test using the fields in the | |
977 | * Selection Profile 3 extension in words 20:31. | |
978 | **/ | |
ed957684 JS |
979 | static void |
980 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, | |
981 | struct lpfc_hbq_init *hbq_desc) | |
982 | { | |
983 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; | |
984 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; | |
985 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; | |
986 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; | |
987 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, | |
988 | sizeof(hbqmb->profiles.profile3.cmdmatch)); | |
989 | } | |
990 | ||
e59058c4 | 991 | /** |
3621a710 | 992 | * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 |
e59058c4 JS |
993 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
994 | * @hbq_desc: pointer to the HBQ selection profile descriptor. | |
995 | * | |
996 | * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The | |
997 | * HBA tests the initial frame of an incoming sequence using the frame's | |
998 | * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test | |
999 | * and Byte Field Test using the fields in the Selection Profile 5 extension | |
1000 | * words 20:31. | |
1001 | **/ | |
ed957684 JS |
1002 | static void |
1003 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, | |
1004 | struct lpfc_hbq_init *hbq_desc) | |
1005 | { | |
1006 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; | |
1007 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; | |
1008 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; | |
1009 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; | |
1010 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, | |
1011 | sizeof(hbqmb->profiles.profile5.cmdmatch)); | |
1012 | } | |
1013 | ||
e59058c4 | 1014 | /** |
3621a710 | 1015 | * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ |
e59058c4 JS |
1016 | * @phba: pointer to lpfc hba data structure. |
1017 | * @id: HBQ identifier. | |
1018 | * @hbq_desc: pointer to the HBA descriptor data structure. | |
1019 | * @hbq_entry_index: index of the HBQ entry data structures. | |
1020 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
1021 | * | |
1022 | * The configure HBQ (Host Buffer Queue) mailbox command is used to configure | |
1023 | * an HBQ. The configuration binds events that require buffers to a particular | |
1024 | * ring and HBQ based on a selection profile. | |
1025 | * | |
1026 | * This routine prepares the mailbox command for configuring an HBQ. | |
1027 | **/ | |
ed957684 | 1028 | void |
51ef4c26 JS |
1029 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
1030 | struct lpfc_hbq_init *hbq_desc, | |
ed957684 JS |
1031 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
1032 | { | |
1033 | int i; | |
04c68496 | 1034 | MAILBOX_t *mb = &pmb->u.mb; |
ed957684 JS |
1035 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
1036 | ||
1037 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); | |
51ef4c26 | 1038 | hbqmb->hbqId = id; |
ed957684 JS |
1039 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
1040 | hbqmb->recvNotify = hbq_desc->rn; /* Receive | |
1041 | * Notification */ | |
1042 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks | |
1043 | * # in words 0-19 */ | |
92d7f7b0 | 1044 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
ed957684 JS |
1045 | * 0 = all, |
1046 | * 7 = logentry */ | |
1047 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring | |
1048 | * e.g. Ring0=b0001, | |
1049 | * ring2=b0100 */ | |
1050 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 | |
1051 | * or 5 */ | |
1052 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this | |
1053 | * HBQ will be used | |
1054 | * for LogEntry | |
1055 | * buffers */ | |
1056 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + | |
1057 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); | |
1058 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); | |
1059 | ||
1060 | mb->mbxCommand = MBX_CONFIG_HBQ; | |
1061 | mb->mbxOwner = OWN_HOST; | |
1062 | ||
92d7f7b0 JS |
1063 | /* Copy info for profiles 2,3,5. Other |
1064 | * profiles this area is reserved | |
1065 | */ | |
ed957684 JS |
1066 | if (hbq_desc->profile == 2) |
1067 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); | |
1068 | else if (hbq_desc->profile == 3) | |
1069 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); | |
1070 | else if (hbq_desc->profile == 5) | |
1071 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); | |
1072 | ||
1073 | /* Return if no rctl / type masks for this HBQ */ | |
1074 | if (!hbq_desc->mask_count) | |
1075 | return; | |
1076 | ||
1077 | /* Otherwise we setup specific rctl / type masks for this HBQ */ | |
1078 | for (i = 0; i < hbq_desc->mask_count; i++) { | |
1079 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; | |
1080 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; | |
1081 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; | |
1082 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; | |
1083 | } | |
1084 | ||
1085 | return; | |
1086 | } | |
1087 | ||
e59058c4 | 1088 | /** |
3621a710 | 1089 | * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring |
e59058c4 JS |
1090 | * @phba: pointer to lpfc hba data structure. |
1091 | * @ring: | |
1092 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
1093 | * | |
1094 | * The configure ring mailbox command is used to configure an IOCB ring. This | |
1095 | * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the | |
1096 | * ring. This is used to map incoming sequences to a particular ring whose | |
1097 | * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not | |
1098 | * attempt to configure a ring whose number is greater than the number | |
1099 | * specified in the Port Control Block (PCB). It is an error to issue the | |
1100 | * configure ring command more than once with the same ring number. The HBA | |
1101 | * returns an error if the driver attempts this. | |
1102 | * | |
1103 | * This routine prepares the mailbox command for configuring IOCB ring. | |
1104 | **/ | |
dea3101e | 1105 | void |
1106 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) | |
1107 | { | |
1108 | int i; | |
04c68496 | 1109 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 1110 | struct lpfc_sli *psli; |
1111 | struct lpfc_sli_ring *pring; | |
1112 | ||
1113 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); | |
1114 | ||
1115 | mb->un.varCfgRing.ring = ring; | |
1116 | mb->un.varCfgRing.maxOrigXchg = 0; | |
1117 | mb->un.varCfgRing.maxRespXchg = 0; | |
1118 | mb->un.varCfgRing.recvNotify = 1; | |
1119 | ||
1120 | psli = &phba->sli; | |
1121 | pring = &psli->ring[ring]; | |
1122 | mb->un.varCfgRing.numMask = pring->num_mask; | |
1123 | mb->mbxCommand = MBX_CONFIG_RING; | |
1124 | mb->mbxOwner = OWN_HOST; | |
1125 | ||
1126 | /* Is this ring configured for a specific profile */ | |
1127 | if (pring->prt[0].profile) { | |
1128 | mb->un.varCfgRing.profile = pring->prt[0].profile; | |
1129 | return; | |
1130 | } | |
1131 | ||
1132 | /* Otherwise we setup specific rctl / type masks for this ring */ | |
1133 | for (i = 0; i < pring->num_mask; i++) { | |
1134 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; | |
1135 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ) | |
1136 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; | |
1137 | else | |
1138 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; | |
1139 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; | |
1140 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; | |
1141 | } | |
1142 | ||
1143 | return; | |
1144 | } | |
1145 | ||
e59058c4 | 1146 | /** |
3621a710 | 1147 | * lpfc_config_port - Prepare a mailbox command for configuring port |
e59058c4 JS |
1148 | * @phba: pointer to lpfc hba data structure. |
1149 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
1150 | * | |
1151 | * The configure port mailbox command is used to identify the Port Control | |
1152 | * Block (PCB) in the driver memory. After this command is issued, the | |
1153 | * driver must not access the mailbox in the HBA without first resetting | |
1154 | * the HBA. The HBA may copy the PCB information to internal storage for | |
1155 | * subsequent use; the driver can not change the PCB information unless it | |
1156 | * resets the HBA. | |
1157 | * | |
1158 | * This routine prepares the mailbox command for configuring port. | |
1159 | **/ | |
dea3101e | 1160 | void |
92d7f7b0 | 1161 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 1162 | { |
ed957684 | 1163 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
04c68496 | 1164 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 1165 | dma_addr_t pdma_addr; |
1166 | uint32_t bar_low, bar_high; | |
1167 | size_t offset; | |
4cc2da1d | 1168 | struct lpfc_hgp hgp; |
f91b392c | 1169 | int i; |
ed957684 | 1170 | uint32_t pgp_offset; |
dea3101e | 1171 | |
1172 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
1173 | mb->mbxCommand = MBX_CONFIG_PORT; | |
1174 | mb->mbxOwner = OWN_HOST; | |
1175 | ||
1176 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); | |
1177 | ||
34b02dcd JS |
1178 | offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; |
1179 | pdma_addr = phba->slim2p.phys + offset; | |
dea3101e | 1180 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
1181 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); | |
1182 | ||
97207482 JS |
1183 | /* Always Host Group Pointer is in SLIM */ |
1184 | mb->un.varCfgPort.hps = 1; | |
1185 | ||
ed957684 JS |
1186 | /* If HBA supports SLI=3 ask for it */ |
1187 | ||
04c68496 | 1188 | if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { |
e2a0a9d6 JS |
1189 | if (phba->cfg_enable_bg) |
1190 | mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ | |
04c68496 | 1191 | mb->un.varCfgPort.cdss = 1; /* Configure Security */ |
ed957684 | 1192 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
34b02dcd JS |
1193 | mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ |
1194 | mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */ | |
51ef4c26 | 1195 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
78b2d852 | 1196 | if (phba->max_vpi && phba->cfg_enable_npiv && |
92d7f7b0 | 1197 | phba->vpd.sli3Feat.cmv) { |
04c68496 | 1198 | mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; |
92d7f7b0 | 1199 | mb->un.varCfgPort.cmv = 1; |
92d7f7b0 JS |
1200 | } else |
1201 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; | |
1202 | } else | |
04c68496 | 1203 | phba->sli_rev = LPFC_SLI_REV2; |
92d7f7b0 | 1204 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
ed957684 | 1205 | |
dea3101e | 1206 | /* Now setup pcb */ |
34b02dcd JS |
1207 | phba->pcb->type = TYPE_NATIVE_SLI2; |
1208 | phba->pcb->feature = FEATURE_INITIAL_SLI2; | |
dea3101e | 1209 | |
1210 | /* Setup Mailbox pointers */ | |
34b02dcd JS |
1211 | phba->pcb->mailBoxSize = sizeof(MAILBOX_t); |
1212 | offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; | |
1213 | pdma_addr = phba->slim2p.phys + offset; | |
1214 | phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); | |
1215 | phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); | |
dea3101e | 1216 | |
1217 | /* | |
1218 | * Setup Host Group ring pointer. | |
1219 | * | |
1220 | * For efficiency reasons, the ring get/put pointers can be | |
1221 | * placed in adapter memory (SLIM) rather than in host memory. | |
1222 | * This allows firmware to avoid PCI reads/writes when updating | |
1223 | * and checking pointers. | |
1224 | * | |
1225 | * The firmware recognizes the use of SLIM memory by comparing | |
1226 | * the address of the get/put pointers structure with that of | |
1227 | * the SLIM BAR (BAR0). | |
1228 | * | |
1229 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 | |
1230 | * (the hardware's view of the base address), not the OS's | |
1231 | * value of pci_resource_start() as the OS value may be a cookie | |
1232 | * for ioremap/iomap. | |
1233 | */ | |
1234 | ||
1235 | ||
1236 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); | |
1237 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); | |
1238 | ||
ed957684 JS |
1239 | /* |
1240 | * Set up HGP - Port Memory | |
1241 | * | |
1242 | * The port expects the host get/put pointers to reside in memory | |
1243 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) | |
1244 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved | |
1245 | * words (0x40 bytes). This area is not reserved if HBQs are | |
1246 | * configured in SLI-3. | |
1247 | * | |
1248 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 | |
1249 | * RR0Get 0xc4 0x84 | |
1250 | * CR1Put 0xc8 0x88 | |
1251 | * RR1Get 0xcc 0x8c | |
1252 | * CR2Put 0xd0 0x90 | |
1253 | * RR2Get 0xd4 0x94 | |
1254 | * CR3Put 0xd8 0x98 | |
1255 | * RR3Get 0xdc 0x9c | |
1256 | * | |
1257 | * Reserved 0xa0-0xbf | |
1258 | * If HBQs configured: | |
1259 | * HBQ 0 Put ptr 0xc0 | |
1260 | * HBQ 1 Put ptr 0xc4 | |
1261 | * HBQ 2 Put ptr 0xc8 | |
1262 | * ...... | |
1263 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 | |
1264 | * | |
1265 | */ | |
1266 | ||
1267 | if (phba->sli_rev == 3) { | |
1268 | phba->host_gp = &mb_slim->us.s3.host[0]; | |
1269 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; | |
1270 | } else { | |
1271 | phba->host_gp = &mb_slim->us.s2.host[0]; | |
1272 | phba->hbq_put = NULL; | |
1273 | } | |
dea3101e | 1274 | |
1275 | /* mask off BAR0's flag bits 0 - 3 */ | |
34b02dcd JS |
1276 | phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
1277 | (void __iomem *)phba->host_gp - | |
ed957684 | 1278 | (void __iomem *)phba->MBslimaddr; |
dea3101e | 1279 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
34b02dcd | 1280 | phba->pcb->hgpAddrHigh = bar_high; |
dea3101e | 1281 | else |
34b02dcd | 1282 | phba->pcb->hgpAddrHigh = 0; |
dea3101e | 1283 | /* write HGP data to SLIM at the required longword offset */ |
4cc2da1d | 1284 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
f91b392c JSEC |
1285 | |
1286 | for (i=0; i < phba->sli.num_rings; i++) { | |
ed957684 JS |
1287 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
1288 | sizeof(*phba->host_gp)); | |
f91b392c | 1289 | } |
dea3101e | 1290 | |
8f34f4ce JS |
1291 | /* Setup Port Group offset */ |
1292 | if (phba->sli_rev == 3) | |
34b02dcd JS |
1293 | pgp_offset = offsetof(struct lpfc_sli2_slim, |
1294 | mbx.us.s3_pgp.port); | |
8f34f4ce | 1295 | else |
34b02dcd JS |
1296 | pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); |
1297 | pdma_addr = phba->slim2p.phys + pgp_offset; | |
1298 | phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); | |
1299 | phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); | |
dea3101e | 1300 | |
1301 | /* Use callback routine to setp rings in the pcb */ | |
1302 | lpfc_config_pcb_setup(phba); | |
1303 | ||
1304 | /* special handling for LC HBAs */ | |
1305 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
1306 | uint32_t hbainit[5]; | |
1307 | ||
1308 | lpfc_hba_init(phba, hbainit); | |
1309 | ||
1310 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); | |
1311 | } | |
1312 | ||
1313 | /* Swap PCB if needed */ | |
34b02dcd | 1314 | lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); |
dea3101e | 1315 | } |
1316 | ||
e59058c4 | 1317 | /** |
3621a710 | 1318 | * lpfc_kill_board - Prepare a mailbox command for killing board |
e59058c4 JS |
1319 | * @phba: pointer to lpfc hba data structure. |
1320 | * @pmb: pointer to the driver internal queue element for mailbox command. | |
1321 | * | |
1322 | * The kill board mailbox command is used to tell firmware to perform a | |
1323 | * graceful shutdown of a channel on a specified board to prepare for reset. | |
1324 | * When the kill board mailbox command is received, the ER3 bit is set to 1 | |
1325 | * in the Host Status register and the ER Attention bit is set to 1 in the | |
1326 | * Host Attention register of the HBA function that received the kill board | |
1327 | * command. | |
1328 | * | |
1329 | * This routine prepares the mailbox command for killing the board in | |
1330 | * preparation for a graceful shutdown. | |
1331 | **/ | |
41415862 JW |
1332 | void |
1333 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) | |
1334 | { | |
04c68496 | 1335 | MAILBOX_t *mb = &pmb->u.mb; |
41415862 JW |
1336 | |
1337 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); | |
1338 | mb->mbxCommand = MBX_KILL_BOARD; | |
1339 | mb->mbxOwner = OWN_HOST; | |
1340 | return; | |
1341 | } | |
1342 | ||
e59058c4 | 1343 | /** |
3621a710 | 1344 | * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue |
e59058c4 JS |
1345 | * @phba: pointer to lpfc hba data structure. |
1346 | * @mbq: pointer to the driver internal queue element for mailbox command. | |
1347 | * | |
1348 | * Driver maintains a internal mailbox command queue implemented as a linked | |
1349 | * list. When a mailbox command is issued, it shall be put into the mailbox | |
1350 | * command queue such that they shall be processed orderly as HBA can process | |
1351 | * one mailbox command at a time. | |
1352 | **/ | |
dea3101e | 1353 | void |
1354 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) | |
1355 | { | |
1356 | struct lpfc_sli *psli; | |
1357 | ||
1358 | psli = &phba->sli; | |
1359 | ||
1360 | list_add_tail(&mbq->list, &psli->mboxq); | |
1361 | ||
1362 | psli->mboxq_cnt++; | |
1363 | ||
1364 | return; | |
1365 | } | |
1366 | ||
e59058c4 | 1367 | /** |
3621a710 | 1368 | * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue |
e59058c4 JS |
1369 | * @phba: pointer to lpfc hba data structure. |
1370 | * | |
1371 | * Driver maintains a internal mailbox command queue implemented as a linked | |
1372 | * list. When a mailbox command is issued, it shall be put into the mailbox | |
1373 | * command queue such that they shall be processed orderly as HBA can process | |
1374 | * one mailbox command at a time. After HBA finished processing a mailbox | |
1375 | * command, the driver will remove a pending mailbox command from the head of | |
1376 | * the mailbox command queue and send to the HBA for processing. | |
1377 | * | |
1378 | * Return codes | |
1379 | * pointer to the driver internal queue element for mailbox command. | |
1380 | **/ | |
dea3101e | 1381 | LPFC_MBOXQ_t * |
1382 | lpfc_mbox_get(struct lpfc_hba * phba) | |
1383 | { | |
1384 | LPFC_MBOXQ_t *mbq = NULL; | |
1385 | struct lpfc_sli *psli = &phba->sli; | |
1386 | ||
2e0fef85 | 1387 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
92d7f7b0 | 1388 | if (mbq) |
dea3101e | 1389 | psli->mboxq_cnt--; |
dea3101e | 1390 | |
1391 | return mbq; | |
1392 | } | |
a309a6b6 | 1393 | |
04c68496 JS |
1394 | /** |
1395 | * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list | |
1396 | * @phba: pointer to lpfc hba data structure. | |
1397 | * @mbq: pointer to the driver internal queue element for mailbox command. | |
1398 | * | |
1399 | * This routine put the completed mailbox command into the mailbox command | |
1400 | * complete list. This is the unlocked version of the routine. The mailbox | |
1401 | * complete list is used by the driver worker thread to process mailbox | |
1402 | * complete callback functions outside the driver interrupt handler. | |
1403 | **/ | |
1404 | void | |
1405 | __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) | |
1406 | { | |
1407 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); | |
1408 | } | |
1409 | ||
e59058c4 | 1410 | /** |
3621a710 | 1411 | * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list |
e59058c4 JS |
1412 | * @phba: pointer to lpfc hba data structure. |
1413 | * @mbq: pointer to the driver internal queue element for mailbox command. | |
1414 | * | |
1415 | * This routine put the completed mailbox command into the mailbox command | |
04c68496 JS |
1416 | * complete list. This is the locked version of the routine. The mailbox |
1417 | * complete list is used by the driver worker thread to process mailbox | |
1418 | * complete callback functions outside the driver interrupt handler. | |
e59058c4 | 1419 | **/ |
92d7f7b0 | 1420 | void |
04c68496 | 1421 | lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
92d7f7b0 | 1422 | { |
5b75da2f JS |
1423 | unsigned long iflag; |
1424 | ||
b1c11812 | 1425 | /* This function expects to be called from interrupt context */ |
5b75da2f | 1426 | spin_lock_irqsave(&phba->hbalock, iflag); |
04c68496 | 1427 | __lpfc_mbox_cmpl_put(phba, mbq); |
5b75da2f | 1428 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
1429 | return; |
1430 | } | |
1431 | ||
04c68496 JS |
1432 | /** |
1433 | * lpfc_mbox_cmd_check - Check the validality of a mailbox command | |
1434 | * @phba: pointer to lpfc hba data structure. | |
1435 | * @mboxq: pointer to the driver internal queue element for mailbox command. | |
1436 | * | |
1437 | * This routine is to check whether a mailbox command is valid to be issued. | |
1438 | * This check will be performed by both the mailbox issue API when a client | |
1439 | * is to issue a mailbox command to the mailbox transport. | |
1440 | * | |
1441 | * Return 0 - pass the check, -ENODEV - fail the check | |
1442 | **/ | |
1443 | int | |
1444 | lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
1445 | { | |
1446 | /* Mailbox command that have a completion handler must also have a | |
1447 | * vport specified. | |
1448 | */ | |
1449 | if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && | |
1450 | mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { | |
1451 | if (!mboxq->vport) { | |
1452 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, | |
1453 | "1814 Mbox x%x failed, no vport\n", | |
1454 | mboxq->u.mb.mbxCommand); | |
1455 | dump_stack(); | |
1456 | return -ENODEV; | |
1457 | } | |
1458 | } | |
1459 | return 0; | |
1460 | } | |
1461 | ||
1462 | /** | |
1463 | * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command | |
1464 | * @phba: pointer to lpfc hba data structure. | |
1465 | * | |
1466 | * This routine is to check whether the HBA device is ready for posting a | |
1467 | * mailbox command. It is used by the mailbox transport API at the time the | |
1468 | * to post a mailbox command to the device. | |
1469 | * | |
1470 | * Return 0 - pass the check, -ENODEV - fail the check | |
1471 | **/ | |
1472 | int | |
1473 | lpfc_mbox_dev_check(struct lpfc_hba *phba) | |
1474 | { | |
1475 | /* If the PCI channel is in offline state, do not issue mbox */ | |
1476 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
1477 | return -ENODEV; | |
1478 | ||
1479 | /* If the HBA is in error state, do not issue mbox */ | |
1480 | if (phba->link_state == LPFC_HBA_ERROR) | |
1481 | return -ENODEV; | |
1482 | ||
1483 | return 0; | |
1484 | } | |
1485 | ||
e59058c4 | 1486 | /** |
3621a710 | 1487 | * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value |
e59058c4 JS |
1488 | * @phba: pointer to lpfc hba data structure. |
1489 | * @cmd: mailbox command code. | |
1490 | * | |
1491 | * This routine retrieves the proper timeout value according to the mailbox | |
1492 | * command code. | |
1493 | * | |
1494 | * Return codes | |
1495 | * Timeout value to be used for the given mailbox command | |
1496 | **/ | |
a309a6b6 JS |
1497 | int |
1498 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd) | |
1499 | { | |
1500 | switch (cmd) { | |
1501 | case MBX_WRITE_NV: /* 0x03 */ | |
1502 | case MBX_UPDATE_CFG: /* 0x1B */ | |
1503 | case MBX_DOWN_LOAD: /* 0x1C */ | |
1504 | case MBX_DEL_LD_ENTRY: /* 0x1D */ | |
1505 | case MBX_LOAD_AREA: /* 0x81 */ | |
09372820 | 1506 | case MBX_WRITE_WWN: /* 0x98 */ |
a309a6b6 JS |
1507 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
1508 | return LPFC_MBOX_TMO_FLASH_CMD; | |
04c68496 JS |
1509 | case MBX_SLI4_CONFIG: /* 0x9b */ |
1510 | return LPFC_MBOX_SLI4_CONFIG_TMO; | |
a309a6b6 JS |
1511 | } |
1512 | return LPFC_MBOX_TMO; | |
1513 | } | |
04c68496 JS |
1514 | |
1515 | /** | |
1516 | * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command | |
1517 | * @mbox: pointer to lpfc mbox command. | |
1518 | * @sgentry: sge entry index. | |
1519 | * @phyaddr: physical address for the sge | |
1520 | * @length: Length of the sge. | |
1521 | * | |
1522 | * This routine sets up an entry in the non-embedded mailbox command at the sge | |
1523 | * index location. | |
1524 | **/ | |
1525 | void | |
1526 | lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, | |
1527 | dma_addr_t phyaddr, uint32_t length) | |
1528 | { | |
1529 | struct lpfc_mbx_nembed_cmd *nembed_sge; | |
1530 | ||
1531 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) | |
1532 | &mbox->u.mqe.un.nembed_cmd; | |
1533 | nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); | |
1534 | nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); | |
1535 | nembed_sge->sge[sgentry].length = length; | |
1536 | } | |
1537 | ||
1538 | /** | |
1539 | * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command | |
1540 | * @mbox: pointer to lpfc mbox command. | |
1541 | * @sgentry: sge entry index. | |
1542 | * | |
1543 | * This routine gets an entry from the non-embedded mailbox command at the sge | |
1544 | * index location. | |
1545 | **/ | |
1546 | void | |
1547 | lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, | |
1548 | struct lpfc_mbx_sge *sge) | |
1549 | { | |
1550 | struct lpfc_mbx_nembed_cmd *nembed_sge; | |
1551 | ||
1552 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) | |
1553 | &mbox->u.mqe.un.nembed_cmd; | |
1554 | sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; | |
1555 | sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; | |
1556 | sge->length = nembed_sge->sge[sgentry].length; | |
1557 | } | |
1558 | ||
1559 | /** | |
1560 | * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command | |
1561 | * @phba: pointer to lpfc hba data structure. | |
1562 | * @mbox: pointer to lpfc mbox command. | |
1563 | * | |
1564 | * This routine frees SLI4 specific mailbox command for sending IOCTL command. | |
1565 | **/ | |
1566 | void | |
1567 | lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) | |
1568 | { | |
1569 | struct lpfc_mbx_sli4_config *sli4_cfg; | |
1570 | struct lpfc_mbx_sge sge; | |
1571 | dma_addr_t phyaddr; | |
1572 | uint32_t sgecount, sgentry; | |
1573 | ||
1574 | sli4_cfg = &mbox->u.mqe.un.sli4_config; | |
1575 | ||
1576 | /* For embedded mbox command, just free the mbox command */ | |
1577 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { | |
1578 | mempool_free(mbox, phba->mbox_mem_pool); | |
1579 | return; | |
1580 | } | |
1581 | ||
1582 | /* For non-embedded mbox command, we need to free the pages first */ | |
1583 | sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); | |
1584 | /* There is nothing we can do if there is no sge address array */ | |
1585 | if (unlikely(!mbox->sge_array)) { | |
1586 | mempool_free(mbox, phba->mbox_mem_pool); | |
1587 | return; | |
1588 | } | |
1589 | /* Each non-embedded DMA memory was allocated in the length of a page */ | |
1590 | for (sgentry = 0; sgentry < sgecount; sgentry++) { | |
1591 | lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); | |
1592 | phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); | |
1593 | dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE, | |
1594 | mbox->sge_array->addr[sgentry], phyaddr); | |
1595 | } | |
1596 | /* Free the sge address array memory */ | |
1597 | kfree(mbox->sge_array); | |
1598 | /* Finally, free the mailbox command itself */ | |
1599 | mempool_free(mbox, phba->mbox_mem_pool); | |
1600 | } | |
1601 | ||
1602 | /** | |
1603 | * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command | |
1604 | * @phba: pointer to lpfc hba data structure. | |
1605 | * @mbox: pointer to lpfc mbox command. | |
1606 | * @subsystem: The sli4 config sub mailbox subsystem. | |
1607 | * @opcode: The sli4 config sub mailbox command opcode. | |
1608 | * @length: Length of the sli4 config mailbox command. | |
1609 | * | |
1610 | * This routine sets up the header fields of SLI4 specific mailbox command | |
1611 | * for sending IOCTL command. | |
1612 | * | |
1613 | * Return: the actual length of the mbox command allocated (mostly useful | |
1614 | * for none embedded mailbox command). | |
1615 | **/ | |
1616 | int | |
1617 | lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, | |
1618 | uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) | |
1619 | { | |
1620 | struct lpfc_mbx_sli4_config *sli4_config; | |
1621 | union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; | |
1622 | uint32_t alloc_len; | |
1623 | uint32_t resid_len; | |
1624 | uint32_t pagen, pcount; | |
1625 | void *viraddr; | |
1626 | dma_addr_t phyaddr; | |
1627 | ||
1628 | /* Set up SLI4 mailbox command header fields */ | |
1629 | memset(mbox, 0, sizeof(*mbox)); | |
1630 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); | |
1631 | ||
1632 | /* Set up SLI4 ioctl command header fields */ | |
1633 | sli4_config = &mbox->u.mqe.un.sli4_config; | |
1634 | ||
1635 | /* Setup for the embedded mbox command */ | |
1636 | if (emb) { | |
1637 | /* Set up main header fields */ | |
1638 | bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); | |
1639 | sli4_config->header.cfg_mhdr.payload_length = | |
1640 | LPFC_MBX_CMD_HDR_LENGTH + length; | |
1641 | /* Set up sub-header fields following main header */ | |
1642 | bf_set(lpfc_mbox_hdr_opcode, | |
1643 | &sli4_config->header.cfg_shdr.request, opcode); | |
1644 | bf_set(lpfc_mbox_hdr_subsystem, | |
1645 | &sli4_config->header.cfg_shdr.request, subsystem); | |
1646 | sli4_config->header.cfg_shdr.request.request_length = length; | |
1647 | return length; | |
1648 | } | |
1649 | ||
1650 | /* Setup for the none-embedded mbox command */ | |
1651 | pcount = (PAGE_ALIGN(length))/PAGE_SIZE; | |
1652 | pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? | |
1653 | LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; | |
1654 | /* Allocate record for keeping SGE virtual addresses */ | |
1655 | mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), | |
1656 | GFP_KERNEL); | |
1657 | if (!mbox->sge_array) | |
1658 | return 0; | |
1659 | ||
1660 | for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { | |
1661 | /* The DMA memory is always allocated in the length of a | |
1662 | * page even though the last SGE might not fill up to a | |
1663 | * page, this is used as a priori size of PAGE_SIZE for | |
1664 | * the later DMA memory free. | |
1665 | */ | |
1666 | viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE, | |
1667 | &phyaddr, GFP_KERNEL); | |
1668 | /* In case of malloc fails, proceed with whatever we have */ | |
1669 | if (!viraddr) | |
1670 | break; | |
d11e31dd | 1671 | memset(viraddr, 0, PAGE_SIZE); |
04c68496 JS |
1672 | mbox->sge_array->addr[pagen] = viraddr; |
1673 | /* Keep the first page for later sub-header construction */ | |
1674 | if (pagen == 0) | |
1675 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; | |
1676 | resid_len = length - alloc_len; | |
1677 | if (resid_len > PAGE_SIZE) { | |
1678 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, | |
1679 | PAGE_SIZE); | |
1680 | alloc_len += PAGE_SIZE; | |
1681 | } else { | |
1682 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, | |
1683 | resid_len); | |
1684 | alloc_len = length; | |
1685 | } | |
1686 | } | |
1687 | ||
1688 | /* Set up main header fields in mailbox command */ | |
1689 | sli4_config->header.cfg_mhdr.payload_length = alloc_len; | |
1690 | bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); | |
1691 | ||
1692 | /* Set up sub-header fields into the first page */ | |
1693 | if (pagen > 0) { | |
1694 | bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); | |
1695 | bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); | |
1696 | cfg_shdr->request.request_length = | |
1697 | alloc_len - sizeof(union lpfc_sli4_cfg_shdr); | |
1698 | } | |
1699 | /* The sub-header is in DMA memory, which needs endian converstion */ | |
1700 | lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, | |
1701 | sizeof(union lpfc_sli4_cfg_shdr)); | |
1702 | ||
1703 | return alloc_len; | |
1704 | } | |
1705 | ||
1706 | /** | |
1707 | * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command | |
1708 | * @phba: pointer to lpfc hba data structure. | |
1709 | * @mbox: pointer to lpfc mbox command. | |
1710 | * | |
1711 | * This routine gets the opcode from a SLI4 specific mailbox command for | |
1712 | * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG | |
1713 | * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be | |
1714 | * returned. | |
1715 | **/ | |
1716 | uint8_t | |
1717 | lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox) | |
1718 | { | |
1719 | struct lpfc_mbx_sli4_config *sli4_cfg; | |
1720 | union lpfc_sli4_cfg_shdr *cfg_shdr; | |
1721 | ||
1722 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) | |
1723 | return 0; | |
1724 | sli4_cfg = &mbox->u.mqe.un.sli4_config; | |
1725 | ||
1726 | /* For embedded mbox command, get opcode from embedded sub-header*/ | |
1727 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { | |
1728 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; | |
1729 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); | |
1730 | } | |
1731 | ||
1732 | /* For non-embedded mbox command, get opcode from first dma page */ | |
1733 | if (unlikely(!mbox->sge_array)) | |
1734 | return 0; | |
1735 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; | |
1736 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); | |
1737 | } | |
1738 | ||
1739 | /** | |
1740 | * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox | |
1741 | * @mboxq: pointer to lpfc mbox command. | |
1742 | * | |
1743 | * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES | |
1744 | * mailbox command. | |
1745 | **/ | |
1746 | void | |
1747 | lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) | |
1748 | { | |
1749 | /* Set up SLI4 mailbox command header fields */ | |
1750 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
1751 | bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); | |
1752 | ||
1753 | /* Set up host requested features. */ | |
1754 | bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); | |
1755 | ||
0c287589 JS |
1756 | if (phba->cfg_enable_fip) |
1757 | bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0); | |
1758 | else | |
1759 | bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 1); | |
04c68496 JS |
1760 | |
1761 | /* Enable DIF (block guard) only if configured to do so. */ | |
1762 | if (phba->cfg_enable_bg) | |
1763 | bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); | |
1764 | ||
1765 | /* Enable NPIV only if configured to do so. */ | |
1766 | if (phba->max_vpi && phba->cfg_enable_npiv) | |
1767 | bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); | |
1768 | ||
1769 | return; | |
1770 | } | |
1771 | ||
1772 | /** | |
1773 | * lpfc_init_vfi - Initialize the INIT_VFI mailbox command | |
1774 | * @mbox: pointer to lpfc mbox command to initialize. | |
1775 | * @vport: Vport associated with the VF. | |
1776 | * | |
1777 | * This routine initializes @mbox to all zeros and then fills in the mailbox | |
1778 | * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI | |
1779 | * in the context of an FCF. The driver issues this command to setup a VFI | |
1780 | * before issuing a FLOGI to login to the VSAN. The driver should also issue a | |
1781 | * REG_VFI after a successful VSAN login. | |
1782 | **/ | |
1783 | void | |
1784 | lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) | |
1785 | { | |
1786 | struct lpfc_mbx_init_vfi *init_vfi; | |
1787 | ||
1788 | memset(mbox, 0, sizeof(*mbox)); | |
1789 | init_vfi = &mbox->u.mqe.un.init_vfi; | |
1790 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); | |
1791 | bf_set(lpfc_init_vfi_vr, init_vfi, 1); | |
1792 | bf_set(lpfc_init_vfi_vt, init_vfi, 1); | |
1793 | bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base); | |
1794 | bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi); | |
1795 | } | |
1796 | ||
1797 | /** | |
1798 | * lpfc_reg_vfi - Initialize the REG_VFI mailbox command | |
1799 | * @mbox: pointer to lpfc mbox command to initialize. | |
1800 | * @vport: vport associated with the VF. | |
1801 | * @phys: BDE DMA bus address used to send the service parameters to the HBA. | |
1802 | * | |
1803 | * This routine initializes @mbox to all zeros and then fills in the mailbox | |
1804 | * fields from @vport, and uses @buf as a DMAable buffer to send the vport's | |
1805 | * fc service parameters to the HBA for this VFI. REG_VFI configures virtual | |
1806 | * fabrics identified by VFI in the context of an FCF. | |
1807 | **/ | |
1808 | void | |
1809 | lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) | |
1810 | { | |
1811 | struct lpfc_mbx_reg_vfi *reg_vfi; | |
1812 | ||
1813 | memset(mbox, 0, sizeof(*mbox)); | |
1814 | reg_vfi = &mbox->u.mqe.un.reg_vfi; | |
1815 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); | |
1816 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); | |
1817 | bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base); | |
1818 | bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi); | |
1819 | bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base); | |
1820 | reg_vfi->bde.addrHigh = putPaddrHigh(phys); | |
1821 | reg_vfi->bde.addrLow = putPaddrLow(phys); | |
1822 | reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); | |
1823 | reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; | |
1824 | bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); | |
1825 | } | |
1826 | ||
1827 | /** | |
1828 | * lpfc_init_vpi - Initialize the INIT_VPI mailbox command | |
1c6834a7 | 1829 | * @phba: pointer to the hba structure to init the VPI for. |
04c68496 JS |
1830 | * @mbox: pointer to lpfc mbox command to initialize. |
1831 | * @vpi: VPI to be initialized. | |
1832 | * | |
1833 | * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the | |
1834 | * command to activate a virtual N_Port. The HBA assigns a MAC address to use | |
1835 | * with the virtual N Port. The SLI Host issues this command before issuing a | |
1836 | * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a | |
1837 | * successful virtual NPort login. | |
1838 | **/ | |
1839 | void | |
1c6834a7 | 1840 | lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) |
04c68496 JS |
1841 | { |
1842 | memset(mbox, 0, sizeof(*mbox)); | |
1843 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); | |
1c6834a7 JS |
1844 | bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, |
1845 | vpi + phba->vpi_base); | |
1846 | bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, | |
1847 | phba->pport->vfi + phba->vfi_base); | |
04c68496 JS |
1848 | } |
1849 | ||
1850 | /** | |
1851 | * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command | |
1852 | * @mbox: pointer to lpfc mbox command to initialize. | |
1853 | * @vfi: VFI to be unregistered. | |
1854 | * | |
1855 | * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric | |
1856 | * (logical NPort) into the inactive state. The SLI Host must have logged out | |
1857 | * and unregistered all remote N_Ports to abort any activity on the virtual | |
1858 | * fabric. The SLI Port posts the mailbox response after marking the virtual | |
1859 | * fabric inactive. | |
1860 | **/ | |
1861 | void | |
1862 | lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi) | |
1863 | { | |
1864 | memset(mbox, 0, sizeof(*mbox)); | |
1865 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); | |
1866 | bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi); | |
1867 | } | |
1868 | ||
1869 | /** | |
1870 | * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters. | |
1871 | * @phba: pointer to the hba structure containing. | |
1872 | * @mbox: pointer to lpfc mbox command to initialize. | |
1873 | * | |
1874 | * This function create a SLI4 dump mailbox command to dump FCoE | |
1875 | * parameters stored in region 23. | |
1876 | **/ | |
1877 | int | |
1878 | lpfc_dump_fcoe_param(struct lpfc_hba *phba, | |
1879 | struct lpfcMboxq *mbox) | |
1880 | { | |
1881 | struct lpfc_dmabuf *mp = NULL; | |
1882 | MAILBOX_t *mb; | |
1883 | ||
1884 | memset(mbox, 0, sizeof(*mbox)); | |
1885 | mb = &mbox->u.mb; | |
1886 | ||
1887 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
1888 | if (mp) | |
1889 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
1890 | ||
1891 | if (!mp || !mp->virt) { | |
1892 | kfree(mp); | |
1893 | /* dump_fcoe_param failed to allocate memory */ | |
1894 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
1895 | "2569 lpfc_dump_fcoe_param: memory" | |
e4e74273 | 1896 | " allocation failed\n"); |
04c68496 JS |
1897 | return 1; |
1898 | } | |
1899 | ||
1900 | memset(mp->virt, 0, LPFC_BPL_SIZE); | |
1901 | INIT_LIST_HEAD(&mp->list); | |
1902 | ||
1903 | /* save address for completion */ | |
1904 | mbox->context1 = (uint8_t *) mp; | |
1905 | ||
1906 | mb->mbxCommand = MBX_DUMP_MEMORY; | |
1907 | mb->un.varDmp.type = DMP_NV_PARAMS; | |
a0c87cbd JS |
1908 | mb->un.varDmp.region_id = DMP_REGION_23; |
1909 | mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; | |
04c68496 JS |
1910 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
1911 | mb->un.varWords[4] = putPaddrHigh(mp->phys); | |
1912 | return 0; | |
1913 | } | |
1914 | ||
1915 | /** | |
1916 | * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command | |
1917 | * @phba: pointer to the hba structure containing the FCF index and RQ ID. | |
1918 | * @mbox: pointer to lpfc mbox command to initialize. | |
1919 | * | |
1920 | * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The | |
1921 | * SLI Host uses the command to activate an FCF after it has acquired FCF | |
1922 | * information via a READ_FCF mailbox command. This mailbox command also is used | |
1923 | * to indicate where received unsolicited frames from this FCF will be sent. By | |
1924 | * default this routine will set up the FCF to forward all unsolicited frames | |
1925 | * the the RQ ID passed in the @phba. This can be overridden by the caller for | |
1926 | * more complicated setups. | |
1927 | **/ | |
1928 | void | |
1929 | lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) | |
1930 | { | |
1931 | struct lpfc_mbx_reg_fcfi *reg_fcfi; | |
1932 | ||
1933 | memset(mbox, 0, sizeof(*mbox)); | |
1934 | reg_fcfi = &mbox->u.mqe.un.reg_fcfi; | |
1935 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); | |
1936 | bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id); | |
1937 | bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); | |
1938 | bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); | |
1939 | bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); | |
1940 | bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx); | |
1941 | /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */ | |
1942 | bf_set(lpfc_reg_fcfi_mam, reg_fcfi, | |
1943 | (~phba->fcf.addr_mode) & 0x3); | |
1944 | if (phba->fcf.fcf_flag & FCF_VALID_VLAN) { | |
1945 | bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); | |
1946 | bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id); | |
1947 | } | |
1948 | } | |
1949 | ||
1950 | /** | |
1951 | * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command | |
1952 | * @mbox: pointer to lpfc mbox command to initialize. | |
1953 | * @fcfi: FCFI to be unregistered. | |
1954 | * | |
1955 | * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). | |
1956 | * The SLI Host uses the command to inactivate an FCFI. | |
1957 | **/ | |
1958 | void | |
1959 | lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) | |
1960 | { | |
1961 | memset(mbox, 0, sizeof(*mbox)); | |
1962 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); | |
1963 | bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); | |
1964 | } | |
1965 | ||
1966 | /** | |
1967 | * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command | |
1968 | * @mbox: pointer to lpfc mbox command to initialize. | |
1969 | * @ndlp: The nodelist structure that describes the RPI to resume. | |
1970 | * | |
1971 | * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a | |
1972 | * link event. | |
1973 | **/ | |
1974 | void | |
1975 | lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) | |
1976 | { | |
1977 | struct lpfc_mbx_resume_rpi *resume_rpi; | |
1978 | ||
1979 | memset(mbox, 0, sizeof(*mbox)); | |
1980 | resume_rpi = &mbox->u.mqe.un.resume_rpi; | |
1981 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); | |
8fa38513 JS |
1982 | bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi); |
1983 | bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); | |
1984 | resume_rpi->event_tag = ndlp->phba->fc_eventTag; | |
04c68496 | 1985 | } |