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