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