2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 * @defgroup sli SLI-4 Base APIs
40 * All common (i.e. transport-independent) SLI-4 functions are implemented
46 #if defined(OCS_INCLUDE_DEBUG)
47 #include "ocs_utils.h"
50 #define SLI4_BMBX_DELAY_US 1000 /* 1 ms */
51 #define SLI4_INIT_PORT_DELAY_US 10000 /* 10 ms */
53 static int32_t sli_fw_init(sli4_t *);
54 static int32_t sli_fw_term(sli4_t *);
55 static int32_t sli_sliport_control(sli4_t *sli4, uint32_t endian);
56 static int32_t sli_cmd_fw_deinitialize(sli4_t *, void *, size_t);
57 static int32_t sli_cmd_fw_initialize(sli4_t *, void *, size_t);
58 static int32_t sli_queue_doorbell(sli4_t *, sli4_queue_t *);
59 static uint8_t sli_queue_entry_is_valid(sli4_queue_t *, uint8_t *, uint8_t);
61 const uint8_t sli4_fw_initialize[] = {
62 0xff, 0x12, 0x34, 0xff,
63 0xff, 0x56, 0x78, 0xff,
66 const uint8_t sli4_fw_deinitialize[] = {
67 0xff, 0xaa, 0xbb, 0xff,
68 0xff, 0xcc, 0xdd, 0xff,
73 uint32_t family; /* generation */
74 sli4_asic_type_e type;
78 sli4_asic_entry_t sli4_asic_table[] = {
79 { 0x00, 1, SLI4_ASIC_TYPE_BE3, SLI4_ASIC_REV_A0},
80 { 0x01, 1, SLI4_ASIC_TYPE_BE3, SLI4_ASIC_REV_A1},
81 { 0x02, 1, SLI4_ASIC_TYPE_BE3, SLI4_ASIC_REV_A2},
82 { 0x00, 4, SLI4_ASIC_TYPE_SKYHAWK, SLI4_ASIC_REV_A0},
83 { 0x00, 2, SLI4_ASIC_TYPE_SKYHAWK, SLI4_ASIC_REV_A0},
84 { 0x10, 1, SLI4_ASIC_TYPE_BE3, SLI4_ASIC_REV_B0},
85 { 0x10, 0x04, SLI4_ASIC_TYPE_SKYHAWK, SLI4_ASIC_REV_B0},
86 { 0x11, 0x04, SLI4_ASIC_TYPE_SKYHAWK, SLI4_ASIC_REV_B1},
87 { 0x0, 0x0a, SLI4_ASIC_TYPE_LANCER, SLI4_ASIC_REV_A0},
88 { 0x10, 0x0b, SLI4_ASIC_TYPE_LANCER, SLI4_ASIC_REV_B0},
89 { 0x30, 0x0b, SLI4_ASIC_TYPE_LANCER, SLI4_ASIC_REV_D0},
90 { 0x3, 0x0b, SLI4_ASIC_TYPE_LANCERG6,SLI4_ASIC_REV_A3},
91 { 0x0, 0x0c, SLI4_ASIC_TYPE_LANCERG6,SLI4_ASIC_REV_A0},
92 { 0x1, 0x0c, SLI4_ASIC_TYPE_LANCERG6,SLI4_ASIC_REV_A1},
93 { 0x3, 0x0c, SLI4_ASIC_TYPE_LANCERG6,SLI4_ASIC_REV_A3},
95 { 0x00, 0x05, SLI4_ASIC_TYPE_CORSAIR, SLI4_ASIC_REV_A0},
99 * @brief Convert queue type enum (SLI_QTYPE_*) into a string.
101 const char *SLI_QNAME[] = {
111 * @brief Define the mapping of registers to their BAR and offset.
114 * Although SLI-4 specification defines a common set of registers, their locations
115 * (both BAR and offset) depend on the interface type. This array maps a register
116 * enum to an array of BAR/offset pairs indexed by the interface type. For
117 * example, to access the bootstrap mailbox register on an interface type 0
118 * device, code can refer to the offset using regmap[SLI4_REG_BMBX][0].offset.
120 * @b Note: A value of UINT32_MAX for either the register set (rset) or offset (off)
121 * indicates an invalid mapping.
123 const sli4_reg_t regmap[SLI4_REG_MAX][SLI4_MAX_IF_TYPES] = {
126 { 2, SLI4_BMBX_REG }, { 0, SLI4_BMBX_REG }, { 0, SLI4_BMBX_REG }, { 0, SLI4_BMBX_REG },
128 /* SLI4_REG_EQCQ_DOORBELL */
130 { 2, SLI4_EQCQ_DOORBELL_REG }, { 0, SLI4_EQCQ_DOORBELL_REG },
131 { 0, SLI4_EQCQ_DOORBELL_REG }, { 0, SLI4_EQCQ_DOORBELL_REG },
133 /* SLI4_REG_FCOE_RQ_DOORBELL */
135 { 2, SLI4_RQ_DOORBELL_REG }, { 0, SLI4_RQ_DOORBELL_REG },
136 { 0, SLI4_RQ_DOORBELL_REG }, { UINT32_MAX, UINT32_MAX },
138 /* SLI4_REG_IO_WQ_DOORBELL */
140 { 2, SLI4_IO_WQ_DOORBELL_REG }, { 0, SLI4_IO_WQ_DOORBELL_REG }, { 0, SLI4_IO_WQ_DOORBELL_REG }, { UINT32_MAX, UINT32_MAX },
142 /* SLI4_REG_MQ_DOORBELL */
144 { 2, SLI4_MQ_DOORBELL_REG }, { 0, SLI4_MQ_DOORBELL_REG },
145 { 0, SLI4_MQ_DOORBELL_REG }, { 0, SLI4_MQ_DOORBELL_REG },
147 /* SLI4_REG_PHYSDEV_CONTROL */
149 { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { 0, SLI4_PHSDEV_CONTROL_REG_23 }, { 0, SLI4_PHSDEV_CONTROL_REG_23 },
151 /* SLI4_REG_SLIPORT_CONTROL */
153 { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { 0, SLI4_SLIPORT_CONTROL_REG }, { UINT32_MAX, UINT32_MAX },
155 /* SLI4_REG_SLIPORT_ERROR1 */
157 { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { 0, SLI4_SLIPORT_ERROR1 }, { UINT32_MAX, UINT32_MAX },
159 /* SLI4_REG_SLIPORT_ERROR2 */
161 { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { 0, SLI4_SLIPORT_ERROR2 }, { UINT32_MAX, UINT32_MAX },
163 /* SLI4_REG_SLIPORT_SEMAPHORE */
165 { 1, SLI4_PORT_SEMAPHORE_REG_0 }, { 0, SLI4_PORT_SEMAPHORE_REG_1 },
166 { 0, SLI4_PORT_SEMAPHORE_REG_23 }, { 0, SLI4_PORT_SEMAPHORE_REG_23 },
168 /* SLI4_REG_SLIPORT_STATUS */
170 { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { 0, SLI4_PORT_STATUS_REG_23 }, { 0, SLI4_PORT_STATUS_REG_23 },
172 /* SLI4_REG_UERR_MASK_HI */
174 { 0, SLI4_UERR_MASK_HIGH_REG }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
176 /* SLI4_REG_UERR_MASK_LO */
178 { 0, SLI4_UERR_MASK_LOW_REG }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
180 /* SLI4_REG_UERR_STATUS_HI */
182 { 0, SLI4_UERR_STATUS_HIGH_REG }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
184 /* SLI4_REG_UERR_STATUS_LO */
186 { 0, SLI4_UERR_STATUS_LOW_REG }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
188 /* SLI4_REG_SW_UE_CSR1 */
190 { 1, SLI4_SW_UE_CSR1}, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
192 /* SLI4_REG_SW_UE_CSR2 */
194 { 1, SLI4_SW_UE_CSR2}, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX }, { UINT32_MAX, UINT32_MAX },
199 * @brief Read the given SLI register.
201 * @param sli Pointer to the SLI context.
202 * @param reg Register name enum.
204 * @return Returns the register value.
207 sli_reg_read(sli4_t *sli, sli4_regname_e reg)
209 const sli4_reg_t *r = &(regmap[reg][sli->if_type]);
211 if ((UINT32_MAX == r->rset) || (UINT32_MAX == r->off)) {
212 ocs_log_err(sli->os, "regname %d not defined for if_type %d\n", reg, sli->if_type);
216 return ocs_reg_read32(sli->os, r->rset, r->off);
220 * @brief Write the value to the given SLI register.
222 * @param sli Pointer to the SLI context.
223 * @param reg Register name enum.
224 * @param val Value to write.
229 sli_reg_write(sli4_t *sli, sli4_regname_e reg, uint32_t val)
231 const sli4_reg_t *r = &(regmap[reg][sli->if_type]);
233 if ((UINT32_MAX == r->rset) || (UINT32_MAX == r->off)) {
234 ocs_log_err(sli->os, "regname %d not defined for if_type %d\n", reg, sli->if_type);
238 ocs_reg_write32(sli->os, r->rset, r->off, val);
242 * @brief Check if the SLI_INTF register is valid.
244 * @param val 32-bit SLI_INTF register value.
246 * @return Returns 0 on success, or a non-zero value on failure.
249 sli_intf_valid_check(uint32_t val)
251 return ((val >> SLI4_INTF_VALID_SHIFT) & SLI4_INTF_VALID_MASK) != SLI4_INTF_VALID;
255 * @brief Retrieve the SLI revision level.
257 * @param val 32-bit SLI_INTF register value.
259 * @return Returns the SLI revision level.
262 sli_intf_sli_revision(uint32_t val)
264 return ((val >> SLI4_INTF_SLI_REVISION_SHIFT) & SLI4_INTF_SLI_REVISION_MASK);
268 sli_intf_sli_family(uint32_t val)
270 return ((val >> SLI4_INTF_SLI_FAMILY_SHIFT) & SLI4_INTF_SLI_FAMILY_MASK);
274 * @brief Retrieve the SLI interface type.
276 * @param val 32-bit SLI_INTF register value.
278 * @return Returns the SLI interface type.
281 sli_intf_if_type(uint32_t val)
283 return ((val >> SLI4_INTF_IF_TYPE_SHIFT) & SLI4_INTF_IF_TYPE_MASK);
287 * @brief Retrieve PCI revision ID.
289 * @param val 32-bit PCI CLASS_REVISION register value.
291 * @return Returns the PCI revision ID.
294 sli_pci_rev_id(uint32_t val)
296 return ((val >> SLI4_PCI_REV_ID_SHIFT) & SLI4_PCI_REV_ID_MASK);
300 * @brief retrieve SLI ASIC generation
302 * @param val 32-bit SLI_ASIC_ID register value
304 * @return SLI ASIC generation
307 sli_asic_gen(uint32_t val)
309 return ((val >> SLI4_ASIC_GEN_SHIFT) & SLI4_ASIC_GEN_MASK);
313 * @brief Wait for the bootstrap mailbox to report "ready".
315 * @param sli4 SLI context pointer.
316 * @param msec Number of milliseconds to wait.
318 * @return Returns 0 if BMBX is ready, or non-zero otherwise (i.e. time out occurred).
321 sli_bmbx_wait(sli4_t *sli4, uint32_t msec)
326 ocs_udelay(SLI4_BMBX_DELAY_US);
327 val = sli_reg_read(sli4, SLI4_REG_BMBX);
329 } while(msec && !(val & SLI4_BMBX_RDY));
331 return(!(val & SLI4_BMBX_RDY));
335 * @brief Write bootstrap mailbox.
337 * @param sli4 SLI context pointer.
339 * @return Returns 0 if command succeeded, or non-zero otherwise.
342 sli_bmbx_write(sli4_t *sli4)
346 /* write buffer location to bootstrap mailbox register */
347 ocs_dma_sync(&sli4->bmbx, OCS_DMASYNC_PREWRITE);
348 val = SLI4_BMBX_WRITE_HI(sli4->bmbx.phys);
349 sli_reg_write(sli4, SLI4_REG_BMBX, val);
351 if (sli_bmbx_wait(sli4, SLI4_BMBX_DELAY_US)) {
352 ocs_log_crit(sli4->os, "BMBX WRITE_HI failed\n");
355 val = SLI4_BMBX_WRITE_LO(sli4->bmbx.phys);
356 sli_reg_write(sli4, SLI4_REG_BMBX, val);
358 /* wait for SLI Port to set ready bit */
359 return sli_bmbx_wait(sli4, SLI4_BMBX_TIMEOUT_MSEC/*XXX*/);
362 #if defined(OCS_INCLUDE_DEBUG)
365 * @brief Dump BMBX mailbox command.
368 * Convenience function for dumping BMBX mailbox commands. Takes
369 * into account which mailbox command is given since SLI_CONFIG
370 * commands are special.
372 * @b Note: This function takes advantage of
373 * the one-command-at-a-time nature of the BMBX to be able to
374 * display non-embedded SLI_CONFIG commands. This will not work
375 * for mailbox commands on the MQ. Luckily, all current non-emb
376 * mailbox commands go through the BMBX.
378 * @param sli4 SLI context pointer.
379 * @param mbx Pointer to mailbox command to dump.
380 * @param prefix Prefix for dump label.
385 sli_dump_bmbx_command(sli4_t *sli4, void *mbx, const char *prefix)
390 /* Mailbox diagnostic logging */
391 sli4_mbox_command_header_t *hdr = (sli4_mbox_command_header_t *)mbx;
393 if (!ocs_debug_is_enabled(OCS_DEBUG_ENABLE_MQ_DUMP)) {
397 if (hdr->command == SLI4_MBOX_COMMAND_SLI_CONFIG) {
398 sli4_cmd_sli_config_t *sli_config = (sli4_cmd_sli_config_t *)hdr;
399 sli4_req_hdr_t *sli_config_hdr;
400 if (sli_config->emb) {
401 ocs_snprintf(label, sizeof(label), "%s (emb)", prefix);
403 /* if embedded, dump entire command */
404 sli_config_hdr = (sli4_req_hdr_t *)sli_config->payload.embed;
405 size = sizeof(*sli_config) - sizeof(sli_config->payload) +
406 sli_config_hdr->request_length + (4*sizeof(uint32_t));
407 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, label,
408 (uint8_t *)sli4->bmbx.virt, size);
410 sli4_sli_config_pmd_t *pmd;
411 ocs_snprintf(label, sizeof(label), "%s (non-emb hdr)", prefix);
413 /* if non-embedded, break up into two parts: SLI_CONFIG hdr
414 and the payload(s) */
415 size = sizeof(*sli_config) - sizeof(sli_config->payload) + (12 * sli_config->pmd_count);
416 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, label,
417 (uint8_t *)sli4->bmbx.virt, size);
419 /* as sanity check, make sure first PMD matches what was saved */
420 pmd = &sli_config->payload.mem;
421 if ((pmd->address_high == ocs_addr32_hi(sli4->bmbx_non_emb_pmd->phys)) &&
422 (pmd->address_low == ocs_addr32_lo(sli4->bmbx_non_emb_pmd->phys))) {
423 for (i = 0; i < sli_config->pmd_count; i++, pmd++) {
424 sli_config_hdr = sli4->bmbx_non_emb_pmd->virt;
425 ocs_snprintf(label, sizeof(label), "%s (non-emb pay[%d])",
427 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, label,
428 (uint8_t *)sli4->bmbx_non_emb_pmd->virt,
429 sli_config_hdr->request_length + (4*sizeof(uint32_t)));
432 ocs_log_debug(sli4->os, "pmd addr does not match pmd:%x %x (%x %x)\n",
433 pmd->address_high, pmd->address_low,
434 ocs_addr32_hi(sli4->bmbx_non_emb_pmd->phys),
435 ocs_addr32_lo(sli4->bmbx_non_emb_pmd->phys));
440 /* not an SLI_CONFIG command, just display first 64 bytes, like we do
443 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, prefix,
444 (uint8_t *)mbx, size);
451 * @brief Submit a command to the bootstrap mailbox and check the status.
453 * @param sli4 SLI context pointer.
455 * @return Returns 0 on success, or a non-zero value on failure.
458 sli_bmbx_command(sli4_t *sli4)
460 void *cqe = (uint8_t *)sli4->bmbx.virt + SLI4_BMBX_SIZE;
462 #if defined(OCS_INCLUDE_DEBUG)
463 sli_dump_bmbx_command(sli4, sli4->bmbx.virt, "bmbx cmd");
466 if (sli_fw_error_status(sli4) > 0) {
467 ocs_log_crit(sli4->os, "Chip is in an error state - Mailbox "
468 "command rejected status=%#x error1=%#x error2=%#x\n",
469 sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS),
470 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR1),
471 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR2));
475 if (sli_bmbx_write(sli4)) {
476 ocs_log_crit(sli4->os, "bootstrap mailbox write fail phys=%p reg=%#x\n",
477 (void*)sli4->bmbx.phys,
478 sli_reg_read(sli4, SLI4_REG_BMBX));
482 /* check completion queue entry status */
483 ocs_dma_sync(&sli4->bmbx, OCS_DMASYNC_POSTREAD);
484 if (((sli4_mcqe_t *)cqe)->val) {
485 #if defined(OCS_INCLUDE_DEBUG)
486 sli_dump_bmbx_command(sli4, sli4->bmbx.virt, "bmbx cmpl");
487 ocs_dump32(OCS_DEBUG_ENABLE_CQ_DUMP, sli4->os, "bmbx cqe", cqe, sizeof(sli4_mcqe_t));
489 return sli_cqe_mq(cqe);
491 ocs_log_err(sli4->os, "invalid or wrong type\n");
496 /****************************************************************************
502 * @brief Write a CONFIG_LINK command to the provided buffer.
504 * @param sli4 SLI context pointer.
505 * @param buf Virtual pointer to the destination buffer.
506 * @param size Buffer size, in bytes.
508 * @return Returns the number of bytes written.
511 sli_cmd_config_link(sli4_t *sli4, void *buf, size_t size)
513 sli4_cmd_config_link_t *config_link = buf;
515 ocs_memset(buf, 0, size);
517 config_link->hdr.command = SLI4_MBOX_COMMAND_CONFIG_LINK;
519 /* Port interprets zero in a field as "use default value" */
521 return sizeof(sli4_cmd_config_link_t);
526 * @brief Write a DOWN_LINK command to the provided buffer.
528 * @param sli4 SLI context pointer.
529 * @param buf Virtual pointer to the destination buffer.
530 * @param size Buffer size, in bytes.
532 * @return Returns the number of bytes written.
535 sli_cmd_down_link(sli4_t *sli4, void *buf, size_t size)
537 sli4_mbox_command_header_t *hdr = buf;
539 ocs_memset(buf, 0, size);
541 hdr->command = SLI4_MBOX_COMMAND_DOWN_LINK;
543 /* Port interprets zero in a field as "use default value" */
545 return sizeof(sli4_mbox_command_header_t);
550 * @brief Write a DUMP Type 4 command to the provided buffer.
552 * @param sli4 SLI context pointer.
553 * @param buf Virtual pointer to the destination buffer.
554 * @param size Buffer size, in bytes.
555 * @param wki The well known item ID.
557 * @return Returns the number of bytes written.
560 sli_cmd_dump_type4(sli4_t *sli4, void *buf, size_t size, uint16_t wki)
562 sli4_cmd_dump4_t *cmd = buf;
564 ocs_memset(buf, 0, size);
566 cmd->hdr.command = SLI4_MBOX_COMMAND_DUMP;
568 cmd->wki_selection = wki;
569 return sizeof(sli4_cmd_dump4_t);
574 * @brief Write a COMMON_READ_TRANSCEIVER_DATA command.
576 * @param sli4 SLI context.
577 * @param buf Destination buffer for the command.
578 * @param size Buffer size, in bytes.
579 * @param page_num The page of SFP data to retrieve (0xa0 or 0xa2).
580 * @param dma DMA structure from which the data will be copied.
582 * @note This creates a Version 0 message.
584 * @return Returns the number of bytes written.
587 sli_cmd_common_read_transceiver_data(sli4_t *sli4, void *buf, size_t size, uint32_t page_num,
590 sli4_req_common_read_transceiver_data_t *req = NULL;
591 uint32_t sli_config_off = 0;
592 uint32_t payload_size;
595 /* Payload length must accommodate both request and response */
596 payload_size = max(sizeof(sli4_req_common_read_transceiver_data_t),
597 sizeof(sli4_res_common_read_transceiver_data_t));
599 payload_size = dma->size;
602 if (sli4->port_type == SLI4_PORT_TYPE_FC) {
603 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size, dma);
607 req = (sli4_req_common_read_transceiver_data_t *)((uint8_t *)buf + sli_config_off);
609 req = (sli4_req_common_read_transceiver_data_t *)dma->virt;
610 ocs_memset(req, 0, dma->size);
613 req->hdr.opcode = SLI4_OPC_COMMON_READ_TRANSCEIVER_DATA;
614 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
615 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
617 req->page_number = page_num;
618 req->port = sli4->physical_port;
620 return(sli_config_off + sizeof(sli4_req_common_read_transceiver_data_t));
625 * @brief Write a READ_LINK_STAT command to the provided buffer.
627 * @param sli4 SLI context pointer.
628 * @param buf Virtual pointer to the destination buffer.
629 * @param size Buffer size, in bytes.
630 * @param req_ext_counters If TRUE, then the extended counters will be requested.
631 * @param clear_overflow_flags If TRUE, then overflow flags will be cleared.
632 * @param clear_all_counters If TRUE, the counters will be cleared.
634 * @return Returns the number of bytes written.
637 sli_cmd_read_link_stats(sli4_t *sli4, void *buf, size_t size,
638 uint8_t req_ext_counters,
639 uint8_t clear_overflow_flags,
640 uint8_t clear_all_counters)
642 sli4_cmd_read_link_stats_t *cmd = buf;
644 ocs_memset(buf, 0, size);
646 cmd->hdr.command = SLI4_MBOX_COMMAND_READ_LNK_STAT;
647 cmd->rec = req_ext_counters;
648 cmd->clrc = clear_all_counters;
649 cmd->clof = clear_overflow_flags;
650 return sizeof(sli4_cmd_read_link_stats_t);
655 * @brief Write a READ_STATUS command to the provided buffer.
657 * @param sli4 SLI context pointer.
658 * @param buf Virtual pointer to the destination buffer.
659 * @param size Buffer size, in bytes.
660 * @param clear_counters If TRUE, the counters will be cleared.
662 * @return Returns the number of bytes written.
665 sli_cmd_read_status(sli4_t *sli4, void *buf, size_t size,
666 uint8_t clear_counters)
668 sli4_cmd_read_status_t *cmd = buf;
670 ocs_memset(buf, 0, size);
672 cmd->hdr.command = SLI4_MBOX_COMMAND_READ_STATUS;
673 cmd->cc = clear_counters;
674 return sizeof(sli4_cmd_read_status_t);
678 * @brief Write a FW_DEINITIALIZE command to the provided buffer.
680 * @param sli4 SLI context pointer.
681 * @param buf Virtual pointer to the destination buffer.
682 * @param size Buffer size, in bytes.
684 * @return Returns the number of bytes written.
687 sli_cmd_fw_deinitialize(sli4_t *sli4, void *buf, size_t size)
690 ocs_memset(buf, 0, size);
691 ocs_memcpy(buf, sli4_fw_deinitialize, sizeof(sli4_fw_deinitialize));
693 return sizeof(sli4_fw_deinitialize);
697 * @brief Write a FW_INITIALIZE command to the provided buffer.
699 * @param sli4 SLI context pointer.
700 * @param buf Virtual pointer to the destination buffer.
701 * @param size Buffer size, in bytes.
703 * @return Returns the number of bytes written.
706 sli_cmd_fw_initialize(sli4_t *sli4, void *buf, size_t size)
709 ocs_memset(buf, 0, size);
710 ocs_memcpy(buf, sli4_fw_initialize, sizeof(sli4_fw_initialize));
712 return sizeof(sli4_fw_initialize);
717 * @brief Write an INIT_LINK command to the provided buffer.
719 * @param sli4 SLI context pointer.
720 * @param buf Virtual pointer to the destination buffer.
721 * @param size Buffer size, in bytes.
722 * @param speed Link speed.
723 * @param reset_alpa For native FC, this is the selective reset AL_PA
725 * @return Returns the number of bytes written.
728 sli_cmd_init_link(sli4_t *sli4, void *buf, size_t size, uint32_t speed, uint8_t reset_alpa)
730 sli4_cmd_init_link_t *init_link = buf;
732 ocs_memset(buf, 0, size);
734 init_link->hdr.command = SLI4_MBOX_COMMAND_INIT_LINK;
736 /* Most fields only have meaning for FC links */
737 if (sli4->config.topology != SLI4_READ_CFG_TOPO_FCOE) {
738 init_link->selective_reset_al_pa = reset_alpa;
739 init_link->link_flags.loopback = FALSE;
741 init_link->link_speed_selection_code = speed;
743 case FC_LINK_SPEED_1G:
744 case FC_LINK_SPEED_2G:
745 case FC_LINK_SPEED_4G:
746 case FC_LINK_SPEED_8G:
747 case FC_LINK_SPEED_16G:
748 case FC_LINK_SPEED_32G:
749 init_link->link_flags.fixed_speed = TRUE;
751 case FC_LINK_SPEED_10G:
752 ocs_log_test(sli4->os, "unsupported FC speed %d\n", speed);
756 switch (sli4->config.topology) {
757 case SLI4_READ_CFG_TOPO_FC:
758 /* Attempt P2P but failover to FC-AL */
759 init_link->link_flags.enable_topology_failover = TRUE;
761 if (sli_get_asic_type(sli4) == SLI4_ASIC_TYPE_LANCER)
762 init_link->link_flags.topology = SLI4_INIT_LINK_F_FCAL_FAIL_OVER;
764 init_link->link_flags.topology = SLI4_INIT_LINK_F_P2P_FAIL_OVER;
767 case SLI4_READ_CFG_TOPO_FC_AL:
768 init_link->link_flags.topology = SLI4_INIT_LINK_F_FCAL_ONLY;
769 if ((init_link->link_speed_selection_code == FC_LINK_SPEED_16G) ||
770 (init_link->link_speed_selection_code == FC_LINK_SPEED_32G)) {
771 ocs_log_test(sli4->os, "unsupported FC-AL speed %d\n", speed);
775 case SLI4_READ_CFG_TOPO_FC_DA:
776 init_link->link_flags.topology = FC_TOPOLOGY_P2P;
779 ocs_log_test(sli4->os, "unsupported topology %#x\n", sli4->config.topology);
783 init_link->link_flags.unfair = FALSE;
784 init_link->link_flags.skip_lirp_lilp = FALSE;
785 init_link->link_flags.gen_loop_validity_check = FALSE;
786 init_link->link_flags.skip_lisa = FALSE;
787 init_link->link_flags.select_hightest_al_pa = FALSE;
790 return sizeof(sli4_cmd_init_link_t);
795 * @brief Write an INIT_VFI command to the provided buffer.
797 * @param sli4 SLI context pointer.
798 * @param buf Virtual pointer to the destination buffer.
799 * @param size Buffer size, in bytes.
802 * @param vpi VPI (Set to -1 if unused.)
804 * @return Returns the number of bytes written.
807 sli_cmd_init_vfi(sli4_t *sli4, void *buf, size_t size, uint16_t vfi,
808 uint16_t fcfi, uint16_t vpi)
810 sli4_cmd_init_vfi_t *init_vfi = buf;
812 ocs_memset(buf, 0, size);
814 init_vfi->hdr.command = SLI4_MBOX_COMMAND_INIT_VFI;
817 init_vfi->fcfi = fcfi;
820 * If the VPI is valid, initialize it at the same time as
828 return sizeof(sli4_cmd_init_vfi_t);
833 * @brief Write an INIT_VPI command to the provided buffer.
835 * @param sli4 SLI context pointer.
836 * @param buf Virtual pointer to the destination buffer.
837 * @param size Buffer size, in bytes.
838 * @param vpi VPI allocated.
839 * @param vfi VFI associated with this VPI.
841 * @return Returns the number of bytes written.
844 sli_cmd_init_vpi(sli4_t *sli4, void *buf, size_t size, uint16_t vpi, uint16_t vfi)
846 sli4_cmd_init_vpi_t *init_vpi = buf;
848 ocs_memset(buf, 0, size);
850 init_vpi->hdr.command = SLI4_MBOX_COMMAND_INIT_VPI;
854 return sizeof(sli4_cmd_init_vpi_t);
859 * @brief Write a POST_XRI command to the provided buffer.
861 * @param sli4 SLI context pointer.
862 * @param buf Virtual pointer to the destination buffer.
863 * @param size Buffer size, in bytes.
864 * @param xri_base Starting XRI value for range of XRI given to SLI Port.
865 * @param xri_count Number of XRIs provided to the SLI Port.
867 * @return Returns the number of bytes written.
870 sli_cmd_post_xri(sli4_t *sli4, void *buf, size_t size, uint16_t xri_base, uint16_t xri_count)
872 sli4_cmd_post_xri_t *post_xri = buf;
874 ocs_memset(buf, 0, size);
876 post_xri->hdr.command = SLI4_MBOX_COMMAND_POST_XRI;
877 post_xri->xri_base = xri_base;
878 post_xri->xri_count = xri_count;
880 if (sli4->config.auto_xfer_rdy == 0) {
881 post_xri->enx = TRUE;
882 post_xri->val = TRUE;
885 return sizeof(sli4_cmd_post_xri_t);
890 * @brief Write a RELEASE_XRI command to the provided buffer.
892 * @param sli4 SLI context pointer.
893 * @param buf Virtual pointer to the destination buffer.
894 * @param size Buffer size, in bytes.
895 * @param num_xri The number of XRIs to be released.
897 * @return Returns the number of bytes written.
900 sli_cmd_release_xri(sli4_t *sli4, void *buf, size_t size, uint8_t num_xri)
902 sli4_cmd_release_xri_t *release_xri = buf;
904 ocs_memset(buf, 0, size);
906 release_xri->hdr.command = SLI4_MBOX_COMMAND_RELEASE_XRI;
907 release_xri->xri_count = num_xri;
909 return sizeof(sli4_cmd_release_xri_t);
913 * @brief Write a READ_CONFIG command to the provided buffer.
915 * @param sli4 SLI context pointer.
916 * @param buf Virtual pointer to the destination buffer.
917 * @param size Buffer size, in bytes
919 * @return Returns the number of bytes written.
922 sli_cmd_read_config(sli4_t *sli4, void *buf, size_t size)
924 sli4_cmd_read_config_t *read_config = buf;
926 ocs_memset(buf, 0, size);
928 read_config->hdr.command = SLI4_MBOX_COMMAND_READ_CONFIG;
930 return sizeof(sli4_cmd_read_config_t);
934 * @brief Write a READ_NVPARMS command to the provided buffer.
936 * @param sli4 SLI context pointer.
937 * @param buf Virtual pointer to the destination buffer.
938 * @param size Buffer size, in bytes.
940 * @return Returns the number of bytes written.
943 sli_cmd_read_nvparms(sli4_t *sli4, void *buf, size_t size)
945 sli4_cmd_read_nvparms_t *read_nvparms = buf;
947 ocs_memset(buf, 0, size);
949 read_nvparms->hdr.command = SLI4_MBOX_COMMAND_READ_NVPARMS;
951 return sizeof(sli4_cmd_read_nvparms_t);
955 * @brief Write a WRITE_NVPARMS command to the provided buffer.
957 * @param sli4 SLI context pointer.
958 * @param buf Virtual pointer to the destination buffer.
959 * @param size Buffer size, in bytes.
960 * @param wwpn WWPN to write - pointer to array of 8 uint8_t.
961 * @param wwnn WWNN to write - pointer to array of 8 uint8_t.
962 * @param hard_alpa Hard ALPA to write.
963 * @param preferred_d_id Preferred D_ID to write.
965 * @return Returns the number of bytes written.
968 sli_cmd_write_nvparms(sli4_t *sli4, void *buf, size_t size, uint8_t *wwpn, uint8_t *wwnn, uint8_t hard_alpa,
969 uint32_t preferred_d_id)
971 sli4_cmd_write_nvparms_t *write_nvparms = buf;
973 ocs_memset(buf, 0, size);
975 write_nvparms->hdr.command = SLI4_MBOX_COMMAND_WRITE_NVPARMS;
976 ocs_memcpy(write_nvparms->wwpn, wwpn, 8);
977 ocs_memcpy(write_nvparms->wwnn, wwnn, 8);
978 write_nvparms->hard_alpa = hard_alpa;
979 write_nvparms->preferred_d_id = preferred_d_id;
981 return sizeof(sli4_cmd_write_nvparms_t);
985 * @brief Write a READ_REV command to the provided buffer.
987 * @param sli4 SLI context pointer.
988 * @param buf Virtual pointer to the destination buffer.
989 * @param size Buffer size, in bytes.
990 * @param vpd Pointer to the buffer.
992 * @return Returns the number of bytes written.
995 sli_cmd_read_rev(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *vpd)
997 sli4_cmd_read_rev_t *read_rev = buf;
999 ocs_memset(buf, 0, size);
1001 read_rev->hdr.command = SLI4_MBOX_COMMAND_READ_REV;
1003 if (vpd && vpd->size) {
1004 read_rev->vpd = TRUE;
1006 read_rev->available_length = vpd->size;
1008 read_rev->physical_address_low = ocs_addr32_lo(vpd->phys);
1009 read_rev->physical_address_high = ocs_addr32_hi(vpd->phys);
1012 return sizeof(sli4_cmd_read_rev_t);
1017 * @brief Write a READ_SPARM64 command to the provided buffer.
1019 * @param sli4 SLI context pointer.
1020 * @param buf Virtual pointer to the destination buffer.
1021 * @param size Buffer size, in bytes.
1022 * @param dma DMA buffer for the service parameters.
1023 * @param vpi VPI used to determine the WWN.
1025 * @return Returns the number of bytes written.
1028 sli_cmd_read_sparm64(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma,
1031 sli4_cmd_read_sparm64_t *read_sparm64 = buf;
1033 ocs_memset(buf, 0, size);
1035 if (SLI4_READ_SPARM64_VPI_SPECIAL == vpi) {
1036 ocs_log_test(sli4->os, "special VPI not supported!!!\n");
1040 if (!dma || !dma->phys) {
1041 ocs_log_test(sli4->os, "bad DMA buffer\n");
1045 read_sparm64->hdr.command = SLI4_MBOX_COMMAND_READ_SPARM64;
1047 read_sparm64->bde_64.bde_type = SLI4_BDE_TYPE_BDE_64;
1048 read_sparm64->bde_64.buffer_length = dma->size;
1049 read_sparm64->bde_64.u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
1050 read_sparm64->bde_64.u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
1052 read_sparm64->vpi = vpi;
1054 return sizeof(sli4_cmd_read_sparm64_t);
1059 * @brief Write a READ_TOPOLOGY command to the provided buffer.
1061 * @param sli4 SLI context pointer.
1062 * @param buf Virtual pointer to the destination buffer.
1063 * @param size Buffer size, in bytes.
1064 * @param dma DMA buffer for loop map (optional).
1066 * @return Returns the number of bytes written.
1069 sli_cmd_read_topology(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
1071 sli4_cmd_read_topology_t *read_topo = buf;
1073 ocs_memset(buf, 0, size);
1075 read_topo->hdr.command = SLI4_MBOX_COMMAND_READ_TOPOLOGY;
1077 if (dma && dma->size) {
1078 if (dma->size < SLI4_MIN_LOOP_MAP_BYTES) {
1079 ocs_log_test(sli4->os, "loop map buffer too small %jd\n",
1084 ocs_memset(dma->virt, 0, dma->size);
1086 read_topo->bde_loop_map.bde_type = SLI4_BDE_TYPE_BDE_64;
1087 read_topo->bde_loop_map.buffer_length = dma->size;
1088 read_topo->bde_loop_map.u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
1089 read_topo->bde_loop_map.u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
1092 return sizeof(sli4_cmd_read_topology_t);
1097 * @brief Write a REG_FCFI command to the provided buffer.
1099 * @param sli4 SLI context pointer.
1100 * @param buf Virtual pointer to the destination buffer.
1101 * @param size Buffer size, in bytes.
1102 * @param index FCF index returned by READ_FCF_TABLE.
1103 * @param rq_cfg RQ_ID/R_CTL/TYPE routing information
1104 * @param vlan_id VLAN ID tag.
1106 * @return Returns the number of bytes written.
1109 sli_cmd_reg_fcfi(sli4_t *sli4, void *buf, size_t size, uint16_t index, sli4_cmd_rq_cfg_t rq_cfg[SLI4_CMD_REG_FCFI_NUM_RQ_CFG], uint16_t vlan_id)
1111 sli4_cmd_reg_fcfi_t *reg_fcfi = buf;
1114 ocs_memset(buf, 0, size);
1116 reg_fcfi->hdr.command = SLI4_MBOX_COMMAND_REG_FCFI;
1118 reg_fcfi->fcf_index = index;
1120 for (i = 0; i < SLI4_CMD_REG_FCFI_NUM_RQ_CFG; i++) {
1122 case 0: reg_fcfi->rq_id_0 = rq_cfg[0].rq_id; break;
1123 case 1: reg_fcfi->rq_id_1 = rq_cfg[1].rq_id; break;
1124 case 2: reg_fcfi->rq_id_2 = rq_cfg[2].rq_id; break;
1125 case 3: reg_fcfi->rq_id_3 = rq_cfg[3].rq_id; break;
1127 reg_fcfi->rq_cfg[i].r_ctl_mask = rq_cfg[i].r_ctl_mask;
1128 reg_fcfi->rq_cfg[i].r_ctl_match = rq_cfg[i].r_ctl_match;
1129 reg_fcfi->rq_cfg[i].type_mask = rq_cfg[i].type_mask;
1130 reg_fcfi->rq_cfg[i].type_match = rq_cfg[i].type_match;
1134 reg_fcfi->vv = TRUE;
1135 reg_fcfi->vlan_tag = vlan_id;
1138 return sizeof(sli4_cmd_reg_fcfi_t);
1142 * @brief Write REG_FCFI_MRQ to provided command buffer
1144 * @param sli4 SLI context pointer.
1145 * @param buf Virtual pointer to the destination buffer.
1146 * @param size Buffer size, in bytes.
1147 * @param fcf_index FCF index returned by READ_FCF_TABLE.
1148 * @param vlan_id VLAN ID tag.
1149 * @param rr_quant Round robin quanta if RQ selection policy is 2
1150 * @param rq_selection_policy RQ selection policy
1151 * @param num_rqs Array of count of RQs per filter
1152 * @param rq_ids Array of RQ ids per filter
1153 * @param rq_cfg RQ_ID/R_CTL/TYPE routing information
1155 * @return returns 0 for success, a negative error code value for failure.
1158 sli_cmd_reg_fcfi_mrq(sli4_t *sli4, void *buf, size_t size, uint8_t mode,
1159 uint16_t fcf_index, uint16_t vlan_id, uint8_t rq_selection_policy,
1160 uint8_t mrq_bit_mask, uint16_t num_mrqs,
1161 sli4_cmd_rq_cfg_t rq_cfg[SLI4_CMD_REG_FCFI_NUM_RQ_CFG])
1163 sli4_cmd_reg_fcfi_mrq_t *reg_fcfi_mrq = buf;
1166 ocs_memset(buf, 0, size);
1168 reg_fcfi_mrq->hdr.command = SLI4_MBOX_COMMAND_REG_FCFI_MRQ;
1169 if (mode == SLI4_CMD_REG_FCFI_SET_FCFI_MODE) {
1170 reg_fcfi_mrq->fcf_index = fcf_index;
1172 reg_fcfi_mrq->vv = TRUE;
1173 reg_fcfi_mrq->vlan_tag = vlan_id;
1178 reg_fcfi_mrq->mode = mode;
1179 for (i = 0; i < SLI4_CMD_REG_FCFI_NUM_RQ_CFG; i++) {
1180 reg_fcfi_mrq->rq_cfg[i].r_ctl_mask = rq_cfg[i].r_ctl_mask;
1181 reg_fcfi_mrq->rq_cfg[i].r_ctl_match = rq_cfg[i].r_ctl_match;
1182 reg_fcfi_mrq->rq_cfg[i].type_mask = rq_cfg[i].type_mask;
1183 reg_fcfi_mrq->rq_cfg[i].type_match = rq_cfg[i].type_match;
1186 case 3: reg_fcfi_mrq->rq_id_3 = rq_cfg[i].rq_id; break;
1187 case 2: reg_fcfi_mrq->rq_id_2 = rq_cfg[i].rq_id; break;
1188 case 1: reg_fcfi_mrq->rq_id_1 = rq_cfg[i].rq_id; break;
1189 case 0: reg_fcfi_mrq->rq_id_0 = rq_cfg[i].rq_id; break;
1193 reg_fcfi_mrq->rq_selection_policy = rq_selection_policy;
1194 reg_fcfi_mrq->mrq_filter_bitmask = mrq_bit_mask;
1195 reg_fcfi_mrq->num_mrq_pairs = num_mrqs;
1197 return sizeof(sli4_cmd_reg_fcfi_mrq_t);
1202 * @brief Write a REG_RPI command to the provided buffer.
1204 * @param sli4 SLI context pointer.
1205 * @param buf Virtual pointer to the destination buffer.
1206 * @param size Buffer size, in bytes.
1207 * @param nport_id Remote F/N_Port_ID.
1208 * @param rpi Previously-allocated Remote Port Indicator.
1209 * @param vpi Previously-allocated Virtual Port Indicator.
1210 * @param dma DMA buffer that contains the remote port's service parameters.
1211 * @param update Boolean indicating an update to an existing RPI (TRUE)
1212 * or a new registration (FALSE).
1214 * @return Returns the number of bytes written.
1217 sli_cmd_reg_rpi(sli4_t *sli4, void *buf, size_t size, uint32_t nport_id, uint16_t rpi,
1218 uint16_t vpi, ocs_dma_t *dma, uint8_t update, uint8_t enable_t10_pi)
1220 sli4_cmd_reg_rpi_t *reg_rpi = buf;
1222 ocs_memset(buf, 0, size);
1224 reg_rpi->hdr.command = SLI4_MBOX_COMMAND_REG_RPI;
1227 reg_rpi->remote_n_port_id = nport_id;
1228 reg_rpi->upd = update;
1229 reg_rpi->etow = enable_t10_pi;
1231 reg_rpi->bde_64.bde_type = SLI4_BDE_TYPE_BDE_64;
1232 reg_rpi->bde_64.buffer_length = SLI4_REG_RPI_BUF_LEN;
1233 reg_rpi->bde_64.u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
1234 reg_rpi->bde_64.u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
1238 return sizeof(sli4_cmd_reg_rpi_t);
1243 * @brief Write a REG_VFI command to the provided buffer.
1245 * @param sli4 SLI context pointer.
1246 * @param buf Virtual pointer to the destination buffer.
1247 * @param size Buffer size, in bytes.
1248 * @param domain Pointer to the domain object.
1250 * @return Returns the number of bytes written.
1253 sli_cmd_reg_vfi(sli4_t *sli4, void *buf, size_t size, ocs_domain_t *domain)
1255 sli4_cmd_reg_vfi_t *reg_vfi = buf;
1257 if (!sli4 || !buf || !domain) {
1261 ocs_memset(buf, 0, size);
1263 reg_vfi->hdr.command = SLI4_MBOX_COMMAND_REG_VFI;
1265 reg_vfi->vfi = domain->indicator;
1267 reg_vfi->fcfi = domain->fcf_indicator;
1269 /* TODO contents of domain->dma only valid if topo == FABRIC */
1270 reg_vfi->sparm.bde_type = SLI4_BDE_TYPE_BDE_64;
1271 reg_vfi->sparm.buffer_length = 0x70;
1272 reg_vfi->sparm.u.data.buffer_address_low = ocs_addr32_lo(domain->dma.phys);
1273 reg_vfi->sparm.u.data.buffer_address_high = ocs_addr32_hi(domain->dma.phys);
1275 reg_vfi->e_d_tov = sli4->config.e_d_tov;
1276 reg_vfi->r_a_tov = sli4->config.r_a_tov;
1279 reg_vfi->vpi = domain->sport->indicator;
1280 ocs_memcpy(reg_vfi->wwpn, &domain->sport->sli_wwpn, sizeof(reg_vfi->wwpn));
1281 reg_vfi->local_n_port_id = domain->sport->fc_id;
1283 return sizeof(sli4_cmd_reg_vfi_t);
1288 * @brief Write a REG_VPI command to the provided buffer.
1290 * @param sli4 SLI context pointer.
1291 * @param buf Virtual pointer to the destination buffer.
1292 * @param size Buffer size, in bytes.
1293 * @param sport Point to SLI Port object.
1294 * @param update Boolean indicating whether to update the existing VPI (true)
1295 * or create a new VPI (false).
1297 * @return Returns the number of bytes written.
1300 sli_cmd_reg_vpi(sli4_t *sli4, void *buf, size_t size, ocs_sli_port_t *sport, uint8_t update)
1302 sli4_cmd_reg_vpi_t *reg_vpi = buf;
1304 if (!sli4 || !buf || !sport) {
1308 ocs_memset(buf, 0, size);
1310 reg_vpi->hdr.command = SLI4_MBOX_COMMAND_REG_VPI;
1312 reg_vpi->local_n_port_id = sport->fc_id;
1313 reg_vpi->upd = update != 0;
1314 ocs_memcpy(reg_vpi->wwpn, &sport->sli_wwpn, sizeof(reg_vpi->wwpn));
1315 reg_vpi->vpi = sport->indicator;
1316 reg_vpi->vfi = sport->domain->indicator;
1318 return sizeof(sli4_cmd_reg_vpi_t);
1322 * @brief Write a REQUEST_FEATURES command to the provided buffer.
1324 * @param sli4 SLI context pointer.
1325 * @param buf Virtual pointer to the destination buffer.
1326 * @param size Buffer size, in bytes.
1327 * @param mask Features to request.
1328 * @param query Use feature query mode (does not change FW).
1330 * @return Returns the number of bytes written.
1333 sli_cmd_request_features(sli4_t *sli4, void *buf, size_t size, sli4_features_t mask, uint8_t query)
1335 sli4_cmd_request_features_t *features = buf;
1337 ocs_memset(buf, 0, size);
1339 features->hdr.command = SLI4_MBOX_COMMAND_REQUEST_FEATURES;
1342 features->qry = TRUE;
1344 features->command.dword = mask.dword;
1346 return sizeof(sli4_cmd_request_features_t);
1351 * @brief Write a SLI_CONFIG command to the provided buffer.
1353 * @param sli4 SLI context pointer.
1354 * @param buf Virtual pointer to the destination buffer.
1355 * @param size Buffer size, in bytes.
1356 * @param length Length in bytes of attached command.
1357 * @param dma DMA buffer for non-embedded commands.
1359 * @return Returns the number of bytes written.
1362 sli_cmd_sli_config(sli4_t *sli4, void *buf, size_t size, uint32_t length, ocs_dma_t *dma)
1364 sli4_cmd_sli_config_t *sli_config = NULL;
1366 if ((length > sizeof(sli_config->payload.embed)) && (dma == NULL)) {
1367 ocs_log_test(sli4->os, "length(%d) > payload(%ld)\n",
1368 length, sizeof(sli_config->payload.embed));
1374 ocs_memset(buf, 0, size);
1376 sli_config->hdr.command = SLI4_MBOX_COMMAND_SLI_CONFIG;
1378 sli_config->emb = TRUE;
1379 sli_config->payload_length = length;
1381 sli_config->emb = FALSE;
1383 sli_config->pmd_count = 1;
1385 sli_config->payload.mem.address_low = ocs_addr32_lo(dma->phys);
1386 sli_config->payload.mem.address_high = ocs_addr32_hi(dma->phys);
1387 sli_config->payload.mem.length = dma->size;
1388 sli_config->payload_length = dma->size;
1389 #if defined(OCS_INCLUDE_DEBUG)
1390 /* save pointer to DMA for BMBX dumping purposes */
1391 sli4->bmbx_non_emb_pmd = dma;
1396 return offsetof(sli4_cmd_sli_config_t, payload.embed);
1400 * @brief Initialize SLI Port control register.
1402 * @param sli4 SLI context pointer.
1403 * @param endian Endian value to write.
1405 * @return Returns 0 on success, or a negative error code value on failure.
1409 sli_sliport_control(sli4_t *sli4, uint32_t endian)
1416 /* Initialize port, endian */
1417 sli_reg_write(sli4, SLI4_REG_SLIPORT_CONTROL, endian | SLI4_SLIPORT_CONTROL_IP);
1419 for (iter = 0; iter < 3000; iter ++) {
1420 ocs_udelay(SLI4_INIT_PORT_DELAY_US);
1421 if (sli_fw_ready(sli4) == 1) {
1428 ocs_log_crit(sli4->os, "port failed to become ready after initialization\n");
1436 * @brief Write a UNREG_FCFI command to the provided buffer.
1438 * @param sli4 SLI context pointer.
1439 * @param buf Virtual pointer to the destination buffer.
1440 * @param size Buffer size, in bytes.
1441 * @param indicator Indicator value.
1443 * @return Returns the number of bytes written.
1446 sli_cmd_unreg_fcfi(sli4_t *sli4, void *buf, size_t size, uint16_t indicator)
1448 sli4_cmd_unreg_fcfi_t *unreg_fcfi = buf;
1450 if (!sli4 || !buf) {
1454 ocs_memset(buf, 0, size);
1456 unreg_fcfi->hdr.command = SLI4_MBOX_COMMAND_UNREG_FCFI;
1458 unreg_fcfi->fcfi = indicator;
1460 return sizeof(sli4_cmd_unreg_fcfi_t);
1465 * @brief Write an UNREG_RPI command to the provided buffer.
1467 * @param sli4 SLI context pointer.
1468 * @param buf Virtual pointer to the destination buffer.
1469 * @param size Buffer size, in bytes.
1470 * @param indicator Indicator value.
1471 * @param which Type of unregister, such as node, port, domain, or FCF.
1472 * @param fc_id FC address.
1474 * @return Returns the number of bytes written.
1477 sli_cmd_unreg_rpi(sli4_t *sli4, void *buf, size_t size, uint16_t indicator, sli4_resource_e which,
1480 sli4_cmd_unreg_rpi_t *unreg_rpi = buf;
1481 uint8_t index_indicator = 0;
1483 if (!sli4 || !buf) {
1487 ocs_memset(buf, 0, size);
1489 unreg_rpi->hdr.command = SLI4_MBOX_COMMAND_UNREG_RPI;
1492 case SLI_RSRC_FCOE_RPI:
1493 index_indicator = SLI4_UNREG_RPI_II_RPI;
1494 if (fc_id != UINT32_MAX) {
1495 unreg_rpi->dp = TRUE;
1496 unreg_rpi->destination_n_port_id = fc_id & 0x00ffffff;
1499 case SLI_RSRC_FCOE_VPI:
1500 index_indicator = SLI4_UNREG_RPI_II_VPI;
1502 case SLI_RSRC_FCOE_VFI:
1503 index_indicator = SLI4_UNREG_RPI_II_VFI;
1505 case SLI_RSRC_FCOE_FCFI:
1506 index_indicator = SLI4_UNREG_RPI_II_FCFI;
1509 ocs_log_test(sli4->os, "unknown type %#x\n", which);
1513 unreg_rpi->ii = index_indicator;
1514 unreg_rpi->index = indicator;
1516 return sizeof(sli4_cmd_unreg_rpi_t);
1521 * @brief Write an UNREG_VFI command to the provided buffer.
1523 * @param sli4 SLI context pointer.
1524 * @param buf Virtual pointer to the destination buffer.
1525 * @param size Buffer size, in bytes.
1526 * @param domain Pointer to the domain object
1527 * @param which Type of unregister, such as domain, FCFI, or everything.
1529 * @return Returns the number of bytes written.
1532 sli_cmd_unreg_vfi(sli4_t *sli4, void *buf, size_t size, ocs_domain_t *domain, uint32_t which)
1534 sli4_cmd_unreg_vfi_t *unreg_vfi = buf;
1536 if (!sli4 || !buf || !domain) {
1540 ocs_memset(buf, 0, size);
1542 unreg_vfi->hdr.command = SLI4_MBOX_COMMAND_UNREG_VFI;
1544 case SLI4_UNREG_TYPE_DOMAIN:
1545 unreg_vfi->index = domain->indicator;
1547 case SLI4_UNREG_TYPE_FCF:
1548 unreg_vfi->index = domain->fcf_indicator;
1550 case SLI4_UNREG_TYPE_ALL:
1551 unreg_vfi->index = UINT16_MAX;
1557 if (SLI4_UNREG_TYPE_DOMAIN != which) {
1558 unreg_vfi->ii = SLI4_UNREG_VFI_II_FCFI;
1561 return sizeof(sli4_cmd_unreg_vfi_t);
1566 * @brief Write an UNREG_VPI command to the provided buffer.
1568 * @param sli4 SLI context pointer.
1569 * @param buf Virtual pointer to the destination buffer.
1570 * @param size Buffer size, in bytes.
1571 * @param indicator Indicator value.
1572 * @param which Type of unregister: port, domain, FCFI, everything
1574 * @return Returns the number of bytes written.
1577 sli_cmd_unreg_vpi(sli4_t *sli4, void *buf, size_t size, uint16_t indicator, uint32_t which)
1579 sli4_cmd_unreg_vpi_t *unreg_vpi = buf;
1581 if (!sli4 || !buf) {
1585 ocs_memset(buf, 0, size);
1587 unreg_vpi->hdr.command = SLI4_MBOX_COMMAND_UNREG_VPI;
1588 unreg_vpi->index = indicator;
1590 case SLI4_UNREG_TYPE_PORT:
1591 unreg_vpi->ii = SLI4_UNREG_VPI_II_VPI;
1593 case SLI4_UNREG_TYPE_DOMAIN:
1594 unreg_vpi->ii = SLI4_UNREG_VPI_II_VFI;
1596 case SLI4_UNREG_TYPE_FCF:
1597 unreg_vpi->ii = SLI4_UNREG_VPI_II_FCFI;
1599 case SLI4_UNREG_TYPE_ALL:
1600 unreg_vpi->index = UINT16_MAX; /* override indicator */
1601 unreg_vpi->ii = SLI4_UNREG_VPI_II_FCFI;
1607 return sizeof(sli4_cmd_unreg_vpi_t);
1613 * @brief Write an CONFIG_AUTO_XFER_RDY command to the provided buffer.
1615 * @param sli4 SLI context pointer.
1616 * @param buf Virtual pointer to the destination buffer.
1617 * @param size Buffer size, in bytes.
1618 * @param max_burst_len if the write FCP_DL is less than this size,
1619 * then the SLI port will generate the auto XFER_RDY.
1621 * @return Returns the number of bytes written.
1624 sli_cmd_config_auto_xfer_rdy(sli4_t *sli4, void *buf, size_t size, uint32_t max_burst_len)
1626 sli4_cmd_config_auto_xfer_rdy_t *req = buf;
1628 if (!sli4 || !buf) {
1632 ocs_memset(buf, 0, size);
1634 req->hdr.command = SLI4_MBOX_COMMAND_CONFIG_AUTO_XFER_RDY;
1635 req->max_burst_len = max_burst_len;
1637 return sizeof(sli4_cmd_config_auto_xfer_rdy_t);
1642 * @brief Write an CONFIG_AUTO_XFER_RDY_HP command to the provided buffer.
1644 * @param sli4 SLI context pointer.
1645 * @param buf Virtual pointer to the destination buffer.
1646 * @param size Buffer size, in bytes.
1647 * @param max_burst_len if the write FCP_DL is less than this size,
1648 * @param esoc enable start offset computation,
1649 * @param block_size block size,
1650 * then the SLI port will generate the auto XFER_RDY.
1652 * @return Returns the number of bytes written.
1655 sli_cmd_config_auto_xfer_rdy_hp(sli4_t *sli4, void *buf, size_t size, uint32_t max_burst_len,
1656 uint32_t esoc, uint32_t block_size )
1658 sli4_cmd_config_auto_xfer_rdy_hp_t *req = buf;
1660 if (!sli4 || !buf) {
1664 ocs_memset(buf, 0, size);
1666 req->hdr.command = SLI4_MBOX_COMMAND_CONFIG_AUTO_XFER_RDY_HP;
1667 req->max_burst_len = max_burst_len;
1669 req->block_size = block_size;
1670 return sizeof(sli4_cmd_config_auto_xfer_rdy_hp_t);
1674 * @brief Write a COMMON_FUNCTION_RESET command.
1676 * @param sli4 SLI context.
1677 * @param buf Destination buffer for the command.
1678 * @param size Buffer size, in bytes.
1680 * @return Returns the number of bytes written.
1683 sli_cmd_common_function_reset(sli4_t *sli4, void *buf, size_t size)
1685 sli4_req_common_function_reset_t *reset = NULL;
1686 uint32_t sli_config_off = 0;
1688 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1689 uint32_t payload_size;
1691 /* Payload length must accommodate both request and response */
1692 payload_size = max(sizeof(sli4_req_common_function_reset_t),
1693 sizeof(sli4_res_common_function_reset_t));
1695 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
1698 reset = (sli4_req_common_function_reset_t *)((uint8_t *)buf + sli_config_off);
1700 reset->hdr.opcode = SLI4_OPC_COMMON_FUNCTION_RESET;
1701 reset->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1703 return(sli_config_off + sizeof(sli4_req_common_function_reset_t));
1707 * @brief Write a COMMON_CREATE_CQ command.
1709 * @param sli4 SLI context.
1710 * @param buf Destination buffer for the command.
1711 * @param size Buffer size, in bytes.
1712 * @param qmem DMA memory for the queue.
1713 * @param eq_id Associated EQ_ID
1714 * @param ignored This parameter carries the ULP which is only used for WQ and RQs
1716 * @note This creates a Version 0 message.
1718 * @return Returns the number of bytes written.
1721 sli_cmd_common_create_cq(sli4_t *sli4, void *buf, size_t size,
1722 ocs_dma_t *qmem, uint16_t eq_id, uint16_t ignored)
1724 sli4_req_common_create_cq_v0_t *cqv0 = NULL;
1725 sli4_req_common_create_cq_v2_t *cqv2 = NULL;
1726 uint32_t sli_config_off = 0;
1729 uint32_t if_type = sli4->if_type;
1730 uint32_t page_bytes = 0;
1731 uint32_t num_pages = 0;
1732 uint32_t cmd_size = 0;
1733 uint32_t page_size = 0;
1736 /* First calculate number of pages and the mailbox cmd length */
1739 case SLI4_IF_TYPE_BE3_SKH_PF:
1740 page_bytes = SLI_PAGE_SIZE;
1741 num_pages = sli_page_count(qmem->size, page_bytes);
1742 cmd_size = sizeof(sli4_req_common_create_cq_v0_t) + (8 * num_pages);
1744 case SLI4_IF_TYPE_LANCER_FC_ETH:
1745 n_cqe = qmem->size / SLI4_CQE_BYTES;
1759 page_bytes = page_size * SLI_PAGE_SIZE;
1760 num_pages = sli_page_count(qmem->size, page_bytes);
1761 cmd_size = sizeof(sli4_req_common_create_cq_v2_t) + (8 * num_pages);
1764 ocs_log_test(sli4->os, "unsupported IF_TYPE %d\n", if_type);
1769 /* now that we have the mailbox command size, we can set SLI_CONFIG fields */
1770 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1771 uint32_t payload_size;
1773 /* Payload length must accommodate both request and response */
1774 payload_size = max((size_t)cmd_size, sizeof(sli4_res_common_create_queue_t));
1776 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
1782 case SLI4_IF_TYPE_BE3_SKH_PF:
1783 cqv0 = (sli4_req_common_create_cq_v0_t *)((uint8_t *)buf + sli_config_off);
1784 cqv0->hdr.opcode = SLI4_OPC_COMMON_CREATE_CQ;
1785 cqv0->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1786 cqv0->hdr.version = 0;
1787 cqv0->hdr.request_length = cmd_size - sizeof(sli4_req_hdr_t);
1789 /* valid values for number of pages: 1, 2, 4 (sec 4.4.3) */
1790 cqv0->num_pages = num_pages;
1791 switch (cqv0->num_pages) {
1793 cqv0->cqecnt = SLI4_CQ_CNT_256;
1796 cqv0->cqecnt = SLI4_CQ_CNT_512;
1799 cqv0->cqecnt = SLI4_CQ_CNT_1024;
1802 ocs_log_test(sli4->os, "num_pages %d not valid\n", cqv0->num_pages);
1807 /* TODO cq->nodelay = ???; */
1808 /* TODO cq->clswm = ???; */
1810 cqv0->eq_id = eq_id;
1812 for (p = 0, addr = qmem->phys;
1813 p < cqv0->num_pages;
1814 p++, addr += page_bytes) {
1815 cqv0->page_physical_address[p].low = ocs_addr32_lo(addr);
1816 cqv0->page_physical_address[p].high = ocs_addr32_hi(addr);
1820 case SLI4_IF_TYPE_LANCER_FC_ETH:
1822 cqv2 = (sli4_req_common_create_cq_v2_t *)((uint8_t *)buf + sli_config_off);
1823 cqv2->hdr.opcode = SLI4_OPC_COMMON_CREATE_CQ;
1824 cqv2->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1825 cqv2->hdr.version = 2;
1826 cqv2->hdr.request_length = cmd_size - sizeof(sli4_req_hdr_t);
1828 cqv2->page_size = page_size;
1830 /* valid values for number of pages: 1, 2, 4, 8 (sec 4.4.3) */
1831 cqv2->num_pages = num_pages;
1832 if (!cqv2->num_pages || (cqv2->num_pages > SLI4_COMMON_CREATE_CQ_V2_MAX_PAGES)) {
1836 switch (cqv2->num_pages) {
1838 cqv2->cqecnt = SLI4_CQ_CNT_256;
1841 cqv2->cqecnt = SLI4_CQ_CNT_512;
1844 cqv2->cqecnt = SLI4_CQ_CNT_1024;
1847 cqv2->cqecnt = SLI4_CQ_CNT_LARGE;
1848 cqv2->cqe_count = n_cqe;
1851 ocs_log_test(sli4->os, "num_pages %d not valid\n", cqv2->num_pages);
1857 /* TODO cq->nodelay = ???; */
1858 /* TODO cq->clswm = ???; */
1860 cqv2->eq_id = eq_id;
1862 for (p = 0, addr = qmem->phys;
1863 p < cqv2->num_pages;
1864 p++, addr += page_bytes) {
1865 cqv2->page_physical_address[p].low = ocs_addr32_lo(addr);
1866 cqv2->page_physical_address[p].high = ocs_addr32_hi(addr);
1872 return (sli_config_off + cmd_size);
1876 * @brief Write a COMMON_DESTROY_CQ command.
1878 * @param sli4 SLI context.
1879 * @param buf Destination buffer for the command.
1880 * @param size Buffer size, in bytes.
1881 * @param cq_id CQ ID
1883 * @note This creates a Version 0 message.
1885 * @return Returns the number of bytes written.
1888 sli_cmd_common_destroy_cq(sli4_t *sli4, void *buf, size_t size, uint16_t cq_id)
1890 sli4_req_common_destroy_cq_t *cq = NULL;
1891 uint32_t sli_config_off = 0;
1893 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1894 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
1895 /* Payload length must accommodate both request and response */
1896 max(sizeof(sli4_req_common_destroy_cq_t),
1897 sizeof(sli4_res_hdr_t)),
1900 cq = (sli4_req_common_destroy_cq_t *)((uint8_t *)buf + sli_config_off);
1902 cq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_CQ;
1903 cq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1904 cq->hdr.request_length = sizeof(sli4_req_common_destroy_cq_t) -
1905 sizeof(sli4_req_hdr_t);
1908 return(sli_config_off + sizeof(sli4_req_common_destroy_cq_t));
1912 * @brief Write a COMMON_MODIFY_EQ_DELAY command.
1914 * @param sli4 SLI context.
1915 * @param buf Destination buffer for the command.
1916 * @param size Buffer size, in bytes.
1917 * @param q Queue object array.
1918 * @param num_q Queue object array count.
1919 * @param shift Phase shift for staggering interrupts.
1920 * @param delay_mult Delay multiplier for limiting interrupt frequency.
1922 * @return Returns the number of bytes written.
1925 sli_cmd_common_modify_eq_delay(sli4_t *sli4, void *buf, size_t size, sli4_queue_t *q, int num_q, uint32_t shift,
1926 uint32_t delay_mult)
1928 sli4_req_common_modify_eq_delay_t *modify_delay = NULL;
1929 uint32_t sli_config_off = 0;
1932 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1933 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
1934 /* Payload length must accommodate both request and response */
1935 max(sizeof(sli4_req_common_modify_eq_delay_t), sizeof(sli4_res_hdr_t)),
1939 modify_delay = (sli4_req_common_modify_eq_delay_t *)((uint8_t *)buf + sli_config_off);
1941 modify_delay->hdr.opcode = SLI4_OPC_COMMON_MODIFY_EQ_DELAY;
1942 modify_delay->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1943 modify_delay->hdr.request_length = sizeof(sli4_req_common_modify_eq_delay_t) -
1944 sizeof(sli4_req_hdr_t);
1946 modify_delay->num_eq = num_q;
1948 for (i = 0; i<num_q; i++) {
1949 modify_delay->eq_delay_record[i].eq_id = q[i].id;
1950 modify_delay->eq_delay_record[i].phase = shift;
1951 modify_delay->eq_delay_record[i].delay_multiplier = delay_mult;
1954 return(sli_config_off + sizeof(sli4_req_common_modify_eq_delay_t));
1958 * @brief Write a COMMON_CREATE_EQ command.
1960 * @param sli4 SLI context.
1961 * @param buf Destination buffer for the command.
1962 * @param size Buffer size, in bytes.
1963 * @param qmem DMA memory for the queue.
1964 * @param ignored1 Ignored (used for consistency among queue creation functions).
1965 * @param ignored2 Ignored (used for consistency among queue creation functions).
1967 * @note Other queue creation routines use the last parameter to pass in
1968 * the associated Q_ID and ULP. EQ doesn't have an associated queue or ULP,
1969 * so these parameters are ignored
1971 * @note This creates a Version 0 message
1973 * @return Returns the number of bytes written.
1976 sli_cmd_common_create_eq(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *qmem,
1977 uint16_t ignored1, uint16_t ignored2)
1979 sli4_req_common_create_eq_t *eq = NULL;
1980 uint32_t sli_config_off = 0;
1984 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1985 uint32_t payload_size;
1987 /* Payload length must accommodate both request and response */
1988 payload_size = max(sizeof(sli4_req_common_create_eq_t),
1989 sizeof(sli4_res_common_create_queue_t));
1991 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
1994 eq = (sli4_req_common_create_eq_t *)((uint8_t *)buf + sli_config_off);
1996 eq->hdr.opcode = SLI4_OPC_COMMON_CREATE_EQ;
1997 eq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1998 eq->hdr.request_length = sizeof(sli4_req_common_create_eq_t) -
1999 sizeof(sli4_req_hdr_t);
2000 /* valid values for number of pages: 1, 2, 4 (sec 4.4.3) */
2001 eq->num_pages = qmem->size / SLI_PAGE_SIZE;
2002 switch (eq->num_pages) {
2004 eq->eqesz = SLI4_EQE_SIZE_4;
2005 eq->count = SLI4_EQ_CNT_1024;
2008 eq->eqesz = SLI4_EQE_SIZE_4;
2009 eq->count = SLI4_EQ_CNT_2048;
2012 eq->eqesz = SLI4_EQE_SIZE_4;
2013 eq->count = SLI4_EQ_CNT_4096;
2016 ocs_log_test(sli4->os, "num_pages %d not valid\n", eq->num_pages);
2021 eq->delay_multiplier = 32;
2023 for (p = 0, addr = qmem->phys;
2025 p++, addr += SLI_PAGE_SIZE) {
2026 eq->page_address[p].low = ocs_addr32_lo(addr);
2027 eq->page_address[p].high = ocs_addr32_hi(addr);
2030 return(sli_config_off + sizeof(sli4_req_common_create_eq_t));
2035 * @brief Write a COMMON_DESTROY_EQ command.
2037 * @param sli4 SLI context.
2038 * @param buf Destination buffer for the command.
2039 * @param size Buffer size, in bytes.
2040 * @param eq_id Queue ID to destroy.
2042 * @note Other queue creation routines use the last parameter to pass in
2043 * the associated Q_ID. EQ doesn't have an associated queue so this
2044 * parameter is ignored.
2046 * @note This creates a Version 0 message.
2048 * @return Returns the number of bytes written.
2051 sli_cmd_common_destroy_eq(sli4_t *sli4, void *buf, size_t size, uint16_t eq_id)
2053 sli4_req_common_destroy_eq_t *eq = NULL;
2054 uint32_t sli_config_off = 0;
2056 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2057 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2058 /* Payload length must accommodate both request and response */
2059 max(sizeof(sli4_req_common_destroy_eq_t),
2060 sizeof(sli4_res_hdr_t)),
2063 eq = (sli4_req_common_destroy_eq_t *)((uint8_t *)buf + sli_config_off);
2065 eq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_EQ;
2066 eq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2067 eq->hdr.request_length = sizeof(sli4_req_common_destroy_eq_t) -
2068 sizeof(sli4_req_hdr_t);
2072 return(sli_config_off + sizeof(sli4_req_common_destroy_eq_t));
2076 * @brief Write a LOWLEVEL_SET_WATCHDOG command.
2078 * @param sli4 SLI context.
2079 * @param buf Destination buffer for the command.
2080 * @param size Buffer size, in bytes.
2081 * @param timeout watchdog timer timeout in seconds
2086 sli4_cmd_lowlevel_set_watchdog(sli4_t *sli4, void *buf, size_t size, uint16_t timeout)
2089 sli4_req_lowlevel_set_watchdog_t *req = NULL;
2090 uint32_t sli_config_off = 0;
2092 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2093 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2094 /* Payload length must accommodate both request and response */
2095 max(sizeof(sli4_req_lowlevel_set_watchdog_t),
2096 sizeof(sli4_res_lowlevel_set_watchdog_t)),
2099 req = (sli4_req_lowlevel_set_watchdog_t *)((uint8_t *)buf + sli_config_off);
2101 req->hdr.opcode = SLI4_OPC_LOWLEVEL_SET_WATCHDOG;
2102 req->hdr.subsystem = SLI4_SUBSYSTEM_LOWLEVEL;
2103 req->hdr.request_length = sizeof(sli4_req_lowlevel_set_watchdog_t) - sizeof(sli4_req_hdr_t);
2104 req->watchdog_timeout = timeout;
2110 sli_cmd_common_get_cntl_attributes(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2112 sli4_req_hdr_t *hdr = NULL;
2113 uint32_t sli_config_off = 0;
2115 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2116 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2117 sizeof(sli4_req_hdr_t),
2125 ocs_memset(dma->virt, 0, dma->size);
2129 hdr->opcode = SLI4_OPC_COMMON_GET_CNTL_ATTRIBUTES;
2130 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2131 hdr->request_length = dma->size;
2133 return(sli_config_off + sizeof(sli4_req_hdr_t));
2137 * @brief Write a COMMON_GET_CNTL_ADDL_ATTRIBUTES command.
2139 * @param sli4 SLI context.
2140 * @param buf Destination buffer for the command.
2141 * @param size Buffer size, in bytes.
2142 * @param dma DMA structure from which the data will be copied.
2144 * @note This creates a Version 0 message.
2146 * @return Returns the number of bytes written.
2149 sli_cmd_common_get_cntl_addl_attributes(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2151 sli4_req_hdr_t *hdr = NULL;
2152 uint32_t sli_config_off = 0;
2154 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2155 sli_config_off = sli_cmd_sli_config(sli4, buf, size, sizeof(sli4_req_hdr_t), dma);
2162 ocs_memset(dma->virt, 0, dma->size);
2166 hdr->opcode = SLI4_OPC_COMMON_GET_CNTL_ADDL_ATTRIBUTES;
2167 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2168 hdr->request_length = dma->size;
2170 return(sli_config_off + sizeof(sli4_req_hdr_t));
2174 * @brief Write a COMMON_CREATE_MQ_EXT command.
2176 * @param sli4 SLI context.
2177 * @param buf Destination buffer for the command.
2178 * @param size Buffer size, in bytes.
2179 * @param qmem DMA memory for the queue.
2180 * @param cq_id Associated CQ_ID.
2181 * @param ignored This parameter carries the ULP which is only used for WQ and RQs
2183 * @note This creates a Version 0 message.
2185 * @return Returns the number of bytes written.
2188 sli_cmd_common_create_mq_ext(sli4_t *sli4, void *buf, size_t size,
2189 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ignored)
2191 sli4_req_common_create_mq_ext_t *mq = NULL;
2192 uint32_t sli_config_off = 0;
2196 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2197 uint32_t payload_size;
2199 /* Payload length must accommodate both request and response */
2200 payload_size = max(sizeof(sli4_req_common_create_mq_ext_t),
2201 sizeof(sli4_res_common_create_queue_t));
2203 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
2206 mq = (sli4_req_common_create_mq_ext_t *)((uint8_t *)buf + sli_config_off);
2208 mq->hdr.opcode = SLI4_OPC_COMMON_CREATE_MQ_EXT;
2209 mq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2210 mq->hdr.request_length = sizeof(sli4_req_common_create_mq_ext_t) -
2211 sizeof(sli4_req_hdr_t);
2212 /* valid values for number of pages: 1, 2, 4, 8 (sec 4.4.12) */
2213 mq->num_pages = qmem->size / SLI_PAGE_SIZE;
2214 switch (mq->num_pages) {
2216 mq->ring_size = SLI4_MQE_SIZE_16;
2219 mq->ring_size = SLI4_MQE_SIZE_32;
2222 mq->ring_size = SLI4_MQE_SIZE_64;
2225 mq->ring_size = SLI4_MQE_SIZE_128;
2228 ocs_log_test(sli4->os, "num_pages %d not valid\n", mq->num_pages);
2232 /* TODO break this down by sli4->config.topology */
2233 mq->async_event_bitmap = SLI4_ASYNC_EVT_FC_FCOE;
2235 if (sli4->config.mq_create_version) {
2236 mq->cq_id_v1 = cq_id;
2237 mq->hdr.version = 1;
2240 mq->cq_id_v0 = cq_id;
2244 for (p = 0, addr = qmem->phys;
2246 p++, addr += SLI_PAGE_SIZE) {
2247 mq->page_physical_address[p].low = ocs_addr32_lo(addr);
2248 mq->page_physical_address[p].high = ocs_addr32_hi(addr);
2251 return(sli_config_off + sizeof(sli4_req_common_create_mq_ext_t));
2255 * @brief Write a COMMON_DESTROY_MQ command.
2257 * @param sli4 SLI context.
2258 * @param buf Destination buffer for the command.
2259 * @param size Buffer size, in bytes.
2260 * @param mq_id MQ ID
2262 * @note This creates a Version 0 message.
2264 * @return Returns the number of bytes written.
2267 sli_cmd_common_destroy_mq(sli4_t *sli4, void *buf, size_t size, uint16_t mq_id)
2269 sli4_req_common_destroy_mq_t *mq = NULL;
2270 uint32_t sli_config_off = 0;
2272 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2273 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2274 /* Payload length must accommodate both request and response */
2275 max(sizeof(sli4_req_common_destroy_mq_t),
2276 sizeof(sli4_res_hdr_t)),
2279 mq = (sli4_req_common_destroy_mq_t *)((uint8_t *)buf + sli_config_off);
2281 mq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_MQ;
2282 mq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2283 mq->hdr.request_length = sizeof(sli4_req_common_destroy_mq_t) -
2284 sizeof(sli4_req_hdr_t);
2288 return(sli_config_off + sizeof(sli4_req_common_destroy_mq_t));
2293 * @brief Write a COMMON_NOP command
2295 * @param sli4 SLI context.
2296 * @param buf Destination buffer for the command.
2297 * @param size Buffer size, in bytes.
2298 * @param context NOP context value (passed to response, except on FC/FCoE).
2300 * @return Returns the number of bytes written.
2303 sli_cmd_common_nop(sli4_t *sli4, void *buf, size_t size, uint64_t context)
2305 sli4_req_common_nop_t *nop = NULL;
2306 uint32_t sli_config_off = 0;
2308 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2309 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2310 /* Payload length must accommodate both request and response */
2311 max(sizeof(sli4_req_common_nop_t), sizeof(sli4_res_common_nop_t)),
2315 nop = (sli4_req_common_nop_t *)((uint8_t *)buf + sli_config_off);
2317 nop->hdr.opcode = SLI4_OPC_COMMON_NOP;
2318 nop->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2319 nop->hdr.request_length = 8;
2321 ocs_memcpy(&nop->context, &context, sizeof(context));
2323 return(sli_config_off + sizeof(sli4_req_common_nop_t));
2328 * @brief Write a COMMON_GET_RESOURCE_EXTENT_INFO command.
2330 * @param sli4 SLI context.
2331 * @param buf Destination buffer for the command.
2332 * @param size Buffer size, in bytes.
2333 * @param rtype Resource type (for example, XRI, VFI, VPI, and RPI).
2335 * @return Returns the number of bytes written.
2338 sli_cmd_common_get_resource_extent_info(sli4_t *sli4, void *buf, size_t size, uint16_t rtype)
2340 sli4_req_common_get_resource_extent_info_t *extent = NULL;
2341 uint32_t sli_config_off = 0;
2343 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2344 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2345 sizeof(sli4_req_common_get_resource_extent_info_t),
2349 extent = (sli4_req_common_get_resource_extent_info_t *)((uint8_t *)buf + sli_config_off);
2351 extent->hdr.opcode = SLI4_OPC_COMMON_GET_RESOURCE_EXTENT_INFO;
2352 extent->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2353 extent->hdr.request_length = 4;
2355 extent->resource_type = rtype;
2357 return(sli_config_off + sizeof(sli4_req_common_get_resource_extent_info_t));
2362 * @brief Write a COMMON_GET_SLI4_PARAMETERS command.
2364 * @param sli4 SLI context.
2365 * @param buf Destination buffer for the command.
2366 * @param size Buffer size, in bytes.
2368 * @return Returns the number of bytes written.
2371 sli_cmd_common_get_sli4_parameters(sli4_t *sli4, void *buf, size_t size)
2373 sli4_req_hdr_t *hdr = NULL;
2374 uint32_t sli_config_off = 0;
2376 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2377 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2378 sizeof(sli4_res_common_get_sli4_parameters_t),
2382 hdr = (sli4_req_hdr_t *)((uint8_t *)buf + sli_config_off);
2384 hdr->opcode = SLI4_OPC_COMMON_GET_SLI4_PARAMETERS;
2385 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2386 hdr->request_length = 0x50;
2388 return(sli_config_off + sizeof(sli4_req_hdr_t));
2392 * @brief Write a COMMON_QUERY_FW_CONFIG command to the provided buffer.
2394 * @param sli4 SLI context pointer.
2395 * @param buf Virtual pointer to destination buffer.
2396 * @param size Buffer size in bytes.
2398 * @return Returns the number of bytes written
2401 sli_cmd_common_query_fw_config(sli4_t *sli4, void *buf, size_t size)
2403 sli4_req_common_query_fw_config_t *fw_config;
2404 uint32_t sli_config_off = 0;
2405 uint32_t payload_size;
2407 /* Payload length must accommodate both request and response */
2408 payload_size = max(sizeof(sli4_req_common_query_fw_config_t),
2409 sizeof(sli4_res_common_query_fw_config_t));
2411 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2412 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2417 fw_config = (sli4_req_common_query_fw_config_t*)((uint8_t*)buf + sli_config_off);
2418 fw_config->hdr.opcode = SLI4_OPC_COMMON_QUERY_FW_CONFIG;
2419 fw_config->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2420 fw_config->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2421 return sli_config_off + sizeof(sli4_req_common_query_fw_config_t);
2425 * @brief Write a COMMON_GET_PORT_NAME command to the provided buffer.
2427 * @param sli4 SLI context pointer.
2428 * @param buf Virtual pointer to destination buffer.
2429 * @param size Buffer size in bytes.
2431 * @note Function supports both version 0 and 1 forms of this command via
2434 * @return Returns the number of bytes written.
2437 sli_cmd_common_get_port_name(sli4_t *sli4, void *buf, size_t size)
2439 sli4_req_common_get_port_name_t *port_name;
2440 uint32_t sli_config_off = 0;
2441 uint32_t payload_size;
2442 uint8_t version = 0;
2445 /* Select command version according to IF_TYPE */
2446 switch (sli4->if_type) {
2447 case SLI4_IF_TYPE_BE3_SKH_PF:
2448 case SLI4_IF_TYPE_BE3_SKH_VF:
2451 case SLI4_IF_TYPE_LANCER_FC_ETH:
2452 case SLI4_IF_TYPE_LANCER_RDMA:
2456 ocs_log_test(sli4->os, "unsupported IF_TYPE %d\n", sli4->if_type);
2460 /* Payload length must accommodate both request and response */
2461 payload_size = max(sizeof(sli4_req_common_get_port_name_t),
2462 sizeof(sli4_res_common_get_port_name_t));
2464 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2465 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2472 port_name = (sli4_req_common_get_port_name_t *)((uint8_t *)buf + sli_config_off);
2474 port_name->hdr.opcode = SLI4_OPC_COMMON_GET_PORT_NAME;
2475 port_name->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2476 port_name->hdr.request_length = sizeof(sli4_req_hdr_t) + (version * sizeof(uint32_t));
2477 port_name->hdr.version = version;
2479 /* Set the port type value (ethernet=0, FC=1) for V1 commands */
2484 return sli_config_off + port_name->hdr.request_length;
2490 * @brief Write a COMMON_WRITE_OBJECT command.
2492 * @param sli4 SLI context.
2493 * @param buf Destination buffer for the command.
2494 * @param size Buffer size, in bytes.
2495 * @param noc True if the object should be written but not committed to flash.
2496 * @param eof True if this is the last write for this object.
2497 * @param desired_write_length Number of bytes of data to write to the object.
2498 * @param offset Offset, in bytes, from the start of the object.
2499 * @param object_name Name of the object to write.
2500 * @param dma DMA structure from which the data will be copied.
2502 * @return Returns the number of bytes written.
2505 sli_cmd_common_write_object(sli4_t *sli4, void *buf, size_t size,
2506 uint16_t noc, uint16_t eof, uint32_t desired_write_length,
2511 sli4_req_common_write_object_t *wr_obj = NULL;
2512 uint32_t sli_config_off = 0;
2513 sli4_bde_t *host_buffer;
2515 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2516 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2517 sizeof (sli4_req_common_write_object_t) + sizeof (sli4_bde_t),
2521 wr_obj = (sli4_req_common_write_object_t *)((uint8_t *)buf + sli_config_off);
2523 wr_obj->hdr.opcode = SLI4_OPC_COMMON_WRITE_OBJECT;
2524 wr_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2525 wr_obj->hdr.request_length = sizeof(*wr_obj) - 4*sizeof(uint32_t) + sizeof(sli4_bde_t);
2526 wr_obj->hdr.timeout = 0;
2527 wr_obj->hdr.version = 0;
2531 wr_obj->desired_write_length = desired_write_length;
2532 wr_obj->write_offset = offset;
2533 ocs_strncpy(wr_obj->object_name, object_name, sizeof(wr_obj->object_name));
2534 wr_obj->host_buffer_descriptor_count = 1;
2536 host_buffer = (sli4_bde_t *)wr_obj->host_buffer_descriptor;
2538 /* Setup to transfer xfer_size bytes to device */
2539 host_buffer->bde_type = SLI4_BDE_TYPE_BDE_64;
2540 host_buffer->buffer_length = desired_write_length;
2541 host_buffer->u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
2542 host_buffer->u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
2545 return(sli_config_off + sizeof(sli4_req_common_write_object_t) + sizeof (sli4_bde_t));
2551 * @brief Write a COMMON_DELETE_OBJECT command.
2553 * @param sli4 SLI context.
2554 * @param buf Destination buffer for the command.
2555 * @param size Buffer size, in bytes.
2556 * @param object_name Name of the object to write.
2558 * @return Returns the number of bytes written.
2561 sli_cmd_common_delete_object(sli4_t *sli4, void *buf, size_t size,
2564 sli4_req_common_delete_object_t *del_obj = NULL;
2565 uint32_t sli_config_off = 0;
2567 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2568 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2569 sizeof (sli4_req_common_delete_object_t),
2573 del_obj = (sli4_req_common_delete_object_t *)((uint8_t *)buf + sli_config_off);
2575 del_obj->hdr.opcode = SLI4_OPC_COMMON_DELETE_OBJECT;
2576 del_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2577 del_obj->hdr.request_length = sizeof(*del_obj);
2578 del_obj->hdr.timeout = 0;
2579 del_obj->hdr.version = 0;
2581 ocs_strncpy(del_obj->object_name, object_name, sizeof(del_obj->object_name));
2582 return(sli_config_off + sizeof(sli4_req_common_delete_object_t));
2587 * @brief Write a COMMON_READ_OBJECT command.
2589 * @param sli4 SLI context.
2590 * @param buf Destination buffer for the command.
2591 * @param size Buffer size, in bytes.
2592 * @param desired_read_length Number of bytes of data to read from the object.
2593 * @param offset Offset, in bytes, from the start of the object.
2594 * @param object_name Name of the object to read.
2595 * @param dma DMA structure from which the data will be copied.
2597 * @return Returns the number of bytes written.
2600 sli_cmd_common_read_object(sli4_t *sli4, void *buf, size_t size,
2601 uint32_t desired_read_length,
2606 sli4_req_common_read_object_t *rd_obj = NULL;
2607 uint32_t sli_config_off = 0;
2608 sli4_bde_t *host_buffer;
2610 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2611 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2612 sizeof (sli4_req_common_read_object_t) + sizeof (sli4_bde_t),
2616 rd_obj = (sli4_req_common_read_object_t *)((uint8_t *)buf + sli_config_off);
2618 rd_obj->hdr.opcode = SLI4_OPC_COMMON_READ_OBJECT;
2619 rd_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2620 rd_obj->hdr.request_length = sizeof(*rd_obj) - 4*sizeof(uint32_t) + sizeof(sli4_bde_t);
2621 rd_obj->hdr.timeout = 0;
2622 rd_obj->hdr.version = 0;
2624 rd_obj->desired_read_length = desired_read_length;
2625 rd_obj->read_offset = offset;
2626 ocs_strncpy(rd_obj->object_name, object_name, sizeof(rd_obj->object_name));
2627 rd_obj->host_buffer_descriptor_count = 1;
2629 host_buffer = (sli4_bde_t *)rd_obj->host_buffer_descriptor;
2631 /* Setup to transfer xfer_size bytes to device */
2632 host_buffer->bde_type = SLI4_BDE_TYPE_BDE_64;
2633 host_buffer->buffer_length = desired_read_length;
2635 host_buffer->u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
2636 host_buffer->u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
2638 host_buffer->u.data.buffer_address_low = 0;
2639 host_buffer->u.data.buffer_address_high = 0;
2643 return(sli_config_off + sizeof(sli4_req_common_read_object_t) + sizeof (sli4_bde_t));
2648 * @brief Write a DMTF_EXEC_CLP_CMD command.
2650 * @param sli4 SLI context.
2651 * @param buf Destination buffer for the command.
2652 * @param size Buffer size, in bytes.
2653 * @param cmd DMA structure that describes the buffer for the command.
2654 * @param resp DMA structure that describes the buffer for the response.
2656 * @return Returns the number of bytes written.
2659 sli_cmd_dmtf_exec_clp_cmd(sli4_t *sli4, void *buf, size_t size,
2663 sli4_req_dmtf_exec_clp_cmd_t *clp_cmd = NULL;
2664 uint32_t sli_config_off = 0;
2666 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2667 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2668 sizeof (sli4_req_dmtf_exec_clp_cmd_t),
2672 clp_cmd = (sli4_req_dmtf_exec_clp_cmd_t*)((uint8_t *)buf + sli_config_off);
2674 clp_cmd->hdr.opcode = SLI4_OPC_DMTF_EXEC_CLP_CMD;
2675 clp_cmd->hdr.subsystem = SLI4_SUBSYSTEM_DMTF;
2676 clp_cmd->hdr.request_length = sizeof(sli4_req_dmtf_exec_clp_cmd_t) -
2677 sizeof(sli4_req_hdr_t);
2678 clp_cmd->hdr.timeout = 0;
2679 clp_cmd->hdr.version = 0;
2680 clp_cmd->cmd_buf_length = cmd->size;
2681 clp_cmd->cmd_buf_addr_low = ocs_addr32_lo(cmd->phys);
2682 clp_cmd->cmd_buf_addr_high = ocs_addr32_hi(cmd->phys);
2683 clp_cmd->resp_buf_length = resp->size;
2684 clp_cmd->resp_buf_addr_low = ocs_addr32_lo(resp->phys);
2685 clp_cmd->resp_buf_addr_high = ocs_addr32_hi(resp->phys);
2687 return(sli_config_off + sizeof(sli4_req_dmtf_exec_clp_cmd_t));
2692 * @brief Write a COMMON_SET_DUMP_LOCATION command.
2694 * @param sli4 SLI context.
2695 * @param buf Destination buffer for the command.
2696 * @param size Buffer size, in bytes.
2697 * @param query Zero to set dump location, non-zero to query dump size
2698 * @param is_buffer_list Set to one if the buffer is a set of buffer descriptors or
2699 * set to 0 if the buffer is a contiguous dump area.
2700 * @param buffer DMA structure to which the dump will be copied.
2702 * @return Returns the number of bytes written.
2705 sli_cmd_common_set_dump_location(sli4_t *sli4, void *buf, size_t size,
2706 uint8_t query, uint8_t is_buffer_list,
2707 ocs_dma_t *buffer, uint8_t fdb)
2709 sli4_req_common_set_dump_location_t *set_dump_loc = NULL;
2710 uint32_t sli_config_off = 0;
2712 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2713 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2714 sizeof (sli4_req_common_set_dump_location_t),
2718 set_dump_loc = (sli4_req_common_set_dump_location_t *)((uint8_t *)buf + sli_config_off);
2720 set_dump_loc->hdr.opcode = SLI4_OPC_COMMON_SET_DUMP_LOCATION;
2721 set_dump_loc->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2722 set_dump_loc->hdr.request_length = sizeof(sli4_req_common_set_dump_location_t) - sizeof(sli4_req_hdr_t);
2723 set_dump_loc->hdr.timeout = 0;
2724 set_dump_loc->hdr.version = 0;
2726 set_dump_loc->blp = is_buffer_list;
2727 set_dump_loc->qry = query;
2728 set_dump_loc->fdb = fdb;
2731 set_dump_loc->buf_addr_low = ocs_addr32_lo(buffer->phys);
2732 set_dump_loc->buf_addr_high = ocs_addr32_hi(buffer->phys);
2733 set_dump_loc->buffer_length = buffer->len;
2735 set_dump_loc->buf_addr_low = 0;
2736 set_dump_loc->buf_addr_high = 0;
2737 set_dump_loc->buffer_length = 0;
2740 return(sli_config_off + sizeof(sli4_req_common_set_dump_location_t));
2746 * @brief Write a COMMON_SET_FEATURES command.
2748 * @param sli4 SLI context.
2749 * @param buf Destination buffer for the command.
2750 * @param size Buffer size, in bytes.
2751 * @param feature Feature to set.
2752 * @param param_len Length of the parameter (must be a multiple of 4 bytes).
2753 * @param parameter Pointer to the parameter value.
2755 * @return Returns the number of bytes written.
2758 sli_cmd_common_set_features(sli4_t *sli4, void *buf, size_t size,
2763 sli4_req_common_set_features_t *cmd = NULL;
2764 uint32_t sli_config_off = 0;
2766 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2767 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2768 sizeof (sli4_req_common_set_features_t),
2772 cmd = (sli4_req_common_set_features_t *)((uint8_t *)buf + sli_config_off);
2774 cmd->hdr.opcode = SLI4_OPC_COMMON_SET_FEATURES;
2775 cmd->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2776 cmd->hdr.request_length = sizeof(sli4_req_common_set_features_t) - sizeof(sli4_req_hdr_t);
2777 cmd->hdr.timeout = 0;
2778 cmd->hdr.version = 0;
2780 cmd->feature = feature;
2781 cmd->param_len = param_len;
2782 ocs_memcpy(cmd->params, parameter, param_len);
2784 return(sli_config_off + sizeof(sli4_req_common_set_features_t));
2789 * @brief Write a COMMON_COMMON_GET_PROFILE_CONFIG command.
2791 * @param sli4 SLI context.
2792 * @param buf Destination buffer for the command.
2793 * @param size Buffer size in bytes.
2794 * @param dma DMA capable memory used to retrieve profile.
2796 * @return Returns the number of bytes written.
2799 sli_cmd_common_get_profile_config(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2801 sli4_req_common_get_profile_config_t *req = NULL;
2802 uint32_t sli_config_off = 0;
2803 uint32_t payload_size;
2805 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2806 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2807 sizeof (sli4_req_common_get_profile_config_t),
2813 ocs_memset(req, 0, dma->size);
2814 payload_size = dma->size;
2816 req = (sli4_req_common_get_profile_config_t *)((uint8_t *)buf + sli_config_off);
2817 payload_size = sizeof(sli4_req_common_get_profile_config_t);
2820 req->hdr.opcode = SLI4_OPC_COMMON_GET_PROFILE_CONFIG;
2821 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2822 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2823 req->hdr.version = 1;
2825 return(sli_config_off + sizeof(sli4_req_common_get_profile_config_t));
2830 * @brief Write a COMMON_COMMON_SET_PROFILE_CONFIG command.
2832 * @param sli4 SLI context.
2833 * @param buf Destination buffer for the command.
2834 * @param size Buffer size, in bytes.
2835 * @param dma DMA capable memory containing profile.
2836 * @param profile_id Profile ID to configure.
2837 * @param descriptor_count Number of descriptors in DMA buffer.
2838 * @param isap Implicit Set Active Profile value to use.
2840 * @return Returns the number of bytes written.
2843 sli_cmd_common_set_profile_config(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma,
2844 uint8_t profile_id, uint32_t descriptor_count, uint8_t isap)
2846 sli4_req_common_set_profile_config_t *req = NULL;
2847 uint32_t cmd_off = 0;
2848 uint32_t payload_size;
2850 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2851 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2852 sizeof (sli4_req_common_set_profile_config_t),
2858 ocs_memset(req, 0, dma->size);
2859 payload_size = dma->size;
2861 req = (sli4_req_common_set_profile_config_t *)((uint8_t *)buf + cmd_off);
2862 payload_size = sizeof(sli4_req_common_set_profile_config_t);
2865 req->hdr.opcode = SLI4_OPC_COMMON_SET_PROFILE_CONFIG;
2866 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2867 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2868 req->hdr.version = 1;
2869 req->profile_id = profile_id;
2870 req->desc_count = descriptor_count;
2873 return(cmd_off + sizeof(sli4_req_common_set_profile_config_t));
2878 * @brief Write a COMMON_COMMON_GET_PROFILE_LIST command.
2880 * @param sli4 SLI context.
2881 * @param buf Destination buffer for the command.
2882 * @param size Buffer size in bytes.
2883 * @param start_profile_index First profile index to return.
2884 * @param dma Buffer into which the list will be written.
2886 * @return Returns the number of bytes written.
2889 sli_cmd_common_get_profile_list(sli4_t *sli4, void *buf, size_t size,
2890 uint32_t start_profile_index, ocs_dma_t *dma)
2892 sli4_req_common_get_profile_list_t *req = NULL;
2893 uint32_t cmd_off = 0;
2894 uint32_t payload_size;
2896 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2897 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2898 sizeof (sli4_req_common_get_profile_list_t),
2904 ocs_memset(req, 0, dma->size);
2905 payload_size = dma->size;
2907 req = (sli4_req_common_get_profile_list_t *)((uint8_t *)buf + cmd_off);
2908 payload_size = sizeof(sli4_req_common_get_profile_list_t);
2911 req->hdr.opcode = SLI4_OPC_COMMON_GET_PROFILE_LIST;
2912 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2913 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2914 req->hdr.version = 0;
2916 req->start_profile_index = start_profile_index;
2918 return(cmd_off + sizeof(sli4_req_common_get_profile_list_t));
2923 * @brief Write a COMMON_COMMON_GET_ACTIVE_PROFILE command.
2925 * @param sli4 SLI context.
2926 * @param buf Destination buffer for the command.
2927 * @param size Buffer size in bytes.
2929 * @return Returns the number of bytes written.
2932 sli_cmd_common_get_active_profile(sli4_t *sli4, void *buf, size_t size)
2934 sli4_req_common_get_active_profile_t *req = NULL;
2935 uint32_t cmd_off = 0;
2936 uint32_t payload_size;
2938 /* Payload length must accommodate both request and response */
2939 payload_size = max(sizeof(sli4_req_common_get_active_profile_t),
2940 sizeof(sli4_res_common_get_active_profile_t));
2942 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2943 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2948 req = (sli4_req_common_get_active_profile_t *)
2949 ((uint8_t*)buf + cmd_off);
2951 req->hdr.opcode = SLI4_OPC_COMMON_GET_ACTIVE_PROFILE;
2952 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2953 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2954 req->hdr.version = 0;
2956 return(cmd_off + sizeof(sli4_req_common_get_active_profile_t));
2961 * @brief Write a COMMON_COMMON_SET_ACTIVE_PROFILE command.
2963 * @param sli4 SLI context.
2964 * @param buf Destination buffer for the command.
2965 * @param size Buffer size in bytes.
2966 * @param fd If non-zero, set profile to factory default.
2967 * @param active_profile_id ID of new active profile.
2969 * @return Returns the number of bytes written.
2972 sli_cmd_common_set_active_profile(sli4_t *sli4, void *buf, size_t size,
2973 uint32_t fd, uint32_t active_profile_id)
2975 sli4_req_common_set_active_profile_t *req = NULL;
2976 uint32_t cmd_off = 0;
2977 uint32_t payload_size;
2979 /* Payload length must accommodate both request and response */
2980 payload_size = max(sizeof(sli4_req_common_set_active_profile_t),
2981 sizeof(sli4_res_common_set_active_profile_t));
2983 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2984 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2989 req = (sli4_req_common_set_active_profile_t *)
2990 ((uint8_t*)buf + cmd_off);
2992 req->hdr.opcode = SLI4_OPC_COMMON_SET_ACTIVE_PROFILE;
2993 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2994 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2995 req->hdr.version = 0;
2997 req->active_profile_id = active_profile_id;
2999 return(cmd_off + sizeof(sli4_req_common_set_active_profile_t));
3004 * @brief Write a COMMON_GET_RECONFIG_LINK_INFO command.
3006 * @param sli4 SLI context.
3007 * @param buf Destination buffer for the command.
3008 * @param size Buffer size in bytes.
3009 * @param dma Buffer to store the supported link configuration modes from the physical device.
3011 * @return Returns the number of bytes written.
3014 sli_cmd_common_get_reconfig_link_info(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
3016 sli4_req_common_get_reconfig_link_info_t *req = NULL;
3017 uint32_t cmd_off = 0;
3018 uint32_t payload_size;
3020 /* Payload length must accommodate both request and response */
3021 payload_size = max(sizeof(sli4_req_common_get_reconfig_link_info_t),
3022 sizeof(sli4_res_common_get_reconfig_link_info_t));
3024 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3025 cmd_off = sli_cmd_sli_config(sli4, buf, size,
3032 ocs_memset(req, 0, dma->size);
3033 payload_size = dma->size;
3035 req = (sli4_req_common_get_reconfig_link_info_t *)((uint8_t *)buf + cmd_off);
3036 payload_size = sizeof(sli4_req_common_get_reconfig_link_info_t);
3039 req->hdr.opcode = SLI4_OPC_COMMON_GET_RECONFIG_LINK_INFO;
3040 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
3041 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
3042 req->hdr.version = 0;
3044 return(cmd_off + sizeof(sli4_req_common_get_reconfig_link_info_t));
3049 * @brief Write a COMMON_SET_RECONFIG_LINK_ID command.
3051 * @param sli4 SLI context.
3052 * @param buf destination buffer for the command.
3053 * @param size buffer size in bytes.
3054 * @param fd If non-zero, set link config to factory default.
3055 * @param active_link_config_id ID of new active profile.
3056 * @param dma Buffer to assign the link configuration mode that is to become active from the physical device.
3058 * @return Returns the number of bytes written.
3061 sli_cmd_common_set_reconfig_link_id(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma,
3062 uint32_t fd, uint32_t active_link_config_id)
3064 sli4_req_common_set_reconfig_link_id_t *req = NULL;
3065 uint32_t cmd_off = 0;
3066 uint32_t payload_size;
3068 /* Payload length must accommodate both request and response */
3069 payload_size = max(sizeof(sli4_req_common_set_reconfig_link_id_t),
3070 sizeof(sli4_res_common_set_reconfig_link_id_t));
3072 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3073 cmd_off = sli_cmd_sli_config(sli4, buf, size,
3080 ocs_memset(req, 0, dma->size);
3081 payload_size = dma->size;
3083 req = (sli4_req_common_set_reconfig_link_id_t *)((uint8_t *)buf + cmd_off);
3084 payload_size = sizeof(sli4_req_common_set_reconfig_link_id_t);
3087 req->hdr.opcode = SLI4_OPC_COMMON_SET_RECONFIG_LINK_ID;
3088 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
3089 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
3090 req->hdr.version = 0;
3092 req->next_link_config_id = active_link_config_id;
3094 return(cmd_off + sizeof(sli4_req_common_set_reconfig_link_id_t));
3100 * @brief Check the mailbox/queue completion entry.
3102 * @param buf Pointer to the MCQE.
3104 * @return Returns 0 on success, or a non-zero value on failure.
3107 sli_cqe_mq(void *buf)
3109 sli4_mcqe_t *mcqe = buf;
3112 * Firmware can split mbx completions into two MCQEs: first with only
3113 * the "consumed" bit set and a second with the "complete" bit set.
3114 * Thus, ignore MCQE unless "complete" is set.
3120 if (mcqe->completion_status) {
3121 ocs_log_debug(NULL, "bad status (cmpl=%#x ext=%#x con=%d cmp=%d ae=%d val=%d)\n",
3122 mcqe->completion_status,
3123 mcqe->extended_status,
3130 return mcqe->completion_status;
3135 * @brief Check the asynchronous event completion entry.
3137 * @param sli4 SLI context.
3138 * @param buf Pointer to the ACQE.
3140 * @return Returns 0 on success, or a non-zero value on failure.
3143 sli_cqe_async(sli4_t *sli4, void *buf)
3145 sli4_acqe_t *acqe = buf;
3148 if (!sli4 || !buf) {
3149 ocs_log_err(NULL, "bad parameter sli4=%p buf=%p\n", sli4, buf);
3153 switch (acqe->event_code) {
3154 case SLI4_ACQE_EVENT_CODE_LINK_STATE:
3155 rc = sli_fc_process_link_state(sli4, buf);
3157 case SLI4_ACQE_EVENT_CODE_FCOE_FIP:
3158 rc = sli_fc_process_fcoe(sli4, buf);
3160 case SLI4_ACQE_EVENT_CODE_GRP_5:
3161 /*TODO*/ocs_log_debug(sli4->os, "ACQE GRP5\n");
3163 case SLI4_ACQE_EVENT_CODE_SLI_PORT_EVENT:
3164 ocs_log_debug(sli4->os,"ACQE SLI Port, type=0x%x, data1,2=0x%08x,0x%08x\n",
3165 acqe->event_type, acqe->event_data[0], acqe->event_data[1]);
3166 #if defined(OCS_INCLUDE_DEBUG)
3167 ocs_dump32(OCS_DEBUG_ALWAYS, sli4->os, "acq", acqe, sizeof(*acqe));
3170 case SLI4_ACQE_EVENT_CODE_FC_LINK_EVENT:
3171 rc = sli_fc_process_link_attention(sli4, buf);
3174 /*TODO*/ocs_log_test(sli4->os, "ACQE unknown=%#x\n", acqe->event_code);
3181 * @brief Check the SLI_CONFIG response.
3184 * Function checks the SLI_CONFIG response and the payload status.
3186 * @param buf Pointer to SLI_CONFIG response.
3188 * @return Returns 0 on success, or a non-zero value on failure.
3191 sli_res_sli_config(void *buf)
3193 sli4_cmd_sli_config_t *sli_config = buf;
3195 if (!buf || (SLI4_MBOX_COMMAND_SLI_CONFIG != sli_config->hdr.command)) {
3196 ocs_log_err(NULL, "bad parameter buf=%p cmd=%#x\n", buf,
3197 buf ? sli_config->hdr.command : -1);
3201 if (sli_config->hdr.status) {
3202 return sli_config->hdr.status;
3205 if (sli_config->emb) {
3206 return sli_config->payload.embed[4];
3208 ocs_log_test(NULL, "external buffers not supported\n");
3214 * @brief Issue a COMMON_FUNCTION_RESET command.
3216 * @param sli4 SLI context.
3218 * @return Returns 0 on success, or a non-zero value on failure.
3221 sli_common_function_reset(sli4_t *sli4)
3224 if (sli_cmd_common_function_reset(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3225 if (sli_bmbx_command(sli4)) {
3226 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COM_FUNC_RESET)\n");
3229 if (sli_res_sli_config(sli4->bmbx.virt)) {
3230 ocs_log_err(sli4->os, "bad status COM_FUNC_RESET\n");
3234 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3243 * @brief check to see if the FW is ready.
3246 * Based on <i>SLI-4 Architecture Specification, Revision 4.x0-13 (2012).</i>.
3248 * @param sli4 SLI context.
3249 * @param timeout_ms Time, in milliseconds, to wait for the port to be ready
3252 * @return Returns TRUE for ready, or FALSE otherwise.
3255 sli_wait_for_fw_ready(sli4_t *sli4, uint32_t timeout_ms)
3257 uint32_t iter = timeout_ms / (SLI4_INIT_PORT_DELAY_US / 1000);
3258 uint32_t ready = FALSE;
3262 ocs_udelay(SLI4_INIT_PORT_DELAY_US);
3263 if (sli_fw_ready(sli4) == 1) {
3266 } while (!ready && (iter > 0));
3272 * @brief Initialize the firmware.
3275 * Based on <i>SLI-4 Architecture Specification, Revision 4.x0-13 (2012).</i>.
3277 * @param sli4 SLI context.
3279 * @return Returns 0 on success, or a non-zero value on failure.
3282 sli_fw_init(sli4_t *sli4)
3288 * Is firmware ready for operation?
3290 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
3292 ocs_log_crit(sli4->os, "FW status is NOT ready\n");
3297 * Reset port to a known state
3299 switch (sli4->if_type) {
3300 case SLI4_IF_TYPE_BE3_SKH_PF:
3301 case SLI4_IF_TYPE_BE3_SKH_VF:
3302 /* No SLIPORT_CONTROL register so use command sequence instead */
3303 if (sli_bmbx_wait(sli4, SLI4_BMBX_DELAY_US)) {
3304 ocs_log_crit(sli4->os, "bootstrap mailbox not ready\n");
3308 if (sli_cmd_fw_initialize(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3309 if (sli_bmbx_command(sli4)) {
3310 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (FW_INIT)\n");
3314 ocs_log_crit(sli4->os, "bad FW_INIT write\n");
3318 if (sli_common_function_reset(sli4)) {
3319 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3323 case SLI4_IF_TYPE_LANCER_FC_ETH:
3324 #if BYTE_ORDER == LITTLE_ENDIAN
3325 endian = SLI4_SLIPORT_CONTROL_LITTLE_ENDIAN;
3327 endian = SLI4_SLIPORT_CONTROL_BIG_ENDIAN;
3330 if (sli_sliport_control(sli4, endian))
3334 ocs_log_test(sli4->os, "if_type %d not supported\n", sli4->if_type);
3342 * @brief Terminate the firmware.
3344 * @param sli4 SLI context.
3346 * @return Returns 0 on success, or a non-zero value on failure.
3349 sli_fw_term(sli4_t *sli4)
3353 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF ||
3354 sli4->if_type == SLI4_IF_TYPE_BE3_SKH_VF) {
3355 /* No SLIPORT_CONTROL register so use command sequence instead */
3356 if (sli_bmbx_wait(sli4, SLI4_BMBX_DELAY_US)) {
3357 ocs_log_crit(sli4->os, "bootstrap mailbox not ready\n");
3361 if (sli_common_function_reset(sli4)) {
3362 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3366 if (sli_cmd_fw_deinitialize(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3367 if (sli_bmbx_command(sli4)) {
3368 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (FW_DEINIT)\n");
3372 ocs_log_test(sli4->os, "bad FW_DEINIT write\n");
3376 #if BYTE_ORDER == LITTLE_ENDIAN
3377 endian = SLI4_SLIPORT_CONTROL_LITTLE_ENDIAN;
3379 endian = SLI4_SLIPORT_CONTROL_BIG_ENDIAN;
3381 /* type 2 etc. use SLIPORT_CONTROL to initialize port */
3382 sli_sliport_control(sli4, endian);
3388 * @brief Write the doorbell register associated with the queue object.
3390 * @param sli4 SLI context.
3391 * @param q Queue object.
3393 * @return Returns 0 on success, or a non-zero value on failure.
3396 sli_queue_doorbell(sli4_t *sli4, sli4_queue_t *q)
3402 val = sli_eq_doorbell(q->n_posted, q->id, FALSE);
3403 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3406 val = sli_cq_doorbell(q->n_posted, q->id, FALSE);
3407 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3410 val = SLI4_MQ_DOORBELL(q->n_posted, q->id);
3411 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3415 uint32_t n_posted = q->n_posted;
3417 * FC/FCoE has different rules for Receive Queues. The host
3418 * should only update the doorbell of the RQ-pair containing
3419 * the headers since the header / payload RQs are treated
3420 * as a matched unit.
3422 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3424 * In RQ-pair, an RQ either contains the FC header
3425 * (i.e. is_hdr == TRUE) or the payload.
3427 * Don't ring doorbell for payload RQ
3429 if (!q->u.flag.is_hdr) {
3433 * Some RQ cannot be incremented one entry at a time. Instead,
3434 * the driver collects a number of entries and updates the
3437 if (q->u.flag.rq_batch) {
3438 if (((q->index + q->n_posted) % SLI4_QUEUE_RQ_BATCH)) {
3441 n_posted = SLI4_QUEUE_RQ_BATCH;
3445 val = SLI4_RQ_DOORBELL(n_posted, q->id);
3446 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3450 val = SLI4_WQ_DOORBELL(q->n_posted, q->index, q->id);
3451 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3454 ocs_log_test(sli4->os, "bad queue type %d\n", q->type);
3462 sli_request_features(sli4_t *sli4, sli4_features_t *features, uint8_t query)
3465 if (sli_cmd_request_features(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
3466 *features, query)) {
3467 sli4_cmd_request_features_t *req_features = sli4->bmbx.virt;
3469 if (sli_bmbx_command(sli4)) {
3470 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (REQUEST_FEATURES)\n");
3473 if (req_features->hdr.status) {
3474 ocs_log_err(sli4->os, "REQUEST_FEATURES bad status %#x\n",
3475 req_features->hdr.status);
3478 features->dword = req_features->response.dword;
3480 ocs_log_err(sli4->os, "bad REQUEST_FEATURES write\n");
3488 * @brief Calculate max queue entries.
3490 * @param sli4 SLI context.
3492 * @return Returns 0 on success, or a non-zero value on failure.
3495 sli_calc_max_qentries(sli4_t *sli4)
3498 uint32_t alloc_size, qentries, qentry_size;
3500 for (q = SLI_QTYPE_EQ; q < SLI_QTYPE_MAX; q++) {
3501 sli4->config.max_qentries[q] = sli_convert_mask_to_count(sli4->config.count_method[q],
3502 sli4->config.count_mask[q]);
3505 /* single, continguous DMA allocations will be called for each queue
3506 * of size (max_qentries * queue entry size); since these can be large,
3507 * check against the OS max DMA allocation size
3509 for (q = SLI_QTYPE_EQ; q < SLI_QTYPE_MAX; q++) {
3510 qentries = sli4->config.max_qentries[q];
3511 qentry_size = sli_get_queue_entry_size(sli4, q);
3512 alloc_size = qentries * qentry_size;
3513 if (alloc_size > ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE)) {
3514 while (alloc_size > ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE)) {
3515 /* cut the qentries in hwf until alloc_size <= max DMA alloc size */
3517 alloc_size = qentries * qentry_size;
3519 ocs_log_debug(sli4->os, "[%s]: max_qentries from %d to %d (max dma %d)\n",
3520 SLI_QNAME[q], sli4->config.max_qentries[q],
3521 qentries, ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE));
3522 sli4->config.max_qentries[q] = qentries;
3528 * @brief Issue a FW_CONFIG mailbox command and store the results.
3530 * @param sli4 SLI context.
3532 * @return Returns 0 on success, or a non-zero value on failure.
3535 sli_query_fw_config(sli4_t *sli4)
3538 * Read the device configuration
3540 * Note: Only ulp0 fields contain values
3542 if (sli_cmd_common_query_fw_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3543 sli4_res_common_query_fw_config_t *fw_config =
3544 (sli4_res_common_query_fw_config_t *)
3545 (((uint8_t *)sli4->bmbx.virt) + offsetof(sli4_cmd_sli_config_t, payload.embed));
3547 if (sli_bmbx_command(sli4)) {
3548 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (QUERY_FW_CONFIG)\n");
3551 if (fw_config->hdr.status) {
3552 ocs_log_err(sli4->os, "COMMON_QUERY_FW_CONFIG bad status %#x\n",
3553 fw_config->hdr.status);
3557 sli4->physical_port = fw_config->physical_port;
3558 sli4->config.dual_ulp_capable = ((fw_config->function_mode & SLI4_FUNCTION_MODE_DUA_MODE) == 0 ? 0 : 1);
3559 sli4->config.is_ulp_fc[0] = ((fw_config->ulp0_mode &
3560 (SLI4_ULP_MODE_FCOE_INI |
3561 SLI4_ULP_MODE_FCOE_TGT)) == 0 ? 0 : 1);
3562 sli4->config.is_ulp_fc[1] = ((fw_config->ulp1_mode &
3563 (SLI4_ULP_MODE_FCOE_INI |
3564 SLI4_ULP_MODE_FCOE_TGT)) == 0 ? 0 : 1);
3566 if (sli4->config.dual_ulp_capable) {
3568 * Lancer will not support this, so we use the values
3569 * from the READ_CONFIG.
3571 if (sli4->config.is_ulp_fc[0] &&
3572 sli4->config.is_ulp_fc[1]) {
3573 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp0_toe_wq_total + fw_config->ulp1_toe_wq_total;
3574 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp0_toe_defrq_total + fw_config->ulp1_toe_defrq_total;
3575 } else if (sli4->config.is_ulp_fc[0]) {
3576 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp0_toe_wq_total;
3577 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp0_toe_defrq_total;
3579 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp1_toe_wq_total;
3580 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp1_toe_defrq_total;
3584 ocs_log_err(sli4->os, "bad QUERY_FW_CONFIG write\n");
3592 sli_get_config(sli4_t *sli4)
3594 ocs_dma_t get_cntl_addl_data;
3597 * Read the device configuration
3599 if (sli_cmd_read_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3600 sli4_res_read_config_t *read_config = sli4->bmbx.virt;
3604 if (sli_bmbx_command(sli4)) {
3605 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_CONFIG)\n");
3608 if (read_config->hdr.status) {
3609 ocs_log_err(sli4->os, "READ_CONFIG bad status %#x\n",
3610 read_config->hdr.status);
3614 sli4->config.has_extents = read_config->ext;
3615 if (FALSE == sli4->config.has_extents) {
3617 uint32_t *base = sli4->config.extent[0].base;
3620 if (NULL == (base = ocs_malloc(sli4->os, SLI_RSRC_MAX * sizeof(uint32_t),
3621 OCS_M_ZERO | OCS_M_NOWAIT))) {
3622 ocs_log_err(sli4->os, "memory allocation failed for sli4_resource_t\n");
3627 for (i = 0; i < SLI_RSRC_MAX; i++) {
3628 sli4->config.extent[i].number = 1;
3629 sli4->config.extent[i].n_alloc = 0;
3630 sli4->config.extent[i].base = &base[i];
3633 sli4->config.extent[SLI_RSRC_FCOE_VFI].base[0] = read_config->vfi_base;
3634 sli4->config.extent[SLI_RSRC_FCOE_VFI].size = read_config->vfi_count;
3636 sli4->config.extent[SLI_RSRC_FCOE_VPI].base[0] = read_config->vpi_base;
3637 sli4->config.extent[SLI_RSRC_FCOE_VPI].size = read_config->vpi_count;
3639 sli4->config.extent[SLI_RSRC_FCOE_RPI].base[0] = read_config->rpi_base;
3640 sli4->config.extent[SLI_RSRC_FCOE_RPI].size = read_config->rpi_count;
3642 sli4->config.extent[SLI_RSRC_FCOE_XRI].base[0] = read_config->xri_base;
3643 sli4->config.extent[SLI_RSRC_FCOE_XRI].size = read_config->xri_count;
3645 sli4->config.extent[SLI_RSRC_FCOE_FCFI].base[0] = 0;
3646 sli4->config.extent[SLI_RSRC_FCOE_FCFI].size = read_config->fcfi_count;
3652 for (i = 0; i < SLI_RSRC_MAX; i++) {
3653 total = sli4->config.extent[i].number * sli4->config.extent[i].size;
3654 sli4->config.extent[i].use_map = ocs_bitmap_alloc(total);
3655 if (NULL == sli4->config.extent[i].use_map) {
3656 ocs_log_err(sli4->os, "bitmap memory allocation failed "
3657 "resource %d\n", i);
3660 sli4->config.extent[i].map_size = total;
3663 sli4->config.topology = read_config->topology;
3664 switch (sli4->config.topology) {
3665 case SLI4_READ_CFG_TOPO_FCOE:
3666 ocs_log_debug(sli4->os, "FCoE\n");
3668 case SLI4_READ_CFG_TOPO_FC:
3669 ocs_log_debug(sli4->os, "FC (unknown)\n");
3671 case SLI4_READ_CFG_TOPO_FC_DA:
3672 ocs_log_debug(sli4->os, "FC (direct attach)\n");
3674 case SLI4_READ_CFG_TOPO_FC_AL:
3675 ocs_log_debug(sli4->os, "FC (arbitrated loop)\n");
3678 ocs_log_test(sli4->os, "bad topology %#x\n", sli4->config.topology);
3681 sli4->config.e_d_tov = read_config->e_d_tov;
3682 sli4->config.r_a_tov = read_config->r_a_tov;
3684 sli4->config.link_module_type = read_config->lmt;
3686 sli4->config.max_qcount[SLI_QTYPE_EQ] = read_config->eq_count;
3687 sli4->config.max_qcount[SLI_QTYPE_CQ] = read_config->cq_count;
3688 sli4->config.max_qcount[SLI_QTYPE_WQ] = read_config->wq_count;
3689 sli4->config.max_qcount[SLI_QTYPE_RQ] = read_config->rq_count;
3692 * READ_CONFIG doesn't give the max number of MQ. Applications
3693 * will typically want 1, but we may need another at some future
3694 * date. Dummy up a "max" MQ count here.
3696 sli4->config.max_qcount[SLI_QTYPE_MQ] = SLI_USER_MQ_COUNT;
3698 ocs_log_err(sli4->os, "bad READ_CONFIG write\n");
3702 if (sli_cmd_common_get_sli4_parameters(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3703 sli4_res_common_get_sli4_parameters_t *parms = (sli4_res_common_get_sli4_parameters_t *)
3704 (((uint8_t *)sli4->bmbx.virt) + offsetof(sli4_cmd_sli_config_t, payload.embed));
3706 if (sli_bmbx_command(sli4)) {
3707 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_SLI4_PARAMETERS)\n");
3709 } else if (parms->hdr.status) {
3710 ocs_log_err(sli4->os, "COMMON_GET_SLI4_PARAMETERS bad status %#x att'l %#x\n",
3711 parms->hdr.status, parms->hdr.additional_status);
3715 sli4->config.auto_reg = parms->areg;
3716 sli4->config.auto_xfer_rdy = parms->agxf;
3717 sli4->config.hdr_template_req = parms->hdrr;
3718 sli4->config.t10_dif_inline_capable = parms->timm;
3719 sli4->config.t10_dif_separate_capable = parms->tsmm;
3721 sli4->config.mq_create_version = parms->mqv;
3722 sli4->config.cq_create_version = parms->cqv;
3723 sli4->config.rq_min_buf_size = parms->min_rq_buffer_size;
3724 sli4->config.rq_max_buf_size = parms->max_rq_buffer_size;
3726 sli4->config.qpage_count[SLI_QTYPE_EQ] = parms->eq_page_cnt;
3727 sli4->config.qpage_count[SLI_QTYPE_CQ] = parms->cq_page_cnt;
3728 sli4->config.qpage_count[SLI_QTYPE_MQ] = parms->mq_page_cnt;
3729 sli4->config.qpage_count[SLI_QTYPE_WQ] = parms->wq_page_cnt;
3730 sli4->config.qpage_count[SLI_QTYPE_RQ] = parms->rq_page_cnt;
3732 /* save count methods and masks for each queue type */
3733 sli4->config.count_mask[SLI_QTYPE_EQ] = parms->eqe_count_mask;
3734 sli4->config.count_method[SLI_QTYPE_EQ] = parms->eqe_count_method;
3735 sli4->config.count_mask[SLI_QTYPE_CQ] = parms->cqe_count_mask;
3736 sli4->config.count_method[SLI_QTYPE_CQ] = parms->cqe_count_method;
3737 sli4->config.count_mask[SLI_QTYPE_MQ] = parms->mqe_count_mask;
3738 sli4->config.count_method[SLI_QTYPE_MQ] = parms->mqe_count_method;
3739 sli4->config.count_mask[SLI_QTYPE_WQ] = parms->wqe_count_mask;
3740 sli4->config.count_method[SLI_QTYPE_WQ] = parms->wqe_count_method;
3741 sli4->config.count_mask[SLI_QTYPE_RQ] = parms->rqe_count_mask;
3742 sli4->config.count_method[SLI_QTYPE_RQ] = parms->rqe_count_method;
3744 /* now calculate max queue entries */
3745 sli_calc_max_qentries(sli4);
3747 sli4->config.max_sgl_pages = parms->sgl_page_cnt; /* max # of pages */
3748 sli4->config.sgl_page_sizes = parms->sgl_page_sizes; /* bit map of available sizes */
3749 /* ignore HLM here. Use value from REQUEST_FEATURES */
3751 sli4->config.sge_supported_length = parms->sge_supported_length;
3752 if (sli4->config.sge_supported_length > OCS_MAX_SGE_SIZE)
3753 sli4->config.sge_supported_length = OCS_MAX_SGE_SIZE;
3755 sli4->config.sgl_pre_registration_required = parms->sglr;
3756 /* default to using pre-registered SGL's */
3757 sli4->config.sgl_pre_registered = TRUE;
3759 sli4->config.perf_hint = parms->phon;
3760 sli4->config.perf_wq_id_association = parms->phwq;
3762 sli4->config.rq_batch = parms->rq_db_window;
3764 /* save the fields for skyhawk SGL chaining */
3765 sli4->config.sgl_chaining_params.chaining_capable =
3767 sli4->config.sgl_chaining_params.frag_num_field_offset =
3768 parms->frag_num_field_offset;
3769 sli4->config.sgl_chaining_params.frag_num_field_mask =
3770 (1ull << parms->frag_num_field_size) - 1;
3771 sli4->config.sgl_chaining_params.sgl_index_field_offset =
3772 parms->sgl_index_field_offset;
3773 sli4->config.sgl_chaining_params.sgl_index_field_mask =
3774 (1ull << parms->sgl_index_field_size) - 1;
3775 sli4->config.sgl_chaining_params.chain_sge_initial_value_lo =
3776 parms->chain_sge_initial_value_lo;
3777 sli4->config.sgl_chaining_params.chain_sge_initial_value_hi =
3778 parms->chain_sge_initial_value_hi;
3780 /* Use the highest available WQE size. */
3781 if (parms->wqe_sizes & SLI4_128BYTE_WQE_SUPPORT) {
3782 sli4->config.wqe_size = SLI4_WQE_EXT_BYTES;
3784 sli4->config.wqe_size = SLI4_WQE_BYTES;
3788 if (sli_query_fw_config(sli4)) {
3789 ocs_log_err(sli4->os, "Error sending QUERY_FW_CONFIG\n");
3793 sli4->config.port_number = 0;
3796 * Issue COMMON_GET_CNTL_ATTRIBUTES to get port_number. Temporarily
3797 * uses VPD DMA buffer as the response won't fit in the embedded
3800 if (sli_cmd_common_get_cntl_attributes(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &sli4->vpd.data)) {
3801 sli4_res_common_get_cntl_attributes_t *attr = sli4->vpd.data.virt;
3803 if (sli_bmbx_command(sli4)) {
3804 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_CNTL_ATTRIBUTES)\n");
3806 } else if (attr->hdr.status) {
3807 ocs_log_err(sli4->os, "COMMON_GET_CNTL_ATTRIBUTES bad status %#x att'l %#x\n",
3808 attr->hdr.status, attr->hdr.additional_status);
3812 sli4->config.port_number = attr->port_number;
3814 ocs_memcpy(sli4->config.bios_version_string, attr->bios_version_string,
3815 sizeof(sli4->config.bios_version_string));
3817 ocs_log_err(sli4->os, "bad COMMON_GET_CNTL_ATTRIBUTES write\n");
3821 if (ocs_dma_alloc(sli4->os, &get_cntl_addl_data, sizeof(sli4_res_common_get_cntl_addl_attributes_t),
3822 OCS_MIN_DMA_ALIGNMENT)) {
3823 ocs_log_err(sli4->os, "Failed to allocate memory for GET_CNTL_ADDL_ATTR data\n");
3825 if (sli_cmd_common_get_cntl_addl_attributes(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
3826 &get_cntl_addl_data)) {
3827 sli4_res_common_get_cntl_addl_attributes_t *attr = get_cntl_addl_data.virt;
3829 if (sli_bmbx_command(sli4)) {
3830 ocs_log_crit(sli4->os,
3831 "bootstrap mailbox write fail (COMMON_GET_CNTL_ADDL_ATTRIBUTES)\n");
3832 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3835 if (attr->hdr.status) {
3836 ocs_log_err(sli4->os, "COMMON_GET_CNTL_ADDL_ATTRIBUTES bad status %#x\n",
3838 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3842 ocs_memcpy(sli4->config.ipl_name, attr->ipl_file_name, sizeof(sli4->config.ipl_name));
3844 ocs_log_debug(sli4->os, "IPL:%s \n", (char*)sli4->config.ipl_name);
3846 ocs_log_err(sli4->os, "bad COMMON_GET_CNTL_ADDL_ATTRIBUTES write\n");
3847 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3851 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3854 if (sli_cmd_common_get_port_name(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3855 sli4_res_common_get_port_name_t *port_name = (sli4_res_common_get_port_name_t *)(((uint8_t *)sli4->bmbx.virt) +
3856 offsetof(sli4_cmd_sli_config_t, payload.embed));
3858 if (sli_bmbx_command(sli4)) {
3859 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_PORT_NAME)\n");
3863 sli4->config.port_name[0] = port_name->port_name[sli4->config.port_number];
3865 sli4->config.port_name[1] = '\0';
3867 if (sli_cmd_read_rev(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &sli4->vpd.data)) {
3868 sli4_cmd_read_rev_t *read_rev = sli4->bmbx.virt;
3870 if (sli_bmbx_command(sli4)) {
3871 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_REV)\n");
3874 if (read_rev->hdr.status) {
3875 ocs_log_err(sli4->os, "READ_REV bad status %#x\n",
3876 read_rev->hdr.status);
3880 sli4->config.fw_rev[0] = read_rev->first_fw_id;
3881 ocs_memcpy(sli4->config.fw_name[0],read_rev->first_fw_name, sizeof(sli4->config.fw_name[0]));
3883 sli4->config.fw_rev[1] = read_rev->second_fw_id;
3884 ocs_memcpy(sli4->config.fw_name[1],read_rev->second_fw_name, sizeof(sli4->config.fw_name[1]));
3886 sli4->config.hw_rev[0] = read_rev->first_hw_revision;
3887 sli4->config.hw_rev[1] = read_rev->second_hw_revision;
3888 sli4->config.hw_rev[2] = read_rev->third_hw_revision;
3890 ocs_log_debug(sli4->os, "FW1:%s (%08x) / FW2:%s (%08x)\n",
3891 read_rev->first_fw_name, read_rev->first_fw_id,
3892 read_rev->second_fw_name, read_rev->second_fw_id);
3894 ocs_log_debug(sli4->os, "HW1: %08x / HW2: %08x\n", read_rev->first_hw_revision,
3895 read_rev->second_hw_revision);
3897 /* Check that all VPD data was returned */
3898 if (read_rev->returned_vpd_length != read_rev->actual_vpd_length) {
3899 ocs_log_test(sli4->os, "VPD length: available=%d returned=%d actual=%d\n",
3900 read_rev->available_length,
3901 read_rev->returned_vpd_length,
3902 read_rev->actual_vpd_length);
3904 sli4->vpd.length = read_rev->returned_vpd_length;
3906 ocs_log_err(sli4->os, "bad READ_REV write\n");
3910 if (sli_cmd_read_nvparms(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3911 sli4_cmd_read_nvparms_t *read_nvparms = sli4->bmbx.virt;
3913 if (sli_bmbx_command(sli4)) {
3914 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_NVPARMS)\n");
3917 if (read_nvparms->hdr.status) {
3918 ocs_log_err(sli4->os, "READ_NVPARMS bad status %#x\n",
3919 read_nvparms->hdr.status);
3923 ocs_memcpy(sli4->config.wwpn, read_nvparms->wwpn, sizeof(sli4->config.wwpn));
3924 ocs_memcpy(sli4->config.wwnn, read_nvparms->wwnn, sizeof(sli4->config.wwnn));
3926 ocs_log_debug(sli4->os, "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
3927 sli4->config.wwpn[0],
3928 sli4->config.wwpn[1],
3929 sli4->config.wwpn[2],
3930 sli4->config.wwpn[3],
3931 sli4->config.wwpn[4],
3932 sli4->config.wwpn[5],
3933 sli4->config.wwpn[6],
3934 sli4->config.wwpn[7]);
3935 ocs_log_debug(sli4->os, "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
3936 sli4->config.wwnn[0],
3937 sli4->config.wwnn[1],
3938 sli4->config.wwnn[2],
3939 sli4->config.wwnn[3],
3940 sli4->config.wwnn[4],
3941 sli4->config.wwnn[5],
3942 sli4->config.wwnn[6],
3943 sli4->config.wwnn[7]);
3945 ocs_log_err(sli4->os, "bad READ_NVPARMS write\n");
3952 /****************************************************************************
3958 * @brief Set up the SLI context.
3960 * @param sli4 SLI context.
3961 * @param os Device abstraction.
3962 * @param port_type Protocol type of port (for example, FC and NIC).
3964 * @return Returns 0 on success, or a non-zero value on failure.
3967 sli_setup(sli4_t *sli4, ocs_os_handle_t os, sli4_port_type_e port_type)
3969 uint32_t sli_intf = UINT32_MAX;
3970 uint32_t pci_class_rev = 0;
3971 uint32_t rev_id = 0;
3972 uint32_t family = 0;
3974 sli4_asic_entry_t *asic;
3976 ocs_memset(sli4, 0, sizeof(sli4_t));
3979 sli4->port_type = port_type;
3982 * Read the SLI_INTF register to discover the register layout
3983 * and other capability information
3985 sli_intf = ocs_config_read32(os, SLI4_INTF_REG);
3987 if (sli_intf_valid_check(sli_intf)) {
3988 ocs_log_err(os, "SLI_INTF is not valid\n");
3992 /* driver only support SLI-4 */
3993 sli4->sli_rev = sli_intf_sli_revision(sli_intf);
3994 if (4 != sli4->sli_rev) {
3995 ocs_log_err(os, "Unsupported SLI revision (intf=%#x)\n",
4000 sli4->sli_family = sli_intf_sli_family(sli_intf);
4002 sli4->if_type = sli_intf_if_type(sli_intf);
4004 if (SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type) {
4005 ocs_log_debug(os, "status=%#x error1=%#x error2=%#x\n",
4006 sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS),
4007 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR1),
4008 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR2));
4012 * set the ASIC type and revision
4014 pci_class_rev = ocs_config_read32(os, SLI4_PCI_CLASS_REVISION);
4015 rev_id = sli_pci_rev_id(pci_class_rev);
4016 family = sli4->sli_family;
4017 if (family == SLI4_FAMILY_CHECK_ASIC_TYPE) {
4018 uint32_t asic_id = ocs_config_read32(os, SLI4_ASIC_ID_REG);
4019 family = sli_asic_gen(asic_id);
4022 for (i = 0, asic = sli4_asic_table; i < ARRAY_SIZE(sli4_asic_table); i++, asic++) {
4023 if ((rev_id == asic->rev_id) && (family == asic->family)) {
4024 sli4->asic_type = asic->type;
4025 sli4->asic_rev = asic->rev;
4029 /* Fail if no matching asic type/rev was found */
4030 if( (sli4->asic_type == 0) || (sli4->asic_rev == 0)) {
4031 ocs_log_err(os, "no matching asic family/rev found: %02x/%02x\n", family, rev_id);
4036 * The bootstrap mailbox is equivalent to a MQ with a single 256 byte
4037 * entry, a CQ with a single 16 byte entry, and no event queue.
4038 * Alignment must be 16 bytes as the low order address bits in the
4039 * address register are also control / status.
4041 if (ocs_dma_alloc(sli4->os, &sli4->bmbx, SLI4_BMBX_SIZE +
4042 sizeof(sli4_mcqe_t), 16)) {
4043 ocs_log_err(os, "bootstrap mailbox allocation failed\n");
4047 if (sli4->bmbx.phys & SLI4_BMBX_MASK_LO) {
4048 ocs_log_err(os, "bad alignment for bootstrap mailbox\n");
4052 ocs_log_debug(os, "bmbx v=%p p=0x%x %08x s=%zd\n", sli4->bmbx.virt,
4053 ocs_addr32_hi(sli4->bmbx.phys),
4054 ocs_addr32_lo(sli4->bmbx.phys),
4057 /* TODO 4096 is arbitrary. What should this value actually be? */
4058 if (ocs_dma_alloc(sli4->os, &sli4->vpd.data, 4096/*TODO*/, 4096)) {
4059 /* Note that failure isn't fatal in this specific case */
4060 sli4->vpd.data.size = 0;
4061 ocs_log_test(os, "VPD buffer allocation failed\n");
4064 if (sli_fw_init(sli4)) {
4065 ocs_log_err(sli4->os, "FW initialization failed\n");
4070 * Set one of fcpi(initiator), fcpt(target), fcpc(combined) to true
4071 * in addition to any other desired features
4073 sli4->config.features.flag.iaab = TRUE;
4074 sli4->config.features.flag.npiv = TRUE;
4075 sli4->config.features.flag.dif = TRUE;
4076 sli4->config.features.flag.vf = TRUE;
4077 sli4->config.features.flag.fcpc = TRUE;
4078 sli4->config.features.flag.iaar = TRUE;
4079 sli4->config.features.flag.hlm = TRUE;
4080 sli4->config.features.flag.perfh = TRUE;
4081 sli4->config.features.flag.rxseq = TRUE;
4082 sli4->config.features.flag.rxri = TRUE;
4083 sli4->config.features.flag.mrqp = TRUE;
4085 /* use performance hints if available */
4086 if (sli4->config.perf_hint) {
4087 sli4->config.features.flag.perfh = TRUE;
4090 if (sli_request_features(sli4, &sli4->config.features, TRUE)) {
4094 if (sli_get_config(sli4)) {
4102 sli_init(sli4_t *sli4)
4105 if (sli4->config.has_extents) {
4106 /* TODO COMMON_ALLOC_RESOURCE_EXTENTS */;
4107 ocs_log_test(sli4->os, "XXX need to implement extent allocation\n");
4111 sli4->config.features.flag.hlm = sli4->config.high_login_mode;
4112 sli4->config.features.flag.rxseq = FALSE;
4113 sli4->config.features.flag.rxri = FALSE;
4115 if (sli_request_features(sli4, &sli4->config.features, FALSE)) {
4123 sli_reset(sli4_t *sli4)
4127 if (sli_fw_init(sli4)) {
4128 ocs_log_crit(sli4->os, "FW initialization failed\n");
4132 if (sli4->config.extent[0].base) {
4133 ocs_free(sli4->os, sli4->config.extent[0].base, SLI_RSRC_MAX * sizeof(uint32_t));
4134 sli4->config.extent[0].base = NULL;
4137 for (i = 0; i < SLI_RSRC_MAX; i++) {
4138 if (sli4->config.extent[i].use_map) {
4139 ocs_bitmap_free(sli4->config.extent[i].use_map);
4140 sli4->config.extent[i].use_map = NULL;
4142 sli4->config.extent[i].base = NULL;
4145 if (sli_get_config(sli4)) {
4154 * @brief Issue a Firmware Reset.
4157 * Issues a Firmware Reset to the chip. This reset affects the entire chip,
4158 * so all PCI function on the same PCI bus and device are affected.
4159 * @n @n This type of reset can be used to activate newly downloaded firmware.
4160 * @n @n The driver should be considered to be in an unknown state after this
4161 * reset and should be reloaded.
4163 * @param sli4 SLI context.
4165 * @return Returns 0 on success, or -1 otherwise.
4169 sli_fw_reset(sli4_t *sli4)
4175 * Firmware must be ready before issuing the reset.
4177 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
4179 ocs_log_crit(sli4->os, "FW status is NOT ready\n");
4182 switch(sli4->if_type) {
4183 case SLI4_IF_TYPE_BE3_SKH_PF:
4184 /* BE3 / Skyhawk use PCICFG_SOFT_RESET_CSR */
4185 val = ocs_config_read32(sli4->os, SLI4_PCI_SOFT_RESET_CSR);
4186 val |= SLI4_PCI_SOFT_RESET_MASK;
4187 ocs_config_write32(sli4->os, SLI4_PCI_SOFT_RESET_CSR, val);
4189 case SLI4_IF_TYPE_LANCER_FC_ETH:
4190 /* Lancer uses PHYDEV_CONTROL */
4192 val = SLI4_PHYDEV_CONTROL_FRST;
4193 sli_reg_write(sli4, SLI4_REG_PHYSDEV_CONTROL, val);
4196 ocs_log_test(sli4->os, "Unexpected iftype %d\n", sli4->if_type);
4201 /* wait for the FW to become ready after the reset */
4202 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
4204 ocs_log_crit(sli4->os, "Failed to become ready after firmware reset\n");
4212 * @brief Tear down a SLI context.
4214 * @param sli4 SLI context.
4216 * @return Returns 0 on success, or non-zero otherwise.
4219 sli_teardown(sli4_t *sli4)
4223 if (sli4->config.extent[0].base) {
4224 ocs_free(sli4->os, sli4->config.extent[0].base, SLI_RSRC_MAX * sizeof(uint32_t));
4225 sli4->config.extent[0].base = NULL;
4228 for (i = 0; i < SLI_RSRC_MAX; i++) {
4229 if (sli4->config.has_extents) {
4230 /* TODO COMMON_DEALLOC_RESOURCE_EXTENTS */;
4233 sli4->config.extent[i].base = NULL;
4235 ocs_bitmap_free(sli4->config.extent[i].use_map);
4236 sli4->config.extent[i].use_map = NULL;
4239 if (sli_fw_term(sli4)) {
4240 ocs_log_err(sli4->os, "FW deinitialization failed\n");
4243 ocs_dma_free(sli4->os, &sli4->vpd.data);
4244 ocs_dma_free(sli4->os, &sli4->bmbx);
4251 * @brief Register a callback for the given event.
4253 * @param sli4 SLI context.
4254 * @param which Event of interest.
4255 * @param func Function to call when the event occurs.
4256 * @param arg Argument passed to the callback function.
4258 * @return Returns 0 on success, or non-zero otherwise.
4261 sli_callback(sli4_t *sli4, sli4_callback_e which, void *func, void *arg)
4264 if (!sli4 || !func || (which >= SLI4_CB_MAX)) {
4265 ocs_log_err(NULL, "bad parameter sli4=%p which=%#x func=%p\n",
4273 sli4->link_arg = arg;
4277 sli4->fip_arg = arg;
4280 ocs_log_test(sli4->os, "unknown callback %#x\n", which);
4289 * @brief Initialize a queue object.
4292 * This initializes the sli4_queue_t object members, including the underlying
4295 * @param sli4 SLI context.
4296 * @param q Pointer to queue object.
4297 * @param qtype Type of queue to create.
4298 * @param size Size of each entry.
4299 * @param n_entries Number of entries to allocate.
4300 * @param align Starting memory address alignment.
4302 * @note Checks if using the existing DMA memory (if any) is possible. If not,
4303 * it frees the existing memory and re-allocates.
4305 * @return Returns 0 on success, or non-zero otherwise.
4308 __sli_queue_init(sli4_t *sli4, sli4_queue_t *q, uint32_t qtype,
4309 size_t size, uint32_t n_entries, uint32_t align)
4312 if ((q->dma.virt == NULL) || (size != q->size) || (n_entries != q->length)) {
4314 ocs_dma_free(sli4->os, &q->dma);
4317 ocs_memset(q, 0, sizeof(sli4_queue_t));
4319 if (ocs_dma_alloc(sli4->os, &q->dma, size * n_entries, align)) {
4320 ocs_log_err(sli4->os, "%s allocation failed\n", SLI_QNAME[qtype]);
4324 ocs_memset(q->dma.virt, 0, size * n_entries);
4326 ocs_lock_init(sli4->os, &q->lock, "%s lock[%d:%p]",
4327 SLI_QNAME[qtype], ocs_instance(sli4->os), &q->lock);
4331 q->length = n_entries;
4333 /* Limit to hwf the queue size per interrupt */
4334 q->proc_limit = n_entries / 2;
4338 q->posted_limit = q->length / 2;
4341 if ((sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) ||
4342 (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_VF)) {
4343 /* For Skyhawk, ring the doorbell more often */
4344 q->posted_limit = 8;
4346 q->posted_limit = 64;
4357 * @brief Issue the command to create a queue.
4359 * @param sli4 SLI context.
4360 * @param q Pointer to queue object.
4362 * @return Returns 0 on success, or non-zero otherwise.
4365 __sli_create_queue(sli4_t *sli4, sli4_queue_t *q)
4367 sli4_res_common_create_queue_t *res_q = NULL;
4369 if (sli_bmbx_command(sli4)){
4370 ocs_log_crit(sli4->os, "bootstrap mailbox write fail %s\n",
4371 SLI_QNAME[q->type]);
4372 ocs_dma_free(sli4->os, &q->dma);
4375 if (sli_res_sli_config(sli4->bmbx.virt)) {
4376 ocs_log_err(sli4->os, "bad status create %s\n", SLI_QNAME[q->type]);
4377 ocs_dma_free(sli4->os, &q->dma);
4380 res_q = (void *)((uint8_t *)sli4->bmbx.virt +
4381 offsetof(sli4_cmd_sli_config_t, payload));
4383 if (res_q->hdr.status) {
4384 ocs_log_err(sli4->os, "bad create %s status=%#x addl=%#x\n",
4386 res_q->hdr.status, res_q->hdr.additional_status);
4387 ocs_dma_free(sli4->os, &q->dma);
4390 q->id = res_q->q_id;
4391 q->doorbell_offset = res_q->db_offset;
4392 q->doorbell_rset = res_q->db_rs;
4396 /* No doorbell information in response for EQs */
4397 q->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4398 q->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4401 /* No doorbell information in response for CQs */
4402 q->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4403 q->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4406 /* No doorbell information in response for MQs */
4407 q->doorbell_offset = regmap[SLI4_REG_MQ_DOORBELL][sli4->if_type].off;
4408 q->doorbell_rset = regmap[SLI4_REG_MQ_DOORBELL][sli4->if_type].rset;
4411 /* set the doorbell for non-skyhawks */
4412 if (!sli4->config.dual_ulp_capable) {
4413 q->doorbell_offset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].off;
4414 q->doorbell_rset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].rset;
4418 /* set the doorbell for non-skyhawks */
4419 if (!sli4->config.dual_ulp_capable) {
4420 q->doorbell_offset = regmap[SLI4_REG_IO_WQ_DOORBELL][sli4->if_type].off;
4421 q->doorbell_rset = regmap[SLI4_REG_IO_WQ_DOORBELL][sli4->if_type].rset;
4434 * @brief Get queue entry size.
4436 * Get queue entry size given queue type.
4438 * @param sli4 SLI context
4439 * @param qtype Type for which the entry size is returned.
4441 * @return Returns > 0 on success (queue entry size), or a negative value on failure.
4444 sli_get_queue_entry_size(sli4_t *sli4, uint32_t qtype)
4449 ocs_log_err(NULL, "bad parameter sli4=%p\n", sli4);
4455 size = sizeof(uint32_t);
4464 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4465 size = sli4->config.wqe_size;
4468 ocs_log_test(sli4->os, "unsupported queue entry size\n");
4473 size = SLI4_FCOE_RQE_SIZE;
4476 ocs_log_test(sli4->os, "unknown queue type %d\n", qtype);
4484 * @brief Modify the delay timer for all the EQs
4486 * @param sli4 SLI context.
4487 * @param eq Array of EQs.
4488 * @param num_eq Count of EQs.
4489 * @param shift Phase shift for staggering interrupts.
4490 * @param delay_mult Delay multiplier for limiting interrupt frequency.
4492 * @return Returns 0 on success, or -1 otherwise.
4495 sli_eq_modify_delay(sli4_t *sli4, sli4_queue_t *eq, uint32_t num_eq, uint32_t shift, uint32_t delay_mult)
4498 sli_cmd_common_modify_eq_delay(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, eq, num_eq, shift, delay_mult);
4500 if (sli_bmbx_command(sli4)) {
4501 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (MODIFY EQ DELAY)\n");
4504 if (sli_res_sli_config(sli4->bmbx.virt)) {
4505 ocs_log_err(sli4->os, "bad status MODIFY EQ DELAY\n");
4514 * @brief Allocate a queue.
4517 * Allocates DMA memory and configures the requested queue type.
4519 * @param sli4 SLI context.
4520 * @param qtype Type of queue to create.
4521 * @param q Pointer to the queue object.
4522 * @param n_entries Number of entries to allocate.
4523 * @param assoc Associated queue (that is, the EQ for a CQ, the CQ for a MQ, and so on).
4524 * @param ulp The ULP to bind, which is only used for WQ and RQs
4526 * @return Returns 0 on success, or -1 otherwise.
4529 sli_queue_alloc(sli4_t *sli4, uint32_t qtype, sli4_queue_t *q, uint32_t n_entries,
4530 sli4_queue_t *assoc, uint16_t ulp)
4534 sli4_create_q_fn_t create = NULL;
4537 ocs_log_err(NULL, "bad parameter sli4=%p q=%p\n", sli4, q);
4541 /* get queue size */
4542 size = sli_get_queue_entry_size(sli4, qtype);
4545 align = SLI_PAGE_SIZE;
4549 create = sli_cmd_common_create_eq;
4552 create = sli_cmd_common_create_cq;
4555 /* Validate the number of entries */
4556 switch (n_entries) {
4563 ocs_log_test(sli4->os, "illegal n_entries value %d for MQ\n", n_entries);
4566 assoc->u.flag.is_mq = TRUE;
4567 create = sli_cmd_common_create_mq_ext;
4570 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4571 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) {
4572 create = sli_cmd_fcoe_wq_create;
4574 create = sli_cmd_fcoe_wq_create_v1;
4578 ocs_log_test(sli4->os, "unsupported WQ create\n");
4583 ocs_log_test(sli4->os, "unknown queue type %d\n", qtype);
4588 if (__sli_queue_init(sli4, q, qtype, size, n_entries, align)) {
4589 ocs_log_err(sli4->os, "%s allocation failed\n", SLI_QNAME[qtype]);
4593 if (create(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &q->dma, assoc ? assoc->id : 0, ulp)) {
4595 if (__sli_create_queue(sli4, q)) {
4596 ocs_log_err(sli4->os, "create %s failed\n", SLI_QNAME[qtype]);
4601 ocs_log_err(sli4->os, "cannot create %s\n", SLI_QNAME[qtype]);
4611 * @brief Allocate a c queue set.
4613 * @param sli4 SLI context.
4614 * @param num_cqs to create
4615 * @param qs Pointers to the queue objects.
4616 * @param n_entries Number of entries to allocate per CQ.
4617 * @param eqs Associated event queues
4619 * @return Returns 0 on success, or -1 otherwise.
4622 sli_cq_alloc_set(sli4_t *sli4, sli4_queue_t *qs[], uint32_t num_cqs,
4623 uint32_t n_entries, sli4_queue_t *eqs[])
4625 uint32_t i, offset = 0, page_bytes = 0, payload_size, cmd_size = 0;
4626 uint32_t p = 0, page_size = 0, n_cqe = 0, num_pages_cq;
4629 sli4_req_common_create_cq_set_v0_t *req = NULL;
4630 sli4_res_common_create_queue_set_t *res = NULL;
4633 ocs_log_err(NULL, "bad parameter sli4=%p\n", sli4);
4637 memset(&dma, 0, sizeof(dma));
4639 /* Align the queue DMA memory */
4640 for (i = 0; i < num_cqs; i++) {
4641 if (__sli_queue_init(sli4, qs[i], SLI_QTYPE_CQ, SLI4_CQE_BYTES,
4642 n_entries, SLI_PAGE_SIZE)) {
4643 ocs_log_err(sli4->os, "Queue init failed.\n");
4648 n_cqe = qs[0]->dma.size / SLI4_CQE_BYTES;
4663 page_bytes = page_size * SLI_PAGE_SIZE;
4664 num_pages_cq = sli_page_count(qs[0]->dma.size, page_bytes);
4665 cmd_size = sizeof(sli4_req_common_create_cq_set_v0_t) + (8 * num_pages_cq * num_cqs);
4666 payload_size = max((size_t)cmd_size, sizeof(sli4_res_common_create_queue_set_t));
4668 if (ocs_dma_alloc(sli4->os, &dma, payload_size, SLI_PAGE_SIZE)) {
4669 ocs_log_err(sli4->os, "DMA allocation failed\n");
4672 ocs_memset(dma.virt, 0, payload_size);
4674 if (sli_cmd_sli_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
4675 payload_size, &dma) == -1) {
4679 /* Fill the request structure */
4681 req = (sli4_req_common_create_cq_set_v0_t *)((uint8_t *)dma.virt);
4682 req->hdr.opcode = SLI4_OPC_COMMON_CREATE_CQ_SET;
4683 req->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
4684 req->hdr.version = 0;
4685 req->hdr.request_length = cmd_size - sizeof(sli4_req_hdr_t);
4686 req->page_size = page_size;
4688 req->num_pages = num_pages_cq;
4689 switch (req->num_pages) {
4691 req->cqecnt = SLI4_CQ_CNT_256;
4694 req->cqecnt = SLI4_CQ_CNT_512;
4697 req->cqecnt = SLI4_CQ_CNT_1024;
4700 req->cqecnt = SLI4_CQ_CNT_LARGE;
4701 req->cqe_count = n_cqe;
4704 ocs_log_test(sli4->os, "num_pages %d not valid\n", req->num_pages);
4711 req->num_cq_req = num_cqs;
4713 /* Fill page addresses of all the CQs. */
4714 for (i = 0; i < num_cqs; i++) {
4715 req->eq_id[i] = eqs[i]->id;
4716 for (p = 0, addr = qs[i]->dma.phys; p < req->num_pages; p++, addr += page_bytes) {
4717 req->page_physical_address[offset].low = ocs_addr32_lo(addr);
4718 req->page_physical_address[offset].high = ocs_addr32_hi(addr);
4723 if (sli_bmbx_command(sli4)) {
4724 ocs_log_crit(sli4->os, "bootstrap mailbox write fail CQSet\n");
4728 res = (void *)((uint8_t *)dma.virt);
4729 if (res->hdr.status) {
4730 ocs_log_err(sli4->os, "bad create CQSet status=%#x addl=%#x\n",
4731 res->hdr.status, res->hdr.additional_status);
4734 /* Check if we got all requested CQs. */
4735 if (res->num_q_allocated != num_cqs) {
4736 ocs_log_crit(sli4->os, "Requested count CQs doesnt match.\n");
4740 /* Fill the resp cq ids. */
4741 for (i = 0; i < num_cqs; i++) {
4742 qs[i]->id = res->q_id + i;
4743 qs[i]->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4744 qs[i]->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4748 ocs_dma_free(sli4->os, &dma);
4753 for (i = 0; i < num_cqs; i++) {
4754 if (qs[i]->dma.size) {
4755 ocs_dma_free(sli4->os, &qs[i]->dma);
4760 ocs_dma_free(sli4->os, &dma);
4770 * @brief Free a queue.
4773 * Frees DMA memory and de-registers the requested queue.
4775 * @param sli4 SLI context.
4776 * @param q Pointer to the queue object.
4777 * @param destroy_queues Non-zero if the mailbox commands should be sent to destroy the queues.
4778 * @param free_memory Non-zero if the DMA memory associated with the queue should be freed.
4780 * @return Returns 0 on success, or -1 otherwise.
4783 sli_queue_free(sli4_t *sli4, sli4_queue_t *q, uint32_t destroy_queues, uint32_t free_memory)
4785 sli4_destroy_q_fn_t destroy = NULL;
4789 ocs_log_err(NULL, "bad parameter sli4=%p q=%p\n", sli4, q);
4793 if (destroy_queues) {
4796 destroy = sli_cmd_common_destroy_eq;
4799 destroy = sli_cmd_common_destroy_cq;
4802 destroy = sli_cmd_common_destroy_mq;
4805 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4806 destroy = sli_cmd_fcoe_wq_destroy;
4809 ocs_log_test(sli4->os, "unsupported WQ destroy\n");
4814 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4815 destroy = sli_cmd_fcoe_rq_destroy;
4818 ocs_log_test(sli4->os, "unsupported RQ destroy\n");
4823 ocs_log_test(sli4->os, "bad queue type %d\n",
4829 * Destroying queues makes BE3 sad (version 0 interface type). Rely
4830 * on COMMON_FUNCTION_RESET to free host allocated queue resources
4831 * inside the SLI Port.
4833 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
4837 /* Destroy the queue if the operation is defined */
4838 if (destroy && destroy(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, q->id)) {
4839 sli4_res_hdr_t *res = NULL;
4841 if (sli_bmbx_command(sli4)){
4842 ocs_log_crit(sli4->os, "bootstrap mailbox write fail destroy %s\n",
4843 SLI_QNAME[q->type]);
4844 } else if (sli_res_sli_config(sli4->bmbx.virt)) {
4845 ocs_log_err(sli4->os, "bad status destroy %s\n", SLI_QNAME[q->type]);
4847 res = (void *)((uint8_t *)sli4->bmbx.virt +
4848 offsetof(sli4_cmd_sli_config_t, payload));
4851 ocs_log_err(sli4->os, "bad destroy %s status=%#x addl=%#x\n",
4853 res->status, res->additional_status);
4862 ocs_lock_free(&q->lock);
4864 if (ocs_dma_free(sli4->os, &q->dma)) {
4865 ocs_log_err(sli4->os, "%s queue ID %d free failed\n",
4866 SLI_QNAME[q->type], q->id);
4875 sli_queue_reset(sli4_t *sli4, sli4_queue_t *q)
4883 if (SLI_QTYPE_MQ == q->type) {
4887 if (q->dma.virt != NULL) {
4888 ocs_memset(q->dma.virt, 0, (q->size * (uint64_t)q->length));
4891 ocs_unlock(&q->lock);
4898 * @brief Check if the given queue is empty.
4901 * If the valid bit of the current entry is unset, the queue is empty.
4903 * @param sli4 SLI context.
4904 * @param q Pointer to the queue object.
4906 * @return Returns TRUE if empty, or FALSE otherwise.
4909 sli_queue_is_empty(sli4_t *sli4, sli4_queue_t *q)
4912 uint8_t *qe = q->dma.virt;
4916 ocs_dma_sync(&q->dma, OCS_DMASYNC_POSTREAD);
4918 qe += q->index * q->size;
4920 rc = !sli_queue_entry_is_valid(q, qe, FALSE);
4922 ocs_unlock(&q->lock);
4931 * @param sli4 SLI context.
4932 * @param q Pointer to queue object.
4933 * @param arm If TRUE, arm the EQ.
4935 * @return Returns 0 on success, or non-zero otherwise.
4938 sli_queue_eq_arm(sli4_t *sli4, sli4_queue_t *q, uint8_t arm)
4943 val = sli_eq_doorbell(q->n_posted, q->id, arm);
4944 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4946 ocs_unlock(&q->lock);
4953 * @brief Arm a queue.
4955 * @param sli4 SLI context.
4956 * @param q Pointer to queue object.
4957 * @param arm If TRUE, arm the queue.
4959 * @return Returns 0 on success, or non-zero otherwise.
4962 sli_queue_arm(sli4_t *sli4, sli4_queue_t *q, uint8_t arm)
4970 val = sli_eq_doorbell(q->n_posted, q->id, arm);
4971 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4975 val = sli_cq_doorbell(q->n_posted, q->id, arm);
4976 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4980 ocs_log_test(sli4->os, "should only be used for EQ/CQ, not %s\n",
4981 SLI_QNAME[q->type]);
4984 ocs_unlock(&q->lock);
4991 * @brief Write an entry to the queue object.
4993 * Note: Assumes the q->lock will be locked and released by the caller.
4995 * @param sli4 SLI context.
4996 * @param q Pointer to the queue object.
4997 * @param entry Pointer to the entry contents.
4999 * @return Returns queue index on success, or negative error value otherwise.
5002 _sli_queue_write(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5005 uint8_t *qe = q->dma.virt;
5009 qe += q->index * q->size;
5012 if ((SLI_QTYPE_WQ == q->type) && sli4->config.perf_wq_id_association) {
5013 sli_set_wq_id_association(entry, q->id);
5015 #if defined(OCS_INCLUDE_DEBUG)
5017 case SLI_QTYPE_WQ: {
5018 ocs_dump32(OCS_DEBUG_ENABLE_WQ_DUMP, sli4->os, "wqe", entry, q->size);
5023 /* Note: we don't really need to dump the whole
5024 * 256 bytes, just do 64 */
5025 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, "mqe outbound", entry, 64);
5032 ocs_memcpy(qe, entry, q->size);
5036 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5038 rc = sli_queue_doorbell(sli4, q);
5040 q->index = (q->index + q->n_posted) & (q->length - 1);
5046 } else if (rc > 0) {
5047 /* failure, but we need to return a negative value on failure */
5056 * @brief Write an entry to the queue object.
5058 * Note: Assumes the q->lock will be locked and released by the caller.
5060 * @param sli4 SLI context.
5061 * @param q Pointer to the queue object.
5062 * @param entry Pointer to the entry contents.
5064 * @return Returns queue index on success, or negative error value otherwise.
5067 sli_queue_write(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5072 rc = _sli_queue_write(sli4, q, entry);
5073 ocs_unlock(&q->lock);
5079 * @brief Check if the current queue entry is valid.
5081 * @param q Pointer to the queue object.
5082 * @param qe Pointer to the queue entry.
5083 * @param clear Boolean to clear valid bit.
5085 * @return Returns TRUE if the entry is valid, or FALSE otherwise.
5088 sli_queue_entry_is_valid(sli4_queue_t *q, uint8_t *qe, uint8_t clear)
5090 uint8_t valid = FALSE;
5094 valid = ((sli4_eqe_t *)qe)->vld;
5095 if (valid && clear) {
5096 ((sli4_eqe_t *)qe)->vld = 0;
5101 * For both MCQE and WCQE/RCQE, the valid bit
5102 * is bit 31 of dword 3 (0 based)
5104 valid = (qe[15] & 0x80) != 0;
5105 if (valid & clear) {
5110 valid = q->index != q->u.r_idx;
5117 ocs_log_test(NULL, "doesn't handle type=%#x\n", q->type);
5121 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5129 * @brief Read an entry from the queue object.
5131 * @param sli4 SLI context.
5132 * @param q Pointer to the queue object.
5133 * @param entry Destination pointer for the queue entry contents.
5135 * @return Returns 0 on success, or non-zero otherwise.
5138 sli_queue_read(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5141 uint8_t *qe = q->dma.virt;
5142 uint32_t *qindex = NULL;
5144 if (SLI_QTYPE_MQ == q->type) {
5145 qindex = &q->u.r_idx;
5152 ocs_dma_sync(&q->dma, OCS_DMASYNC_POSTREAD);
5154 qe += *qindex * q->size;
5156 if (!sli_queue_entry_is_valid(q, qe, TRUE)) {
5157 ocs_unlock(&q->lock);
5162 ocs_memcpy(entry, qe, q->size);
5163 #if defined(OCS_INCLUDE_DEBUG)
5166 ocs_dump32(OCS_DEBUG_ENABLE_CQ_DUMP, sli4->os, "cq", entry, q->size);
5169 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, "mq Compl", entry, 64);
5172 ocs_dump32(OCS_DEBUG_ENABLE_EQ_DUMP, sli4->os, "eq Compl", entry, q->size);
5184 *qindex = (*qindex + 1) & (q->length - 1);
5185 if (SLI_QTYPE_MQ != q->type) {
5190 /* reads don't update the index */
5194 ocs_unlock(&q->lock);
5200 sli_queue_index(sli4_t *sli4, sli4_queue_t *q)
5211 sli_queue_poke(sli4_t *sli4, sli4_queue_t *q, uint32_t index, uint8_t *entry)
5216 rc = _sli_queue_poke(sli4, q, index, entry);
5217 ocs_unlock(&q->lock);
5223 _sli_queue_poke(sli4_t *sli4, sli4_queue_t *q, uint32_t index, uint8_t *entry)
5226 uint8_t *qe = q->dma.virt;
5228 if (index >= q->length) {
5232 qe += index * q->size;
5235 ocs_memcpy(qe, entry, q->size);
5238 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5245 * @brief Allocate SLI Port resources.
5248 * Allocate port-related resources, such as VFI, RPI, XRI, and so on.
5249 * Resources are modeled using extents, regardless of whether the underlying
5250 * device implements resource extents. If the device does not implement
5251 * extents, the SLI layer models this as a single (albeit large) extent.
5253 * @param sli4 SLI context.
5254 * @param rtype Resource type (for example, RPI or XRI)
5255 * @param rid Allocated resource ID.
5256 * @param index Index into the bitmap.
5258 * @return Returns 0 on success, or a non-zero value on failure.
5261 sli_resource_alloc(sli4_t *sli4, sli4_resource_e rtype, uint32_t *rid, uint32_t *index)
5265 uint32_t extent_idx;
5270 *index = UINT32_MAX;
5273 case SLI_RSRC_FCOE_VFI:
5274 case SLI_RSRC_FCOE_VPI:
5275 case SLI_RSRC_FCOE_RPI:
5276 case SLI_RSRC_FCOE_XRI:
5277 status = ocs_bitmap_find(sli4->config.extent[rtype].use_map,
5278 sli4->config.extent[rtype].map_size);
5280 ocs_log_err(sli4->os, "out of resource %d (alloc=%d)\n",
5281 rtype, sli4->config.extent[rtype].n_alloc);
5288 size = sli4->config.extent[rtype].size;
5290 extent_idx = *index / size;
5291 item_idx = *index % size;
5293 *rid = sli4->config.extent[rtype].base[extent_idx] + item_idx;
5295 sli4->config.extent[rtype].n_alloc++;
5306 * @brief Free the SLI Port resources.
5309 * Free port-related resources, such as VFI, RPI, XRI, and so. See discussion of
5310 * "extent" usage in sli_resource_alloc.
5312 * @param sli4 SLI context.
5313 * @param rtype Resource type (for example, RPI or XRI).
5314 * @param rid Allocated resource ID.
5316 * @return Returns 0 on success, or a non-zero value on failure.
5319 sli_resource_free(sli4_t *sli4, sli4_resource_e rtype, uint32_t rid)
5323 uint32_t size, *base;
5326 case SLI_RSRC_FCOE_VFI:
5327 case SLI_RSRC_FCOE_VPI:
5328 case SLI_RSRC_FCOE_RPI:
5329 case SLI_RSRC_FCOE_XRI:
5331 * Figure out which extent contains the resource ID. I.e. find
5332 * the extent such that
5333 * extent->base <= resource ID < extent->base + extent->size
5335 base = sli4->config.extent[rtype].base;
5336 size = sli4->config.extent[rtype].size;
5339 * In the case of FW reset, this may be cleared but the force_free path will
5340 * still attempt to free the resource. Prevent a NULL pointer access.
5343 for (x = 0; x < sli4->config.extent[rtype].number; x++) {
5344 if ((rid >= base[x]) && (rid < (base[x] + size))) {
5346 ocs_bitmap_clear(sli4->config.extent[rtype].use_map,
5362 sli_resource_reset(sli4_t *sli4, sli4_resource_e rtype)
5368 case SLI_RSRC_FCOE_VFI:
5369 case SLI_RSRC_FCOE_VPI:
5370 case SLI_RSRC_FCOE_RPI:
5371 case SLI_RSRC_FCOE_XRI:
5372 for (i = 0; i < sli4->config.extent[rtype].map_size; i++) {
5373 ocs_bitmap_clear(sli4->config.extent[rtype].use_map, i);
5386 * @brief Parse an EQ entry to retrieve the CQ_ID for this event.
5388 * @param sli4 SLI context.
5389 * @param buf Pointer to the EQ entry.
5390 * @param cq_id CQ_ID for this entry (only valid on success).
5395 * - > 0 if firmware detects EQ overflow.
5398 sli_eq_parse(sli4_t *sli4, uint8_t *buf, uint16_t *cq_id)
5400 sli4_eqe_t *eqe = (void *)buf;
5403 if (!sli4 || !buf || !cq_id) {
5404 ocs_log_err(NULL, "bad parameters sli4=%p buf=%p cq_id=%p\n",
5409 switch (eqe->major_code) {
5410 case SLI4_MAJOR_CODE_STANDARD:
5411 *cq_id = eqe->resource_id;
5413 case SLI4_MAJOR_CODE_SENTINEL:
5414 ocs_log_debug(sli4->os, "sentinel EQE\n");
5418 ocs_log_test(sli4->os, "Unsupported EQE: major %x minor %x\n",
5419 eqe->major_code, eqe->minor_code);
5428 * @brief Parse a CQ entry to retrieve the event type and the associated queue.
5430 * @param sli4 SLI context.
5431 * @param cq CQ to process.
5432 * @param cqe Pointer to the CQ entry.
5433 * @param etype CQ event type.
5434 * @param q_id Queue ID associated with this completion message
5435 * (that is, MQ_ID, RQ_ID, and so on).
5438 * - 0 if call completed correctly and CQE status is SUCCESS.
5439 * - -1 if call failed (no CQE status).
5440 * - Other value if call completed correctly and return value is a CQE status value.
5443 sli_cq_parse(sli4_t *sli4, sli4_queue_t *cq, uint8_t *cqe, sli4_qentry_e *etype,
5448 if (!sli4 || !cq || !cqe || !etype) {
5449 ocs_log_err(NULL, "bad parameters sli4=%p cq=%p cqe=%p etype=%p q_id=%p\n",
5450 sli4, cq, cqe, etype, q_id);
5454 if (cq->u.flag.is_mq) {
5455 sli4_mcqe_t *mcqe = (void *)cqe;
5458 *etype = SLI_QENTRY_ASYNC;
5460 *etype = SLI_QENTRY_MQ;
5461 rc = sli_cqe_mq(mcqe);
5464 } else if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5465 rc = sli_fc_cqe_parse(sli4, cq, cqe, etype, q_id);
5467 ocs_log_test(sli4->os, "implement CQE parsing type = %#x\n",
5477 * @brief Cause chip to enter an unrecoverable error state.
5480 * Cause chip to enter an unrecoverable error state. This is
5481 * used when detecting unexpected FW behavior so FW can be
5482 * hwted from the driver as soon as error is detected.
5484 * @param sli4 SLI context.
5485 * @param dump Generate dump as part of reset.
5487 * @return Returns 0 if call completed correctly, or -1 if call failed (unsupported chip).
5489 int32_t sli_raise_ue(sli4_t *sli4, uint8_t dump)
5492 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5493 switch(sli_get_asic_type(sli4)) {
5494 case SLI4_ASIC_TYPE_BE3: {
5495 sli_reg_write(sli4, SLI4_REG_SW_UE_CSR1, 0xffffffff);
5496 sli_reg_write(sli4, SLI4_REG_SW_UE_CSR2, 0);
5499 case SLI4_ASIC_TYPE_SKYHAWK: {
5501 value = ocs_config_read32(sli4->os, SLI4_SW_UE_REG);
5502 ocs_config_write32(sli4->os, SLI4_SW_UE_REG, (value | (1U << 24)));
5506 ocs_log_test(sli4->os, "invalid asic type %d\n", sli_get_asic_type(sli4));
5509 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli_get_if_type(sli4)) {
5511 sli_reg_write(sli4, SLI4_REG_SLIPORT_CONTROL, SLI4_SLIPORT_CONTROL_FDD | SLI4_SLIPORT_CONTROL_IP);
5513 uint32_t value = SLI4_PHYDEV_CONTROL_FRST;
5515 value |= SLI4_PHYDEV_CONTROL_DD;
5517 sli_reg_write(sli4, SLI4_REG_PHYSDEV_CONTROL, value);
5520 ocs_log_test(sli4->os, "invalid iftype=%d\n", sli_get_if_type(sli4));
5528 * @brief Read the SLIPORT_STATUS register to to check if a dump is present.
5530 * @param sli4 SLI context.
5532 * @return Returns 1 if the chip is ready, or 0 if the chip is not ready, 2 if fdp is present.
5534 int32_t sli_dump_is_ready(sli4_t *sli4)
5541 uint32_t uerr_mask_lo;
5542 uint32_t uerr_mask_hi;
5544 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5545 /* for iftype=0, dump ready when UE is encountered */
5546 uerr_lo = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_LO);
5547 uerr_hi = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_HI);
5548 uerr_mask_lo = sli_reg_read(sli4, SLI4_REG_UERR_MASK_LO);
5549 uerr_mask_hi = sli_reg_read(sli4, SLI4_REG_UERR_MASK_HI);
5550 if ((uerr_lo & ~uerr_mask_lo) || (uerr_hi & ~uerr_mask_hi)) {
5554 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli_get_if_type(sli4)) {
5556 * Ensure that the port is ready AND the mailbox is
5557 * ready before signaling that the dump is ready to go.
5559 port_val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5560 bmbx_val = sli_reg_read(sli4, SLI4_REG_BMBX);
5562 if ((bmbx_val & SLI4_BMBX_RDY) &&
5563 SLI4_PORT_STATUS_READY(port_val)) {
5564 if(SLI4_PORT_STATUS_DUMP_PRESENT(port_val)) {
5566 }else if( SLI4_PORT_STATUS_FDP_PRESENT(port_val)) {
5571 ocs_log_test(sli4->os, "invalid iftype=%d\n", sli_get_if_type(sli4));
5579 * @brief Read the SLIPORT_STATUS register to check if a dump is present.
5581 * @param sli4 SLI context.
5584 * - 0 if call completed correctly and no dump is present.
5585 * - 1 if call completed and dump is present.
5586 * - -1 if call failed (unsupported chip).
5588 int32_t sli_dump_is_present(sli4_t *sli4)
5593 if (SLI4_IF_TYPE_LANCER_FC_ETH != sli_get_if_type(sli4)) {
5594 ocs_log_test(sli4->os, "Function only supported for I/F type 2");
5598 /* If the chip is not ready, then there cannot be a dump */
5599 ready = sli_wait_for_fw_ready(sli4, SLI4_INIT_PORT_DELAY_US);
5604 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5605 if (UINT32_MAX == val) {
5606 ocs_log_err(sli4->os, "error reading SLIPORT_STATUS\n");
5609 return ((val & SLI4_PORT_STATUS_DIP) ? 1 : 0);
5615 * @brief Read the SLIPORT_STATUS register to check if the reset required is set.
5617 * @param sli4 SLI context.
5620 * - 0 if call completed correctly and reset is not required.
5621 * - 1 if call completed and reset is required.
5622 * - -1 if call failed.
5624 int32_t sli_reset_required(sli4_t *sli4)
5628 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5629 ocs_log_test(sli4->os, "reset required N/A for iftype 0\n");
5633 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5634 if (UINT32_MAX == val) {
5635 ocs_log_err(sli4->os, "error reading SLIPORT_STATUS\n");
5638 return ((val & SLI4_PORT_STATUS_RN) ? 1 : 0);
5644 * @brief Read the SLIPORT_SEMAPHORE and SLIPORT_STATUS registers to check if
5645 * the port status indicates that a FW error has occurred.
5647 * @param sli4 SLI context.
5650 * - 0 if call completed correctly and no FW error occurred.
5651 * - > 0 which indicates that a FW error has occurred.
5652 * - -1 if call failed.
5654 int32_t sli_fw_error_status(sli4_t *sli4)
5656 uint32_t sliport_semaphore;
5659 sliport_semaphore = sli_reg_read(sli4, SLI4_REG_SLIPORT_SEMAPHORE);
5660 if (UINT32_MAX == sliport_semaphore) {
5661 ocs_log_err(sli4->os, "error reading SLIPORT_SEMAPHORE register\n");
5664 rc = (SLI4_PORT_SEMAPHORE_IN_ERR(sliport_semaphore) ? 1 : 0);
5667 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type ||
5668 (SLI4_IF_TYPE_BE3_SKH_VF == sli4->if_type)) {
5669 uint32_t uerr_mask_lo, uerr_mask_hi;
5670 uint32_t uerr_status_lo, uerr_status_hi;
5672 uerr_mask_lo = sli_reg_read(sli4, SLI4_REG_UERR_MASK_LO);
5673 uerr_mask_hi = sli_reg_read(sli4, SLI4_REG_UERR_MASK_HI);
5674 uerr_status_lo = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_LO);
5675 uerr_status_hi = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_HI);
5676 if ((uerr_mask_lo & uerr_status_lo) != 0 ||
5677 (uerr_mask_hi & uerr_status_hi) != 0) {
5680 } else if ((SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type)) {
5681 uint32_t sliport_status;
5683 sliport_status = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5684 rc = (SLI4_PORT_STATUS_ERROR(sliport_status) ? 1 : 0);
5692 * @brief Determine if the chip FW is in a ready state
5694 * @param sli4 SLI context.
5697 * - 0 if call completed correctly and FW is not ready.
5698 * - 1 if call completed correctly and FW is ready.
5699 * - -1 if call failed.
5702 sli_fw_ready(sli4_t *sli4)
5708 * Is firmware ready for operation? Check needed depends on IF_TYPE
5710 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type ||
5711 SLI4_IF_TYPE_BE3_SKH_VF == sli4->if_type) {
5712 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_SEMAPHORE);
5713 rc = ((SLI4_PORT_SEMAPHORE_STATUS_POST_READY ==
5714 SLI4_PORT_SEMAPHORE_PORT(val)) &&
5715 (!SLI4_PORT_SEMAPHORE_IN_ERR(val)) ? 1 : 0);
5716 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type) {
5717 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5718 rc = (SLI4_PORT_STATUS_READY(val) ? 1 : 0);
5725 * @brief Determine if the link can be configured
5727 * @param sli4 SLI context.
5730 * - 0 if link is not configurable.
5731 * - 1 if link is configurable.
5733 int32_t sli_link_is_configurable(sli4_t *sli)
5737 * Link config works on: Skyhawk and Lancer
5738 * Link config does not work on: LancerG6
5741 switch (sli_get_asic_type(sli)) {
5742 case SLI4_ASIC_TYPE_SKYHAWK:
5743 case SLI4_ASIC_TYPE_LANCER:
5744 case SLI4_ASIC_TYPE_CORSAIR:
5747 case SLI4_ASIC_TYPE_LANCERG6:
5748 case SLI4_ASIC_TYPE_BE3:
5758 /* vim: set noexpandtab textwidth=120: */
5762 * @brief Write an FCOE_WQ_CREATE command.
5764 * @param sli4 SLI context.
5765 * @param buf Destination buffer for the command.
5766 * @param size Buffer size, in bytes.
5767 * @param qmem DMA memory for the queue.
5768 * @param cq_id Associated CQ_ID.
5769 * @param ulp The ULP to bind
5771 * @note This creates a Version 0 message.
5773 * @return Returns the number of bytes written.
5776 sli_cmd_fcoe_wq_create(sli4_t *sli4, void *buf, size_t size,
5777 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp)
5779 sli4_req_fcoe_wq_create_t *wq = NULL;
5780 uint32_t sli_config_off = 0;
5784 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5785 uint32_t payload_size;
5787 /* Payload length must accommodate both request and response */
5788 payload_size = max(sizeof(sli4_req_fcoe_wq_create_t),
5789 sizeof(sli4_res_common_create_queue_t));
5791 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5794 wq = (sli4_req_fcoe_wq_create_t *)((uint8_t *)buf + sli_config_off);
5796 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_CREATE;
5797 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5798 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_create_t) -
5799 sizeof(sli4_req_hdr_t);
5800 /* valid values for number of pages: 1-4 (sec 4.5.1) */
5801 wq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
5802 if (!wq->num_pages || (wq->num_pages > SLI4_FCOE_WQ_CREATE_V0_MAX_PAGES)) {
5808 if (sli4->config.dual_ulp_capable) {
5814 for (p = 0, addr = qmem->phys;
5816 p++, addr += SLI_PAGE_SIZE) {
5817 wq->page_physical_address[p].low = ocs_addr32_lo(addr);
5818 wq->page_physical_address[p].high = ocs_addr32_hi(addr);
5821 return(sli_config_off + sizeof(sli4_req_fcoe_wq_create_t));
5826 * @brief Write an FCOE_WQ_CREATE_V1 command.
5828 * @param sli4 SLI context.
5829 * @param buf Destination buffer for the command.
5830 * @param size Buffer size, in bytes.
5831 * @param qmem DMA memory for the queue.
5832 * @param cq_id Associated CQ_ID.
5833 * @param ignored This parameter carries the ULP for WQ (ignored for V1)
5836 * @return Returns the number of bytes written.
5839 sli_cmd_fcoe_wq_create_v1(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *qmem,
5840 uint16_t cq_id, uint16_t ignored)
5842 sli4_req_fcoe_wq_create_v1_t *wq = NULL;
5843 uint32_t sli_config_off = 0;
5846 uint32_t page_size = 0;
5847 uint32_t page_bytes = 0;
5850 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5851 uint32_t payload_size;
5853 /* Payload length must accommodate both request and response */
5854 payload_size = max(sizeof(sli4_req_fcoe_wq_create_v1_t),
5855 sizeof(sli4_res_common_create_queue_t));
5857 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5860 wq = (sli4_req_fcoe_wq_create_v1_t *)((uint8_t *)buf + sli_config_off);
5862 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_CREATE;
5863 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5864 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_create_v1_t) -
5865 sizeof(sli4_req_hdr_t);
5866 wq->hdr.version = 1;
5868 n_wqe = qmem->size / sli4->config.wqe_size;
5870 /* This heuristic to determine the page size is simplistic
5871 * but could be made more sophisticated
5873 switch (qmem->size) {
5895 page_bytes = page_size * SLI_PAGE_SIZE;
5897 /* valid values for number of pages: 1-8 */
5898 wq->num_pages = sli_page_count(qmem->size, page_bytes);
5899 if (!wq->num_pages || (wq->num_pages > SLI4_FCOE_WQ_CREATE_V1_MAX_PAGES)) {
5905 wq->page_size = page_size;
5907 if (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) {
5908 wq->wqe_size = SLI4_WQE_EXT_SIZE;
5910 wq->wqe_size = SLI4_WQE_SIZE;
5913 wq->wqe_count = n_wqe;
5915 for (p = 0, addr = qmem->phys;
5917 p++, addr += page_bytes) {
5918 wq->page_physical_address[p].low = ocs_addr32_lo(addr);
5919 wq->page_physical_address[p].high = ocs_addr32_hi(addr);
5922 return(sli_config_off + sizeof(sli4_req_fcoe_wq_create_v1_t));
5927 * @brief Write an FCOE_WQ_DESTROY command.
5929 * @param sli4 SLI context.
5930 * @param buf Destination buffer for the command.
5931 * @param size Buffer size, in bytes.
5932 * @param wq_id WQ_ID.
5934 * @return Returns the number of bytes written.
5937 sli_cmd_fcoe_wq_destroy(sli4_t *sli4, void *buf, size_t size, uint16_t wq_id)
5939 sli4_req_fcoe_wq_destroy_t *wq = NULL;
5940 uint32_t sli_config_off = 0;
5942 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5943 uint32_t payload_size;
5945 /* Payload length must accommodate both request and response */
5946 payload_size = max(sizeof(sli4_req_fcoe_wq_destroy_t),
5947 sizeof(sli4_res_hdr_t));
5949 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5952 wq = (sli4_req_fcoe_wq_destroy_t *)((uint8_t *)buf + sli_config_off);
5954 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_DESTROY;
5955 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5956 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_destroy_t) -
5957 sizeof(sli4_req_hdr_t);
5961 return(sli_config_off + sizeof(sli4_req_fcoe_wq_destroy_t));
5966 * @brief Write an FCOE_POST_SGL_PAGES command.
5968 * @param sli4 SLI context.
5969 * @param buf Destination buffer for the command.
5970 * @param size Buffer size, in bytes.
5971 * @param xri starting XRI
5972 * @param xri_count XRI
5973 * @param page0 First SGL memory page.
5974 * @param page1 Second SGL memory page (optional).
5975 * @param dma DMA buffer for non-embedded mailbox command (options)
5977 * if non-embedded mbx command is used, dma buffer must be at least (32 + xri_count*16) in length
5979 * @return Returns the number of bytes written.
5982 sli_cmd_fcoe_post_sgl_pages(sli4_t *sli4, void *buf, size_t size,
5983 uint16_t xri, uint32_t xri_count, ocs_dma_t *page0[], ocs_dma_t *page1[], ocs_dma_t *dma)
5985 sli4_req_fcoe_post_sgl_pages_t *post = NULL;
5986 uint32_t sli_config_off = 0;
5989 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5990 uint32_t payload_size;
5992 /* Payload length must accommodate both request and response */
5993 payload_size = max(sizeof(sli4_req_fcoe_post_sgl_pages_t),
5994 sizeof(sli4_res_hdr_t));
5996 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6001 ocs_memset(post, 0, dma->size);
6003 post = (sli4_req_fcoe_post_sgl_pages_t *)((uint8_t *)buf + sli_config_off);
6006 post->hdr.opcode = SLI4_OPC_FCOE_POST_SGL_PAGES;
6007 post->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6008 /* payload size calculation
6009 * 4 = xri_start + xri_count
6010 * xri_count = # of XRI's registered
6011 * sizeof(uint64_t) = physical address size
6012 * 2 = # of physical addresses per page set
6014 post->hdr.request_length = 4 + (xri_count * (sizeof(uint64_t) * 2));
6016 post->xri_start = xri;
6017 post->xri_count = xri_count;
6019 for (i = 0; i < xri_count; i++) {
6020 post->page_set[i].page0_low = ocs_addr32_lo(page0[i]->phys);
6021 post->page_set[i].page0_high = ocs_addr32_hi(page0[i]->phys);
6025 for (i = 0; i < xri_count; i++) {
6026 post->page_set[i].page1_low = ocs_addr32_lo(page1[i]->phys);
6027 post->page_set[i].page1_high = ocs_addr32_hi(page1[i]->phys);
6031 return dma ? sli_config_off : (sli_config_off + sizeof(sli4_req_fcoe_post_sgl_pages_t));
6036 * @brief Write an FCOE_RQ_CREATE command.
6038 * @param sli4 SLI context.
6039 * @param buf Destination buffer for the command.
6040 * @param size Buffer size, in bytes.
6041 * @param qmem DMA memory for the queue.
6042 * @param cq_id Associated CQ_ID.
6043 * @param ulp This parameter carries the ULP for the RQ
6044 * @param buffer_size Buffer size pointed to by each RQE.
6046 * @note This creates a Version 0 message.
6048 * @return Returns the number of bytes written.
6051 sli_cmd_fcoe_rq_create(sli4_t *sli4, void *buf, size_t size,
6052 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp, uint16_t buffer_size)
6054 sli4_req_fcoe_rq_create_t *rq = NULL;
6055 uint32_t sli_config_off = 0;
6059 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6060 uint32_t payload_size;
6062 /* Payload length must accommodate both request and response */
6063 payload_size = max(sizeof(sli4_req_fcoe_rq_create_t),
6064 sizeof(sli4_res_common_create_queue_t));
6066 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6069 rq = (sli4_req_fcoe_rq_create_t *)((uint8_t *)buf + sli_config_off);
6071 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
6072 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6073 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_t) -
6074 sizeof(sli4_req_hdr_t);
6075 /* valid values for number of pages: 1-8 (sec 4.5.6) */
6076 rq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
6077 if (!rq->num_pages || (rq->num_pages > SLI4_FCOE_RQ_CREATE_V0_MAX_PAGES)) {
6078 ocs_log_test(sli4->os, "num_pages %d not valid\n", rq->num_pages);
6083 * RQE count is the log base 2 of the total number of entries
6085 rq->rqe_count = ocs_lg2(qmem->size / SLI4_FCOE_RQE_SIZE);
6087 if ((buffer_size < SLI4_FCOE_RQ_CREATE_V0_MIN_BUF_SIZE) ||
6088 (buffer_size > SLI4_FCOE_RQ_CREATE_V0_MAX_BUF_SIZE)) {
6089 ocs_log_err(sli4->os, "buffer_size %d out of range (%d-%d)\n",
6091 SLI4_FCOE_RQ_CREATE_V0_MIN_BUF_SIZE,
6092 SLI4_FCOE_RQ_CREATE_V0_MAX_BUF_SIZE);
6095 rq->buffer_size = buffer_size;
6099 if (sli4->config.dual_ulp_capable) {
6105 for (p = 0, addr = qmem->phys;
6107 p++, addr += SLI_PAGE_SIZE) {
6108 rq->page_physical_address[p].low = ocs_addr32_lo(addr);
6109 rq->page_physical_address[p].high = ocs_addr32_hi(addr);
6112 return(sli_config_off + sizeof(sli4_req_fcoe_rq_create_t));
6117 * @brief Write an FCOE_RQ_CREATE_V1 command.
6119 * @param sli4 SLI context.
6120 * @param buf Destination buffer for the command.
6121 * @param size Buffer size, in bytes.
6122 * @param qmem DMA memory for the queue.
6123 * @param cq_id Associated CQ_ID.
6124 * @param ulp This parameter carries the ULP for RQ (ignored for V1)
6125 * @param buffer_size Buffer size pointed to by each RQE.
6127 * @note This creates a Version 0 message
6129 * @return Returns the number of bytes written.
6132 sli_cmd_fcoe_rq_create_v1(sli4_t *sli4, void *buf, size_t size,
6133 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp,
6134 uint16_t buffer_size)
6136 sli4_req_fcoe_rq_create_v1_t *rq = NULL;
6137 uint32_t sli_config_off = 0;
6141 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6142 uint32_t payload_size;
6144 /* Payload length must accommodate both request and response */
6145 payload_size = max(sizeof(sli4_req_fcoe_rq_create_v1_t),
6146 sizeof(sli4_res_common_create_queue_t));
6148 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6151 rq = (sli4_req_fcoe_rq_create_v1_t *)((uint8_t *)buf + sli_config_off);
6153 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
6154 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6155 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_v1_t) -
6156 sizeof(sli4_req_hdr_t);
6157 rq->hdr.version = 1;
6159 /* Disable "no buffer warnings" to avoid Lancer bug */
6162 /* valid values for number of pages: 1-8 (sec 4.5.6) */
6163 rq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
6164 if (!rq->num_pages || (rq->num_pages > SLI4_FCOE_RQ_CREATE_V1_MAX_PAGES)) {
6165 ocs_log_test(sli4->os, "num_pages %d not valid, max %d\n",
6166 rq->num_pages, SLI4_FCOE_RQ_CREATE_V1_MAX_PAGES);
6171 * RQE count is the total number of entries (note not lg2(# entries))
6173 rq->rqe_count = qmem->size / SLI4_FCOE_RQE_SIZE;
6175 rq->rqe_size = SLI4_FCOE_RQE_SIZE_8;
6177 rq->page_size = SLI4_FCOE_RQ_PAGE_SIZE_4096;
6179 if ((buffer_size < sli4->config.rq_min_buf_size) ||
6180 (buffer_size > sli4->config.rq_max_buf_size)) {
6181 ocs_log_err(sli4->os, "buffer_size %d out of range (%d-%d)\n",
6183 sli4->config.rq_min_buf_size,
6184 sli4->config.rq_max_buf_size);
6187 rq->buffer_size = buffer_size;
6191 for (p = 0, addr = qmem->phys;
6193 p++, addr += SLI_PAGE_SIZE) {
6194 rq->page_physical_address[p].low = ocs_addr32_lo(addr);
6195 rq->page_physical_address[p].high = ocs_addr32_hi(addr);
6198 return(sli_config_off + sizeof(sli4_req_fcoe_rq_create_v1_t));
6203 * @brief Write an FCOE_RQ_DESTROY command.
6205 * @param sli4 SLI context.
6206 * @param buf Destination buffer for the command.
6207 * @param size Buffer size, in bytes.
6208 * @param rq_id RQ_ID.
6210 * @return Returns the number of bytes written.
6213 sli_cmd_fcoe_rq_destroy(sli4_t *sli4, void *buf, size_t size, uint16_t rq_id)
6215 sli4_req_fcoe_rq_destroy_t *rq = NULL;
6216 uint32_t sli_config_off = 0;
6218 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6219 uint32_t payload_size;
6221 /* Payload length must accommodate both request and response */
6222 payload_size = max(sizeof(sli4_req_fcoe_rq_destroy_t),
6223 sizeof(sli4_res_hdr_t));
6225 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6228 rq = (sli4_req_fcoe_rq_destroy_t *)((uint8_t *)buf + sli_config_off);
6230 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_DESTROY;
6231 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6232 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_destroy_t) -
6233 sizeof(sli4_req_hdr_t);
6237 return(sli_config_off + sizeof(sli4_req_fcoe_rq_destroy_t));
6242 * @brief Write an FCOE_READ_FCF_TABLE command.
6245 * The response of this command exceeds the size of an embedded
6246 * command and requires an external buffer with DMA capability to hold the results.
6247 * The caller should allocate the ocs_dma_t structure / memory.
6249 * @param sli4 SLI context.
6250 * @param buf Destination buffer for the command.
6251 * @param size Buffer size, in bytes.
6252 * @param dma Pointer to DMA memory structure. This is allocated by the caller.
6253 * @param index FCF table index to retrieve.
6255 * @return Returns the number of bytes written.
6258 sli_cmd_fcoe_read_fcf_table(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma, uint16_t index)
6260 sli4_req_fcoe_read_fcf_table_t *read_fcf = NULL;
6262 if (SLI4_PORT_TYPE_FC != sli4->port_type) {
6263 ocs_log_test(sli4->os, "FCOE_READ_FCF_TABLE only supported on FC\n");
6267 read_fcf = dma->virt;
6269 ocs_memset(read_fcf, 0, sizeof(sli4_req_fcoe_read_fcf_table_t));
6271 read_fcf->hdr.opcode = SLI4_OPC_FCOE_READ_FCF_TABLE;
6272 read_fcf->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6273 read_fcf->hdr.request_length = dma->size -
6274 sizeof(sli4_req_fcoe_read_fcf_table_t);
6275 read_fcf->fcf_index = index;
6277 return sli_cmd_sli_config(sli4, buf, size, 0, dma);
6282 * @brief Write an FCOE_POST_HDR_TEMPLATES command.
6284 * @param sli4 SLI context.
6285 * @param buf Destination buffer for the command.
6286 * @param size Buffer size, in bytes.
6287 * @param dma Pointer to DMA memory structure. This is allocated by the caller.
6288 * @param rpi Starting RPI index for the header templates.
6289 * @param payload_dma Pointer to DMA memory used to hold larger descriptor counts.
6291 * @return Returns the number of bytes written.
6294 sli_cmd_fcoe_post_hdr_templates(sli4_t *sli4, void *buf, size_t size,
6295 ocs_dma_t *dma, uint16_t rpi, ocs_dma_t *payload_dma)
6297 sli4_req_fcoe_post_hdr_templates_t *template = NULL;
6298 uint32_t sli_config_off = 0;
6301 uint32_t page_count;
6302 uint32_t payload_size;
6304 page_count = sli_page_count(dma->size, SLI_PAGE_SIZE);
6306 payload_size = sizeof(sli4_req_fcoe_post_hdr_templates_t) +
6307 page_count * sizeof(sli4_physical_page_descriptor_t);
6309 if (page_count > 16) {
6310 /* We can't fit more than 16 descriptors into an embedded mailbox
6311 command, it has to be non-embedded */
6312 if (ocs_dma_alloc(sli4->os, payload_dma, payload_size, 4)) {
6313 ocs_log_err(sli4->os, "mailbox payload memory allocation fail\n");
6316 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size, payload_dma);
6317 template = (sli4_req_fcoe_post_hdr_templates_t *)payload_dma->virt;
6319 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size, NULL);
6320 template = (sli4_req_fcoe_post_hdr_templates_t *)((uint8_t *)buf + sli_config_off);
6323 if (UINT16_MAX == rpi) {
6324 rpi = sli4->config.extent[SLI_RSRC_FCOE_RPI].base[0];
6327 template->hdr.opcode = SLI4_OPC_FCOE_POST_HDR_TEMPLATES;
6328 template->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6329 template->hdr.request_length = sizeof(sli4_req_fcoe_post_hdr_templates_t) -
6330 sizeof(sli4_req_hdr_t);
6332 template->rpi_offset = rpi;
6333 template->page_count = page_count;
6335 for (i = 0; i < template->page_count; i++) {
6336 template->page_descriptor[i].low = ocs_addr32_lo(phys);
6337 template->page_descriptor[i].high = ocs_addr32_hi(phys);
6339 phys += SLI_PAGE_SIZE;
6342 return(sli_config_off + payload_size);
6346 sli_cmd_fcoe_rediscover_fcf(sli4_t *sli4, void *buf, size_t size, uint16_t index)
6348 sli4_req_fcoe_rediscover_fcf_t *redisc = NULL;
6349 uint32_t sli_config_off = 0;
6351 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
6352 sizeof(sli4_req_fcoe_rediscover_fcf_t),
6355 redisc = (sli4_req_fcoe_rediscover_fcf_t *)((uint8_t *)buf + sli_config_off);
6357 redisc->hdr.opcode = SLI4_OPC_FCOE_REDISCOVER_FCF;
6358 redisc->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6359 redisc->hdr.request_length = sizeof(sli4_req_fcoe_rediscover_fcf_t) -
6360 sizeof(sli4_req_hdr_t);
6362 if (index == UINT16_MAX) {
6363 redisc->fcf_count = 0;
6365 redisc->fcf_count = 1;
6366 redisc->fcf_index[0] = index;
6369 return(sli_config_off + sizeof(sli4_req_fcoe_rediscover_fcf_t));
6374 * @brief Write an ABORT_WQE work queue entry.
6376 * @param sli4 SLI context.
6377 * @param buf Destination buffer for the WQE.
6378 * @param size Buffer size, in bytes.
6379 * @param type Abort type, such as XRI, abort tag, and request tag.
6380 * @param send_abts Boolean to cause the hardware to automatically generate an ABTS.
6381 * @param ids ID of IOs to abort.
6382 * @param mask Mask applied to the ID values to abort.
6383 * @param tag Tag value associated with this abort.
6384 * @param cq_id The id of the completion queue where the WQE response is sent.
6385 * @param dnrx When set to 1, this field indicates that the SLI Port must not return the associated XRI to the SLI
6386 * Port's optimized write XRI pool.
6388 * @return Returns 0 on success, or a non-zero value on failure.
6391 sli_abort_wqe(sli4_t *sli4, void *buf, size_t size, sli4_abort_type_e type, uint32_t send_abts,
6392 uint32_t ids, uint32_t mask, uint16_t tag, uint16_t cq_id)
6394 sli4_abort_wqe_t *abort = buf;
6396 ocs_memset(buf, 0, size);
6400 abort->criteria = SLI4_ABORT_CRITERIA_XRI_TAG;
6402 ocs_log_warn(sli4->os, "warning non-zero mask %#x when aborting XRI %#x\n", mask, ids);
6406 case SLI_ABORT_ABORT_ID:
6407 abort->criteria = SLI4_ABORT_CRITERIA_ABORT_TAG;
6409 case SLI_ABORT_REQUEST_ID:
6410 abort->criteria = SLI4_ABORT_CRITERIA_REQUEST_TAG;
6413 ocs_log_test(sli4->os, "unsupported type %#x\n", type);
6417 abort->ia = send_abts ? 0 : 1;
6419 /* Suppress ABTS retries */
6422 abort->t_mask = mask;
6424 abort->command = SLI4_WQE_ABORT;
6425 abort->request_tag = tag;
6427 abort->cq_id = cq_id;
6428 abort->cmd_type = SLI4_CMD_ABORT_WQE;
6435 * @brief Write an ELS_REQUEST64_WQE work queue entry.
6437 * @param sli4 SLI context.
6438 * @param buf Destination buffer for the WQE.
6439 * @param size Buffer size, in bytes.
6440 * @param sgl DMA memory for the ELS request.
6441 * @param req_type ELS request type.
6442 * @param req_len Length of ELS request in bytes.
6443 * @param max_rsp_len Max length of ELS response in bytes.
6444 * @param timeout Time, in seconds, before an IO times out. Zero means 2 * R_A_TOV.
6445 * @param xri XRI for this exchange.
6446 * @param tag IO tag value.
6447 * @param cq_id The id of the completion queue where the WQE response is sent.
6448 * @param rnode Destination of ELS request (that is, the remote node).
6450 * @return Returns 0 on success, or a non-zero value on failure.
6453 sli_els_request64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint8_t req_type,
6454 uint32_t req_len, uint32_t max_rsp_len, uint8_t timeout,
6455 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode)
6457 sli4_els_request64_wqe_t *els = buf;
6458 sli4_sge_t *sge = sgl->virt;
6459 uint8_t is_fabric = FALSE;
6461 ocs_memset(buf, 0, size);
6463 if (sli4->config.sgl_pre_registered) {
6467 els->els_request_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
6469 els->els_request_payload.buffer_length = req_len;
6470 els->els_request_payload.u.data.buffer_address_low = sge[0].buffer_address_low;
6471 els->els_request_payload.u.data.buffer_address_high = sge[0].buffer_address_high;
6475 els->els_request_payload.bde_type = SLI4_BDE_TYPE_BLP;
6477 els->els_request_payload.buffer_length = 2 * sizeof(sli4_sge_t);
6478 els->els_request_payload.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6479 els->els_request_payload.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6482 els->els_request_payload_length = req_len;
6483 els->max_response_payload_length = max_rsp_len;
6486 els->timer = timeout;
6487 els->class = SLI4_ELS_REQUEST64_CLASS_3;
6489 els->command = SLI4_WQE_ELS_REQUEST64;
6491 els->request_tag = tag;
6493 if (rnode->node_group) {
6495 els->remote_id = rnode->fc_id & 0x00ffffff;
6498 els->iod = SLI4_ELS_REQUEST64_DIR_READ;
6502 /* figure out the ELS_ID value from the request buffer */
6505 case FC_ELS_CMD_LOGO:
6506 els->els_id = SLI4_ELS_REQUEST64_LOGO;
6507 if (rnode->attached) {
6508 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6509 els->context_tag = rnode->indicator;
6511 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6512 els->context_tag = rnode->sport->indicator;
6514 if (FC_ADDR_FABRIC == rnode->fc_id) {
6518 case FC_ELS_CMD_FDISC:
6519 if (FC_ADDR_FABRIC == rnode->fc_id) {
6522 if (0 == rnode->sport->fc_id) {
6523 els->els_id = SLI4_ELS_REQUEST64_FDISC;
6526 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6528 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6529 els->context_tag = rnode->sport->indicator;
6532 case FC_ELS_CMD_FLOGI:
6533 els->els_id = SLI4_ELS_REQUEST64_FLOGIN;
6535 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
6536 if (!rnode->sport->domain) {
6537 ocs_log_test(sli4->os, "invalid domain handle\n");
6541 * IF_TYPE 0 skips INIT_VFI/INIT_VPI and therefore must use the
6544 els->ct = SLI4_ELS_REQUEST64_CONTEXT_FCFI;
6545 els->context_tag = rnode->sport->domain->fcf_indicator;
6548 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6549 els->context_tag = rnode->sport->indicator;
6552 * Set SP here ... we haven't done a REG_VPI yet
6553 * TODO: need to maybe not set this when we have
6554 * completed VFI/VPI registrations ...
6556 * Use the FC_ID of the SPORT if it has been allocated, otherwise
6557 * use an S_ID of zero.
6560 if (rnode->sport->fc_id != UINT32_MAX) {
6561 els->sid = rnode->sport->fc_id;
6565 case FC_ELS_CMD_PLOGI:
6566 els->els_id = SLI4_ELS_REQUEST64_PLOGI;
6567 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6568 els->context_tag = rnode->sport->indicator;
6570 case FC_ELS_CMD_SCR:
6571 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6572 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6573 els->context_tag = rnode->sport->indicator;
6576 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6577 if (rnode->attached) {
6578 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6579 els->context_tag = rnode->indicator;
6581 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6582 els->context_tag = rnode->sport->indicator;
6588 els->cmd_type = SLI4_ELS_REQUEST64_CMD_FABRIC;
6590 els->cmd_type = SLI4_ELS_REQUEST64_CMD_NON_FABRIC;
6595 if (SLI4_ELS_REQUEST64_CONTEXT_RPI != els->ct) {
6596 els->remote_id = rnode->fc_id;
6598 if (SLI4_ELS_REQUEST64_CONTEXT_VPI == els->ct) {
6599 els->temporary_rpi = rnode->indicator;
6608 * @brief Write an FCP_ICMND64_WQE work queue entry.
6610 * @param sli4 SLI context.
6611 * @param buf Destination buffer for the WQE.
6612 * @param size Buffer size, in bytes.
6613 * @param sgl DMA memory for the scatter gather list.
6614 * @param xri XRI for this exchange.
6615 * @param tag IO tag value.
6616 * @param cq_id The id of the completion queue where the WQE response is sent.
6617 * @param rpi remote node indicator (RPI)
6618 * @param rnode Destination request (that is, the remote node).
6619 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6621 * @return Returns 0 on success, or a non-zero value on failure.
6624 sli_fcp_icmnd64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl,
6625 uint16_t xri, uint16_t tag, uint16_t cq_id,
6626 uint32_t rpi, ocs_remote_node_t *rnode, uint8_t timeout)
6628 sli4_fcp_icmnd64_wqe_t *icmnd = buf;
6629 sli4_sge_t *sge = NULL;
6631 ocs_memset(buf, 0, size);
6633 if (!sgl || !sgl->virt) {
6634 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6635 sgl, sgl ? sgl->virt : NULL);
6640 if (sli4->config.sgl_pre_registered) {
6644 icmnd->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6646 icmnd->bde.buffer_length = sge[0].buffer_length;
6647 icmnd->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6648 icmnd->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6652 icmnd->bde.bde_type = SLI4_BDE_TYPE_BLP;
6654 icmnd->bde.buffer_length = sgl->size;
6655 icmnd->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6656 icmnd->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6659 icmnd->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6660 icmnd->xri_tag = xri;
6661 icmnd->context_tag = rpi;
6662 icmnd->timer = timeout;
6664 icmnd->pu = 2; /* WQE word 4 contains read transfer length */
6665 icmnd->class = SLI4_ELS_REQUEST64_CLASS_3;
6666 icmnd->command = SLI4_WQE_FCP_ICMND64;
6667 icmnd->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6669 icmnd->abort_tag = xri;
6671 icmnd->request_tag = tag;
6673 if (rnode->node_group) {
6675 icmnd->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6677 if (((ocs_node_t *)rnode->node)->fcp2device) {
6680 icmnd->cmd_type = SLI4_CMD_FCP_ICMND64_WQE;
6681 icmnd->cq_id = cq_id;
6688 * @brief Write an FCP_IREAD64_WQE work queue entry.
6690 * @param sli4 SLI context.
6691 * @param buf Destination buffer for the WQE.
6692 * @param size Buffer size, in bytes.
6693 * @param sgl DMA memory for the scatter gather list.
6694 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6695 * @param xfer_len Data transfer length.
6696 * @param xri XRI for this exchange.
6697 * @param tag IO tag value.
6698 * @param cq_id The id of the completion queue where the WQE response is sent.
6699 * @param rpi remote node indicator (RPI)
6700 * @param rnode Destination request (i.e. remote node).
6701 * @param dif T10 DIF operation, or 0 to disable.
6702 * @param bs T10 DIF block size, or 0 if DIF is disabled.
6703 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6705 * @return Returns 0 on success, or a non-zero value on failure.
6708 sli_fcp_iread64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6709 uint32_t xfer_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
6710 uint32_t rpi, ocs_remote_node_t *rnode,
6711 uint8_t dif, uint8_t bs, uint8_t timeout)
6713 sli4_fcp_iread64_wqe_t *iread = buf;
6714 sli4_sge_t *sge = NULL;
6716 ocs_memset(buf, 0, size);
6718 if (!sgl || !sgl->virt) {
6719 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6720 sgl, sgl ? sgl->virt : NULL);
6725 if (sli4->config.sgl_pre_registered) {
6729 iread->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6731 iread->bde.buffer_length = sge[0].buffer_length;
6732 iread->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6733 iread->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6737 iread->bde.bde_type = SLI4_BDE_TYPE_BLP;
6739 iread->bde.buffer_length = sgl->size;
6740 iread->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6741 iread->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6743 /* fill out fcp_cmnd buffer len and change resp buffer to be of type
6744 * "skip" (note: response will still be written to sge[1] if necessary) */
6745 iread->fcp_cmd_buffer_length = sge[0].buffer_length;
6746 sge[1].sge_type = SLI4_SGE_TYPE_SKIP;
6749 iread->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6750 iread->total_transfer_length = xfer_len;
6752 iread->xri_tag = xri;
6753 iread->context_tag = rpi;
6755 iread->timer = timeout;
6757 iread->pu = 2; /* WQE word 4 contains read transfer length */
6758 iread->class = SLI4_ELS_REQUEST64_CLASS_3;
6759 iread->command = SLI4_WQE_FCP_IREAD64;
6760 iread->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6764 iread->abort_tag = xri;
6766 iread->request_tag = tag;
6768 if (rnode->node_group) {
6770 iread->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6772 if (((ocs_node_t *)rnode->node)->fcp2device) {
6776 iread->cmd_type = SLI4_CMD_FCP_IREAD64_WQE;
6777 iread->cq_id = cq_id;
6779 if (sli4->config.perf_hint) {
6780 iread->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6781 iread->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
6782 iread->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
6783 iread->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
6792 * @brief Write an FCP_IWRITE64_WQE work queue entry.
6794 * @param sli4 SLI context.
6795 * @param buf Destination buffer for the WQE.
6796 * @param size Buffer size, in bytes.
6797 * @param sgl DMA memory for the scatter gather list.
6798 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6799 * @param xfer_len Data transfer length.
6800 * @param first_burst The number of first burst bytes
6801 * @param xri XRI for this exchange.
6802 * @param tag IO tag value.
6803 * @param cq_id The id of the completion queue where the WQE response is sent.
6804 * @param rpi remote node indicator (RPI)
6805 * @param rnode Destination request (i.e. remote node)
6806 * @param dif T10 DIF operation, or 0 to disable
6807 * @param bs T10 DIF block size, or 0 if DIF is disabled
6808 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6810 * @return Returns 0 on success, or a non-zero value on failure.
6813 sli_fcp_iwrite64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6814 uint32_t xfer_len, uint32_t first_burst, uint16_t xri, uint16_t tag, uint16_t cq_id,
6815 uint32_t rpi, ocs_remote_node_t *rnode,
6816 uint8_t dif, uint8_t bs, uint8_t timeout)
6818 sli4_fcp_iwrite64_wqe_t *iwrite = buf;
6819 sli4_sge_t *sge = NULL;
6821 ocs_memset(buf, 0, size);
6823 if (!sgl || !sgl->virt) {
6824 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6825 sgl, sgl ? sgl->virt : NULL);
6830 if (sli4->config.sgl_pre_registered) {
6831 iwrite->xbl = FALSE;
6833 iwrite->dbde = TRUE;
6834 iwrite->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6836 iwrite->bde.buffer_length = sge[0].buffer_length;
6837 iwrite->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6838 iwrite->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6842 iwrite->bde.bde_type = SLI4_BDE_TYPE_BLP;
6844 iwrite->bde.buffer_length = sgl->size;
6845 iwrite->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6846 iwrite->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6848 /* fill out fcp_cmnd buffer len and change resp buffer to be of type
6849 * "skip" (note: response will still be written to sge[1] if necessary) */
6850 iwrite->fcp_cmd_buffer_length = sge[0].buffer_length;
6851 sge[1].sge_type = SLI4_SGE_TYPE_SKIP;
6854 iwrite->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6855 iwrite->total_transfer_length = xfer_len;
6856 iwrite->initial_transfer_length = MIN(xfer_len, first_burst);
6858 iwrite->xri_tag = xri;
6859 iwrite->context_tag = rpi;
6861 iwrite->timer = timeout;
6863 iwrite->pu = 2; /* WQE word 4 contains read transfer length */
6864 iwrite->class = SLI4_ELS_REQUEST64_CLASS_3;
6865 iwrite->command = SLI4_WQE_FCP_IWRITE64;
6866 iwrite->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6870 iwrite->abort_tag = xri;
6872 iwrite->request_tag = tag;
6873 iwrite->len_loc = 3;
6874 if (rnode->node_group) {
6876 iwrite->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6878 if (((ocs_node_t *)rnode->node)->fcp2device) {
6881 iwrite->cmd_type = SLI4_CMD_FCP_IWRITE64_WQE;
6882 iwrite->cq_id = cq_id;
6884 if (sli4->config.perf_hint) {
6885 iwrite->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6886 iwrite->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
6887 iwrite->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
6888 iwrite->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
6896 * @brief Write an FCP_TRECEIVE64_WQE work queue entry.
6898 * @param sli4 SLI context.
6899 * @param buf Destination buffer for the WQE.
6900 * @param size Buffer size, in bytes.
6901 * @param sgl DMA memory for the Scatter-Gather List.
6902 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6903 * @param relative_off Relative offset of the IO (if any).
6904 * @param xfer_len Data transfer length.
6905 * @param xri XRI for this exchange.
6906 * @param tag IO tag value.
6907 * @param xid OX_ID for the exchange.
6908 * @param cq_id The id of the completion queue where the WQE response is sent.
6909 * @param rpi remote node indicator (RPI)
6910 * @param rnode Destination request (i.e. remote node).
6911 * @param flags Optional attributes, including:
6912 * - ACTIVE - IO is already active.
6913 * - AUTO RSP - Automatically generate a good FCP_RSP.
6914 * @param dif T10 DIF operation, or 0 to disable.
6915 * @param bs T10 DIF block size, or 0 if DIF is disabled.
6916 * @param csctl value of csctl field.
6917 * @param app_id value for VM application header.
6919 * @return Returns 0 on success, or a non-zero value on failure.
6922 sli_fcp_treceive64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6923 uint32_t relative_off, uint32_t xfer_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
6924 uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode, uint32_t flags, uint8_t dif, uint8_t bs,
6925 uint8_t csctl, uint32_t app_id)
6927 sli4_fcp_treceive64_wqe_t *trecv = buf;
6928 sli4_fcp_128byte_wqe_t *trecv_128 = buf;
6929 sli4_sge_t *sge = NULL;
6931 ocs_memset(buf, 0, size);
6933 if (!sgl || !sgl->virt) {
6934 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6935 sgl, sgl ? sgl->virt : NULL);
6940 if (sli4->config.sgl_pre_registered) {
6944 trecv->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6946 trecv->bde.buffer_length = sge[0].buffer_length;
6947 trecv->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6948 trecv->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6950 trecv->payload_offset_length = sge[0].buffer_length;
6954 /* if data is a single physical address, use a BDE */
6955 if (!dif && (xfer_len <= sge[2].buffer_length)) {
6957 trecv->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6959 trecv->bde.buffer_length = sge[2].buffer_length;
6960 trecv->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
6961 trecv->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
6963 trecv->bde.bde_type = SLI4_BDE_TYPE_BLP;
6964 trecv->bde.buffer_length = sgl->size;
6965 trecv->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6966 trecv->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6970 trecv->relative_offset = relative_off;
6972 if (flags & SLI4_IO_CONTINUATION) {
6975 trecv->xri_tag = xri;
6977 trecv->context_tag = rpi;
6979 trecv->pu = TRUE; /* WQE uses relative offset */
6981 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
6985 trecv->command = SLI4_WQE_FCP_TRECEIVE64;
6986 trecv->class = SLI4_ELS_REQUEST64_CLASS_3;
6987 trecv->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6991 trecv->remote_xid = xid;
6993 trecv->request_tag = tag;
6997 trecv->len_loc = 0x2;
6999 if (rnode->node_group) {
7001 trecv->dword5.dword = rnode->fc_id & 0x00ffffff;
7004 trecv->cmd_type = SLI4_CMD_FCP_TRECEIVE64_WQE;
7006 trecv->cq_id = cq_id;
7008 trecv->fcp_data_receive_length = xfer_len;
7010 if (sli4->config.perf_hint) {
7011 trecv->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7012 trecv->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
7013 trecv->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
7014 trecv->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
7017 /* The upper 7 bits of csctl is the priority */
7018 if (csctl & SLI4_MASK_CCP) {
7020 trecv->ccp = (csctl & SLI4_MASK_CCP);
7023 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !trecv->eat) {
7024 trecv->app_id_valid = 1;
7026 trecv_128->dw[31] = app_id;
7033 * @brief Write an FCP_CONT_TRECEIVE64_WQE work queue entry.
7035 * @param sli4 SLI context.
7036 * @param buf Destination buffer for the WQE.
7037 * @param size Buffer size, in bytes.
7038 * @param sgl DMA memory for the Scatter-Gather List.
7039 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
7040 * @param relative_off Relative offset of the IO (if any).
7041 * @param xfer_len Data transfer length.
7042 * @param xri XRI for this exchange.
7043 * @param sec_xri Secondary XRI for this exchange. (BZ 161832 workaround)
7044 * @param tag IO tag value.
7045 * @param xid OX_ID for the exchange.
7046 * @param cq_id The id of the completion queue where the WQE response is sent.
7047 * @param rpi remote node indicator (RPI)
7048 * @param rnode Destination request (i.e. remote node).
7049 * @param flags Optional attributes, including:
7050 * - ACTIVE - IO is already active.
7051 * - AUTO RSP - Automatically generate a good FCP_RSP.
7052 * @param dif T10 DIF operation, or 0 to disable.
7053 * @param bs T10 DIF block size, or 0 if DIF is disabled.
7054 * @param csctl value of csctl field.
7055 * @param app_id value for VM application header.
7057 * @return Returns 0 on success, or a non-zero value on failure.
7060 sli_fcp_cont_treceive64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
7061 uint32_t relative_off, uint32_t xfer_len, uint16_t xri, uint16_t sec_xri, uint16_t tag,
7062 uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode, uint32_t flags,
7063 uint8_t dif, uint8_t bs, uint8_t csctl, uint32_t app_id)
7067 rc = sli_fcp_treceive64_wqe(sli4, buf, size, sgl, first_data_sge, relative_off, xfer_len, xri, tag,
7068 cq_id, xid, rpi, rnode, flags, dif, bs, csctl, app_id);
7070 sli4_fcp_treceive64_wqe_t *trecv = buf;
7072 trecv->command = SLI4_WQE_FCP_CONT_TRECEIVE64;
7073 trecv->dword5.sec_xri_tag = sec_xri;
7080 * @brief Write an FCP_TRSP64_WQE work queue entry.
7082 * @param sli4 SLI context.
7083 * @param buf Destination buffer for the WQE.
7084 * @param size Buffer size, in bytes.
7085 * @param sgl DMA memory for the Scatter-Gather List.
7086 * @param rsp_len Response data length.
7087 * @param xri XRI for this exchange.
7088 * @param tag IO tag value.
7089 * @param cq_id The id of the completion queue where the WQE response is sent.
7090 * @param xid OX_ID for the exchange.
7091 * @param rpi remote node indicator (RPI)
7092 * @param rnode Destination request (i.e. remote node).
7093 * @param flags Optional attributes, including:
7094 * - ACTIVE - IO is already active
7095 * - AUTO RSP - Automatically generate a good FCP_RSP.
7096 * @param csctl value of csctl field.
7097 * @param port_owned 0/1 to indicate if the XRI is port owned (used to set XBL=0)
7098 * @param app_id value for VM application header.
7100 * @return Returns 0 on success, or a non-zero value on failure.
7103 sli_fcp_trsp64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t rsp_len,
7104 uint16_t xri, uint16_t tag, uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode,
7105 uint32_t flags, uint8_t csctl, uint8_t port_owned, uint32_t app_id)
7107 sli4_fcp_trsp64_wqe_t *trsp = buf;
7108 sli4_fcp_128byte_wqe_t *trsp_128 = buf;
7110 ocs_memset(buf, 0, size);
7112 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
7115 * The SLI-4 documentation states that the BDE is ignored when
7116 * using auto-good response, but, at least for IF_TYPE 0 devices,
7117 * this does not appear to be true.
7119 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
7120 trsp->bde.buffer_length = 12; /* byte size of RSP */
7123 sli4_sge_t *sge = sgl->virt;
7125 if (sli4->config.sgl_pre_registered || port_owned) {
7131 trsp->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7132 trsp->bde.buffer_length = sge[0].buffer_length;
7133 trsp->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
7134 trsp->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
7136 trsp->fcp_response_length = rsp_len;
7139 if (flags & SLI4_IO_CONTINUATION) {
7143 if (rnode->node_group) {
7145 trsp->dword5 = rnode->fc_id & 0x00ffffff;
7148 trsp->xri_tag = xri;
7151 trsp->command = SLI4_WQE_FCP_TRSP64;
7152 trsp->class = SLI4_ELS_REQUEST64_CLASS_3;
7154 trsp->remote_xid = xid;
7155 trsp->request_tag = tag;
7156 trsp->dnrx = ((flags & SLI4_IO_DNRX) == 0 ? 0 : 1);
7157 trsp->len_loc = 0x1;
7158 trsp->cq_id = cq_id;
7159 trsp->cmd_type = SLI4_CMD_FCP_TRSP64_WQE;
7161 /* The upper 7 bits of csctl is the priority */
7162 if (csctl & SLI4_MASK_CCP) {
7164 trsp->ccp = (csctl & SLI4_MASK_CCP);
7167 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !trsp->eat) {
7168 trsp->app_id_valid = 1;
7170 trsp_128->dw[31] = app_id;
7177 * @brief Write an FCP_TSEND64_WQE work queue entry.
7179 * @param sli4 SLI context.
7180 * @param buf Destination buffer for the WQE.
7181 * @param size Buffer size, in bytes.
7182 * @param sgl DMA memory for the scatter gather list.
7183 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
7184 * @param relative_off Relative offset of the IO (if any).
7185 * @param xfer_len Data transfer length.
7186 * @param xri XRI for this exchange.
7187 * @param tag IO tag value.
7188 * @param cq_id The id of the completion queue where the WQE response is sent.
7189 * @param xid OX_ID for the exchange.
7190 * @param rpi remote node indicator (RPI)
7191 * @param rnode Destination request (i.e. remote node).
7192 * @param flags Optional attributes, including:
7193 * - ACTIVE - IO is already active.
7194 * - AUTO RSP - Automatically generate a good FCP_RSP.
7195 * @param dif T10 DIF operation, or 0 to disable.
7196 * @param bs T10 DIF block size, or 0 if DIF is disabled.
7197 * @param csctl value of csctl field.
7198 * @param app_id value for VM application header.
7200 * @return Returns 0 on success, or a non-zero value on failure.
7203 sli_fcp_tsend64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
7204 uint32_t relative_off, uint32_t xfer_len,
7205 uint16_t xri, uint16_t tag, uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode,
7206 uint32_t flags, uint8_t dif, uint8_t bs, uint8_t csctl, uint32_t app_id)
7208 sli4_fcp_tsend64_wqe_t *tsend = buf;
7209 sli4_fcp_128byte_wqe_t *tsend_128 = buf;
7210 sli4_sge_t *sge = NULL;
7212 ocs_memset(buf, 0, size);
7214 if (!sgl || !sgl->virt) {
7215 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7216 sgl, sgl ? sgl->virt : NULL);
7221 if (sli4->config.sgl_pre_registered) {
7225 tsend->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7227 /* TSEND64_WQE specifies first two SGE are skipped
7228 * (i.e. 3rd is valid) */
7229 tsend->bde.buffer_length = sge[2].buffer_length;
7230 tsend->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
7231 tsend->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
7235 /* if data is a single physical address, use a BDE */
7236 if (!dif && (xfer_len <= sge[2].buffer_length)) {
7238 tsend->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7239 /* TSEND64_WQE specifies first two SGE are skipped
7240 * (i.e. 3rd is valid) */
7241 tsend->bde.buffer_length = sge[2].buffer_length;
7242 tsend->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
7243 tsend->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
7245 tsend->bde.bde_type = SLI4_BDE_TYPE_BLP;
7246 tsend->bde.buffer_length = sgl->size;
7247 tsend->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
7248 tsend->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
7252 tsend->relative_offset = relative_off;
7254 if (flags & SLI4_IO_CONTINUATION) {
7257 tsend->xri_tag = xri;
7261 tsend->pu = TRUE; /* WQE uses relative offset */
7263 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
7267 tsend->command = SLI4_WQE_FCP_TSEND64;
7268 tsend->class = SLI4_ELS_REQUEST64_CLASS_3;
7269 tsend->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7273 tsend->remote_xid = xid;
7275 tsend->request_tag = tag;
7277 tsend->len_loc = 0x2;
7279 if (rnode->node_group) {
7281 tsend->dword5 = rnode->fc_id & 0x00ffffff;
7284 tsend->cq_id = cq_id;
7286 tsend->cmd_type = SLI4_CMD_FCP_TSEND64_WQE;
7288 tsend->fcp_data_transmit_length = xfer_len;
7290 if (sli4->config.perf_hint) {
7291 tsend->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7292 tsend->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
7293 tsend->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
7294 tsend->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
7297 /* The upper 7 bits of csctl is the priority */
7298 if (csctl & SLI4_MASK_CCP) {
7300 tsend->ccp = (csctl & SLI4_MASK_CCP);
7303 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !tsend->eat) {
7304 tsend->app_id_valid = 1;
7306 tsend_128->dw[31] = app_id;
7313 * @brief Write a GEN_REQUEST64 work queue entry.
7315 * @note This WQE is only used to send FC-CT commands.
7317 * @param sli4 SLI context.
7318 * @param buf Destination buffer for the WQE.
7319 * @param size Buffer size, in bytes.
7320 * @param sgl DMA memory for the request.
7321 * @param req_len Length of request.
7322 * @param max_rsp_len Max length of response.
7323 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7324 * @param xri XRI for this exchange.
7325 * @param tag IO tag value.
7326 * @param cq_id The id of the completion queue where the WQE response is sent.
7327 * @param rnode Destination of request (that is, the remote node).
7328 * @param r_ctl R_CTL value for sequence.
7329 * @param type TYPE value for sequence.
7330 * @param df_ctl DF_CTL value for sequence.
7332 * @return Returns 0 on success, or a non-zero value on failure.
7335 sli_gen_request64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl,
7336 uint32_t req_len, uint32_t max_rsp_len, uint8_t timeout,
7337 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode,
7338 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7340 sli4_gen_request64_wqe_t *gen = buf;
7341 sli4_sge_t *sge = NULL;
7343 ocs_memset(buf, 0, size);
7345 if (!sgl || !sgl->virt) {
7346 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7347 sgl, sgl ? sgl->virt : NULL);
7352 if (sli4->config.sgl_pre_registered) {
7356 gen->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7358 gen->bde.buffer_length = req_len;
7359 gen->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
7360 gen->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
7364 gen->bde.bde_type = SLI4_BDE_TYPE_BLP;
7366 gen->bde.buffer_length = 2 * sizeof(sli4_sge_t);
7367 gen->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
7368 gen->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
7371 gen->request_payload_length = req_len;
7372 gen->max_response_payload_length = max_rsp_len;
7374 gen->df_ctl = df_ctl;
7380 gen->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7381 gen->context_tag = rnode->indicator;
7383 gen->class = SLI4_ELS_REQUEST64_CLASS_3;
7385 gen->command = SLI4_WQE_GEN_REQUEST64;
7387 gen->timer = timeout;
7389 gen->request_tag = tag;
7391 gen->iod = SLI4_ELS_REQUEST64_DIR_READ;
7395 if (rnode->node_group) {
7397 gen->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7400 gen->cmd_type = SLI4_CMD_GEN_REQUEST64_WQE;
7409 * @brief Write a SEND_FRAME work queue entry
7411 * @param sli4 SLI context.
7412 * @param buf Destination buffer for the WQE.
7413 * @param size Buffer size, in bytes.
7414 * @param sof Start of frame value
7415 * @param eof End of frame value
7416 * @param hdr Pointer to FC header data
7417 * @param payload DMA memory for the payload.
7418 * @param req_len Length of payload.
7419 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7420 * @param xri XRI for this exchange.
7421 * @param req_tag IO tag value.
7423 * @return Returns 0 on success, or a non-zero value on failure.
7426 sli_send_frame_wqe(sli4_t *sli4, void *buf, size_t size, uint8_t sof, uint8_t eof, uint32_t *hdr,
7427 ocs_dma_t *payload, uint32_t req_len, uint8_t timeout,
7428 uint16_t xri, uint16_t req_tag)
7430 sli4_send_frame_wqe_t *sf = buf;
7432 ocs_memset(buf, 0, size);
7435 sf->bde.buffer_length = req_len;
7436 sf->bde.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7437 sf->bde.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7439 /* Copy FC header */
7440 sf->fc_header_0_1[0] = hdr[0];
7441 sf->fc_header_0_1[1] = hdr[1];
7442 sf->fc_header_2_5[0] = hdr[2];
7443 sf->fc_header_2_5[1] = hdr[3];
7444 sf->fc_header_2_5[2] = hdr[4];
7445 sf->fc_header_2_5[3] = hdr[5];
7447 sf->frame_length = req_len;
7451 sf->context_tag = 0;
7455 sf->command = SLI4_WQE_SEND_FRAME;
7456 sf->class = SLI4_ELS_REQUEST64_CLASS_3;
7457 sf->timer = timeout;
7459 sf->request_tag = req_tag;
7469 sf->cmd_type = SLI4_CMD_SEND_FRAME_WQE;
7477 * @brief Write a XMIT_SEQUENCE64 work queue entry.
7479 * This WQE is used to send FC-CT response frames.
7481 * @note This API implements a restricted use for this WQE, a TODO: would
7482 * include passing in sequence initiative, and full SGL's
7484 * @param sli4 SLI context.
7485 * @param buf Destination buffer for the WQE.
7486 * @param size Buffer size, in bytes.
7487 * @param payload DMA memory for the request.
7488 * @param payload_len Length of request.
7489 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7490 * @param ox_id originator exchange ID
7491 * @param xri XRI for this exchange.
7492 * @param tag IO tag value.
7493 * @param rnode Destination of request (that is, the remote node).
7494 * @param r_ctl R_CTL value for sequence.
7495 * @param type TYPE value for sequence.
7496 * @param df_ctl DF_CTL value for sequence.
7498 * @return Returns 0 on success, or a non-zero value on failure.
7501 sli_xmit_sequence64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *payload,
7502 uint32_t payload_len, uint8_t timeout, uint16_t ox_id,
7503 uint16_t xri, uint16_t tag, ocs_remote_node_t *rnode,
7504 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7506 sli4_xmit_sequence64_wqe_t *xmit = buf;
7508 ocs_memset(buf, 0, size);
7510 if ((payload == NULL) || (payload->virt == NULL)) {
7511 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7512 payload, payload ? payload->virt : NULL);
7516 if (sli4->config.sgl_pre_registered) {
7522 xmit->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7523 xmit->bde.buffer_length = payload_len;
7524 xmit->bde.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7525 xmit->bde.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7526 xmit->sequence_payload_len = payload_len;
7528 xmit->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7530 xmit->relative_offset = 0;
7532 xmit->si = 0; /* sequence initiative - this matches what is seen from
7533 * FC switches in response to FCGS commands */
7534 xmit->ft = 0; /* force transmit */
7535 xmit->xo = 0; /* exchange responder */
7536 xmit->ls = 1; /* last in seqence */
7537 xmit->df_ctl = df_ctl;
7539 xmit->r_ctl = r_ctl;
7541 xmit->xri_tag = xri;
7542 xmit->context_tag = rnode->indicator;
7545 xmit->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7548 xmit->command = SLI4_WQE_XMIT_SEQUENCE64;
7549 xmit->class = SLI4_ELS_REQUEST64_CLASS_3;
7551 xmit->timer = timeout;
7553 xmit->abort_tag = 0;
7554 xmit->request_tag = tag;
7555 xmit->remote_xid = ox_id;
7557 xmit->iod = SLI4_ELS_REQUEST64_DIR_READ;
7559 if (rnode->node_group) {
7561 xmit->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7564 xmit->cmd_type = SLI4_CMD_XMIT_SEQUENCE64_WQE;
7568 xmit->cq_id = 0xFFFF;
7575 * @brief Write a REQUEUE_XRI_WQE work queue entry.
7577 * @param sli4 SLI context.
7578 * @param buf Destination buffer for the WQE.
7579 * @param size Buffer size, in bytes.
7580 * @param xri XRI for this exchange.
7581 * @param tag IO tag value.
7582 * @param cq_id The id of the completion queue where the WQE response is sent.
7584 * @return Returns 0 on success, or a non-zero value on failure.
7587 sli_requeue_xri_wqe(sli4_t *sli4, void *buf, size_t size, uint16_t xri, uint16_t tag, uint16_t cq_id)
7589 sli4_requeue_xri_wqe_t *requeue = buf;
7591 ocs_memset(buf, 0, size);
7593 requeue->command = SLI4_WQE_REQUEUE_XRI;
7594 requeue->xri_tag = xri;
7595 requeue->request_tag = tag;
7598 requeue->cq_id = cq_id;
7599 requeue->cmd_type = SLI4_CMD_REQUEUE_XRI_WQE;
7604 sli_xmit_bcast64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *payload,
7605 uint32_t payload_len, uint8_t timeout, uint16_t xri, uint16_t tag,
7606 uint16_t cq_id, ocs_remote_node_t *rnode,
7607 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7609 sli4_xmit_bcast64_wqe_t *bcast = buf;
7611 /* Command requires a temporary RPI (i.e. unused remote node) */
7612 if (rnode->attached) {
7613 ocs_log_test(sli4->os, "remote node %d in use\n", rnode->indicator);
7617 ocs_memset(buf, 0, size);
7620 bcast->sequence_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
7621 bcast->sequence_payload.buffer_length = payload_len;
7622 bcast->sequence_payload.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7623 bcast->sequence_payload.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7625 bcast->sequence_payload_length = payload_len;
7627 bcast->df_ctl = df_ctl;
7629 bcast->r_ctl = r_ctl;
7631 bcast->xri_tag = xri;
7633 bcast->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7634 bcast->context_tag = rnode->sport->indicator;
7636 bcast->class = SLI4_ELS_REQUEST64_CLASS_3;
7638 bcast->command = SLI4_WQE_XMIT_BCAST64;
7640 bcast->timer = timeout;
7642 bcast->request_tag = tag;
7644 bcast->temporary_rpi = rnode->indicator;
7646 bcast->len_loc = 0x1;
7648 bcast->iod = SLI4_ELS_REQUEST64_DIR_WRITE;
7650 bcast->cmd_type = SLI4_CMD_XMIT_BCAST64_WQE;
7652 bcast->cq_id = cq_id;
7659 * @brief Write an XMIT_BLS_RSP64_WQE work queue entry.
7661 * @param sli4 SLI context.
7662 * @param buf Destination buffer for the WQE.
7663 * @param size Buffer size, in bytes.
7664 * @param payload Contents of the BLS payload to be sent.
7665 * @param xri XRI for this exchange.
7666 * @param tag IO tag value.
7667 * @param cq_id The id of the completion queue where the WQE response is sent.
7668 * @param rnode Destination of request (that is, the remote node).
7669 * @param s_id Source ID to use in the response. If UINT32_MAX, use SLI Port's ID.
7671 * @return Returns 0 on success, or a non-zero value on failure.
7674 sli_xmit_bls_rsp64_wqe(sli4_t *sli4, void *buf, size_t size, sli_bls_payload_t *payload,
7675 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode, uint32_t s_id)
7677 sli4_xmit_bls_rsp_wqe_t *bls = buf;
7680 * Callers can either specify RPI or S_ID, but not both
7682 if (rnode->attached && (s_id != UINT32_MAX)) {
7683 ocs_log_test(sli4->os, "S_ID specified for attached remote node %d\n",
7688 ocs_memset(buf, 0, size);
7690 if (SLI_BLS_ACC == payload->type) {
7691 bls->payload_word0 = (payload->u.acc.seq_id_last << 16) |
7692 (payload->u.acc.seq_id_validity << 24);
7693 bls->high_seq_cnt = payload->u.acc.high_seq_cnt;
7694 bls->low_seq_cnt = payload->u.acc.low_seq_cnt;
7695 } else if (SLI_BLS_RJT == payload->type) {
7696 bls->payload_word0 = *((uint32_t *)&payload->u.rjt);
7699 ocs_log_test(sli4->os, "bad BLS type %#x\n",
7704 bls->ox_id = payload->ox_id;
7705 bls->rx_id = payload->rx_id;
7707 if (rnode->attached) {
7708 bls->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7709 bls->context_tag = rnode->indicator;
7711 bls->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7712 bls->context_tag = rnode->sport->indicator;
7714 if (UINT32_MAX != s_id) {
7715 bls->local_n_port_id = s_id & 0x00ffffff;
7717 bls->local_n_port_id = rnode->sport->fc_id & 0x00ffffff;
7719 bls->remote_id = rnode->fc_id & 0x00ffffff;
7721 bls->temporary_rpi = rnode->indicator;
7726 bls->class = SLI4_ELS_REQUEST64_CLASS_3;
7728 bls->command = SLI4_WQE_XMIT_BLS_RSP;
7730 bls->request_tag = tag;
7734 if (rnode->node_group) {
7736 bls->remote_id = rnode->fc_id & 0x00ffffff;
7741 bls->cmd_type = SLI4_CMD_XMIT_BLS_RSP64_WQE;
7748 * @brief Write a XMIT_ELS_RSP64_WQE work queue entry.
7750 * @param sli4 SLI context.
7751 * @param buf Destination buffer for the WQE.
7752 * @param size Buffer size, in bytes.
7753 * @param rsp DMA memory for the ELS response.
7754 * @param rsp_len Length of ELS response, in bytes.
7755 * @param xri XRI for this exchange.
7756 * @param tag IO tag value.
7757 * @param cq_id The id of the completion queue where the WQE response is sent.
7758 * @param ox_id OX_ID of the exchange containing the request.
7759 * @param rnode Destination of the ELS response (that is, the remote node).
7760 * @param flags Optional attributes, including:
7761 * - SLI4_IO_CONTINUATION - IO is already active.
7762 * @param s_id S_ID used for special responses.
7764 * @return Returns 0 on success, or a non-zero value on failure.
7767 sli_xmit_els_rsp64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *rsp,
7768 uint32_t rsp_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
7769 uint16_t ox_id, ocs_remote_node_t *rnode, uint32_t flags, uint32_t s_id)
7771 sli4_xmit_els_rsp64_wqe_t *els = buf;
7773 ocs_memset(buf, 0, size);
7775 if (sli4->config.sgl_pre_registered) {
7781 els->els_response_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
7782 els->els_response_payload.buffer_length = rsp_len;
7783 els->els_response_payload.u.data.buffer_address_low = ocs_addr32_lo(rsp->phys);
7784 els->els_response_payload.u.data.buffer_address_high = ocs_addr32_hi(rsp->phys);
7786 els->els_response_payload_length = rsp_len;
7790 els->class = SLI4_ELS_REQUEST64_CLASS_3;
7792 els->command = SLI4_WQE_ELS_RSP64;
7794 els->request_tag = tag;
7798 els->iod = SLI4_ELS_REQUEST64_DIR_WRITE;
7802 if (flags & SLI4_IO_CONTINUATION) {
7806 if (rnode->attached) {
7807 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7808 els->context_tag = rnode->indicator;
7810 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7811 els->context_tag = rnode->sport->indicator;
7812 els->remote_id = rnode->fc_id & 0x00ffffff;
7813 els->temporary_rpi = rnode->indicator;
7814 if (UINT32_MAX != s_id) {
7816 els->s_id = s_id & 0x00ffffff;
7820 if (rnode->node_group) {
7822 els->remote_id = rnode->fc_id & 0x00ffffff;
7825 els->cmd_type = SLI4_ELS_REQUEST64_CMD_GEN;
7834 * @brief Process an asynchronous Link State event entry.
7837 * Parses Asynchronous Completion Queue Entry (ACQE),
7838 * creates an abstracted event, and calls registered callback functions.
7840 * @param sli4 SLI context.
7841 * @param acqe Pointer to the ACQE.
7843 * @return Returns 0 on success, or a non-zero value on failure.
7846 sli_fc_process_link_state(sli4_t *sli4, void *acqe)
7848 sli4_link_state_t *link_state = acqe;
7849 sli4_link_event_t event = { 0 };
7853 /* bail if there is no callback */
7857 if (SLI4_LINK_TYPE_ETHERNET == link_state->link_type) {
7858 event.topology = SLI_LINK_TOPO_NPORT;
7859 event.medium = SLI_LINK_MEDIUM_ETHERNET;
7861 /* TODO is this supported for anything other than FCoE? */
7862 ocs_log_test(sli4->os, "unsupported link type %#x\n",
7863 link_state->link_type);
7864 event.topology = SLI_LINK_TOPO_MAX;
7865 event.medium = SLI_LINK_MEDIUM_MAX;
7869 switch (link_state->port_link_status) {
7870 case SLI4_PORT_LINK_STATUS_PHYSICAL_DOWN:
7871 case SLI4_PORT_LINK_STATUS_LOGICAL_DOWN:
7872 event.status = SLI_LINK_STATUS_DOWN;
7874 case SLI4_PORT_LINK_STATUS_PHYSICAL_UP:
7875 case SLI4_PORT_LINK_STATUS_LOGICAL_UP:
7876 event.status = SLI_LINK_STATUS_UP;
7879 ocs_log_test(sli4->os, "unsupported link status %#x\n",
7880 link_state->port_link_status);
7881 event.status = SLI_LINK_STATUS_MAX;
7885 switch (link_state->port_speed) {
7899 event.speed = 10000;
7902 event.speed = 20000;
7905 event.speed = 25000;
7908 event.speed = 40000;
7911 event.speed = 100000;
7914 ocs_log_test(sli4->os, "unsupported port_speed %#x\n",
7915 link_state->port_speed);
7919 sli4->link(sli4->link_arg, (void *)&event);
7926 * @brief Process an asynchronous Link Attention event entry.
7929 * Parses Asynchronous Completion Queue Entry (ACQE),
7930 * creates an abstracted event, and calls the registered callback functions.
7932 * @param sli4 SLI context.
7933 * @param acqe Pointer to the ACQE.
7935 * @todo XXX all events return LINK_UP.
7937 * @return Returns 0 on success, or a non-zero value on failure.
7940 sli_fc_process_link_attention(sli4_t *sli4, void *acqe)
7942 sli4_link_attention_t *link_attn = acqe;
7943 sli4_link_event_t event = { 0 };
7945 ocs_log_debug(sli4->os, "link_number=%d attn_type=%#x topology=%#x port_speed=%#x "
7946 "port_fault=%#x shared_link_status=%#x logical_link_speed=%#x "
7947 "event_tag=%#x\n", link_attn->link_number, link_attn->attn_type,
7948 link_attn->topology, link_attn->port_speed, link_attn->port_fault,
7949 link_attn->shared_link_status, link_attn->logical_link_speed,
7950 link_attn->event_tag);
7956 event.medium = SLI_LINK_MEDIUM_FC;
7958 switch (link_attn->attn_type) {
7959 case SLI4_LINK_ATTN_TYPE_LINK_UP:
7960 event.status = SLI_LINK_STATUS_UP;
7962 case SLI4_LINK_ATTN_TYPE_LINK_DOWN:
7963 event.status = SLI_LINK_STATUS_DOWN;
7965 case SLI4_LINK_ATTN_TYPE_NO_HARD_ALPA:
7966 ocs_log_debug(sli4->os, "attn_type: no hard alpa\n");
7967 event.status = SLI_LINK_STATUS_NO_ALPA;
7970 ocs_log_test(sli4->os, "attn_type: unknown\n");
7974 switch (link_attn->event_type) {
7975 case SLI4_FC_EVENT_LINK_ATTENTION:
7977 case SLI4_FC_EVENT_SHARED_LINK_ATTENTION:
7978 ocs_log_debug(sli4->os, "event_type: FC shared link event \n");
7981 ocs_log_test(sli4->os, "event_type: unknown\n");
7985 switch (link_attn->topology) {
7986 case SLI4_LINK_ATTN_P2P:
7987 event.topology = SLI_LINK_TOPO_NPORT;
7989 case SLI4_LINK_ATTN_FC_AL:
7990 event.topology = SLI_LINK_TOPO_LOOP;
7992 case SLI4_LINK_ATTN_INTERNAL_LOOPBACK:
7993 ocs_log_debug(sli4->os, "topology Internal loopback\n");
7994 event.topology = SLI_LINK_TOPO_LOOPBACK_INTERNAL;
7996 case SLI4_LINK_ATTN_SERDES_LOOPBACK:
7997 ocs_log_debug(sli4->os, "topology serdes loopback\n");
7998 event.topology = SLI_LINK_TOPO_LOOPBACK_EXTERNAL;
8001 ocs_log_test(sli4->os, "topology: unknown\n");
8005 event.speed = link_attn->port_speed * 1000;
8007 sli4->link(sli4->link_arg, (void *)&event);
8014 * @brief Parse an FC/FCoE work queue CQ entry.
8016 * @param sli4 SLI context.
8017 * @param cq CQ to process.
8018 * @param cqe Pointer to the CQ entry.
8019 * @param etype CQ event type.
8020 * @param r_id Resource ID associated with this completion message (such as the IO tag).
8022 * @return Returns 0 on success, or a non-zero value on failure.
8025 sli_fc_cqe_parse(sli4_t *sli4, sli4_queue_t *cq, uint8_t *cqe, sli4_qentry_e *etype,
8028 uint8_t code = cqe[SLI4_CQE_CODE_OFFSET];
8032 case SLI4_CQE_CODE_WORK_REQUEST_COMPLETION:
8034 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8036 *etype = SLI_QENTRY_WQ;
8037 *r_id = wcqe->request_tag;
8040 /* Flag errors except for FCP_RSP_FAILURE */
8041 if (rc && (rc != SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE)) {
8043 ocs_log_test(sli4->os, "WCQE: status=%#x hw_status=%#x tag=%#x w1=%#x w2=%#x xb=%d\n",
8044 wcqe->status, wcqe->hw_status,
8045 wcqe->request_tag, wcqe->wqe_specific_1,
8046 wcqe->wqe_specific_2, wcqe->xb);
8047 ocs_log_test(sli4->os, " %08X %08X %08X %08X\n", ((uint32_t*) cqe)[0], ((uint32_t*) cqe)[1],
8048 ((uint32_t*) cqe)[2], ((uint32_t*) cqe)[3]);
8051 /* TODO: need to pass additional status back out of here as well
8052 * as status (could overload rc as status/addlstatus are only 8 bits each)
8057 case SLI4_CQE_CODE_RQ_ASYNC:
8059 sli4_fc_async_rcqe_t *rcqe = (void *)cqe;
8061 *etype = SLI_QENTRY_RQ;
8062 *r_id = rcqe->rq_id;
8066 case SLI4_CQE_CODE_RQ_ASYNC_V1:
8068 sli4_fc_async_rcqe_v1_t *rcqe = (void *)cqe;
8070 *etype = SLI_QENTRY_RQ;
8071 *r_id = rcqe->rq_id;
8075 case SLI4_CQE_CODE_OPTIMIZED_WRITE_CMD:
8077 sli4_fc_optimized_write_cmd_cqe_t *optcqe = (void *)cqe;
8079 *etype = SLI_QENTRY_OPT_WRITE_CMD;
8080 *r_id = optcqe->rq_id;
8081 rc = optcqe->status;
8084 case SLI4_CQE_CODE_OPTIMIZED_WRITE_DATA:
8086 sli4_fc_optimized_write_data_cqe_t *dcqe = (void *)cqe;
8088 *etype = SLI_QENTRY_OPT_WRITE_DATA;
8093 if (rc != SLI4_FC_WCQE_STATUS_SUCCESS) {
8094 ocs_log_test(sli4->os, "Optimized DATA CQE: status=%#x hw_status=%#x xri=%#x dpl=%#x w3=%#x xb=%d\n",
8095 dcqe->status, dcqe->hw_status,
8096 dcqe->xri, dcqe->total_data_placed,
8097 ((uint32_t*) cqe)[3], dcqe->xb);
8101 case SLI4_CQE_CODE_RQ_COALESCING:
8103 sli4_fc_coalescing_rcqe_t *rcqe = (void *)cqe;
8105 *etype = SLI_QENTRY_RQ;
8106 *r_id = rcqe->rq_id;
8110 case SLI4_CQE_CODE_XRI_ABORTED:
8112 sli4_fc_xri_aborted_cqe_t *xa = (void *)cqe;
8114 *etype = SLI_QENTRY_XABT;
8119 case SLI4_CQE_CODE_RELEASE_WQE: {
8120 sli4_fc_wqec_t *wqec = (void*) cqe;
8122 *etype = SLI_QENTRY_WQ_RELEASE;
8123 *r_id = wqec->wq_id;
8128 ocs_log_test(sli4->os, "CQE completion code %d not handled\n", code);
8129 *etype = SLI_QENTRY_MAX;
8138 * @brief Return the ELS/CT response length.
8140 * @param sli4 SLI context.
8141 * @param cqe Pointer to the CQ entry.
8143 * @return Returns the length, in bytes.
8146 sli_fc_response_length(sli4_t *sli4, uint8_t *cqe)
8148 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8150 return wcqe->wqe_specific_1;
8155 * @brief Return the FCP IO length.
8157 * @param sli4 SLI context.
8158 * @param cqe Pointer to the CQ entry.
8160 * @return Returns the length, in bytes.
8163 sli_fc_io_length(sli4_t *sli4, uint8_t *cqe)
8165 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8167 return wcqe->wqe_specific_1;
8172 * @brief Retrieve the D_ID from the completion.
8174 * @param sli4 SLI context.
8175 * @param cqe Pointer to the CQ entry.
8176 * @param d_id Pointer where the D_ID is written.
8178 * @return Returns 0 on success, or a non-zero value on failure.
8181 sli_fc_els_did(sli4_t *sli4, uint8_t *cqe, uint32_t *d_id)
8183 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8190 *d_id = wcqe->wqe_specific_2 & 0x00ffffff;
8196 sli_fc_ext_status(sli4_t *sli4, uint8_t *cqe)
8198 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8201 switch (wcqe->status) {
8202 case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE:
8205 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
8206 case SLI4_FC_WCQE_STATUS_CMD_REJECT:
8209 case SLI4_FC_WCQE_STATUS_NPORT_RJT:
8210 case SLI4_FC_WCQE_STATUS_FABRIC_RJT:
8211 case SLI4_FC_WCQE_STATUS_NPORT_BSY:
8212 case SLI4_FC_WCQE_STATUS_FABRIC_BSY:
8213 case SLI4_FC_WCQE_STATUS_LS_RJT:
8216 case SLI4_FC_WCQE_STATUS_DI_ERROR:
8223 return wcqe->wqe_specific_2 & mask;
8228 * @brief Retrieve the RQ index from the completion.
8230 * @param sli4 SLI context.
8231 * @param cqe Pointer to the CQ entry.
8232 * @param rq_id Pointer where the rq_id is written.
8233 * @param index Pointer where the index is written.
8235 * @return Returns 0 on success, or a non-zero value on failure.
8238 sli_fc_rqe_rqid_and_index(sli4_t *sli4, uint8_t *cqe, uint16_t *rq_id, uint32_t *index)
8240 sli4_fc_async_rcqe_t *rcqe = (void *)cqe;
8241 sli4_fc_async_rcqe_v1_t *rcqe_v1 = (void *)cqe;
8246 *index = UINT32_MAX;
8248 code = cqe[SLI4_CQE_CODE_OFFSET];
8250 if (code == SLI4_CQE_CODE_RQ_ASYNC) {
8251 *rq_id = rcqe->rq_id;
8252 if (SLI4_FC_ASYNC_RQ_SUCCESS == rcqe->status) {
8253 *index = rcqe->rq_element_index;
8256 *index = rcqe->rq_element_index;
8258 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8259 rcqe->status, sli_fc_get_status_string(rcqe->status), rcqe->rq_id,
8260 rcqe->rq_element_index, rcqe->payload_data_placement_length, rcqe->sof_byte,
8261 rcqe->eof_byte, rcqe->header_data_placement_length);
8263 } else if (code == SLI4_CQE_CODE_RQ_ASYNC_V1) {
8264 *rq_id = rcqe_v1->rq_id;
8265 if (SLI4_FC_ASYNC_RQ_SUCCESS == rcqe_v1->status) {
8266 *index = rcqe_v1->rq_element_index;
8269 *index = rcqe_v1->rq_element_index;
8270 rc = rcqe_v1->status;
8271 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8272 rcqe_v1->status, sli_fc_get_status_string(rcqe_v1->status),
8273 rcqe_v1->rq_id, rcqe_v1->rq_element_index,
8274 rcqe_v1->payload_data_placement_length, rcqe_v1->sof_byte,
8275 rcqe_v1->eof_byte, rcqe_v1->header_data_placement_length);
8277 } else if (code == SLI4_CQE_CODE_OPTIMIZED_WRITE_CMD) {
8278 sli4_fc_optimized_write_cmd_cqe_t *optcqe = (void *)cqe;
8280 *rq_id = optcqe->rq_id;
8281 if (SLI4_FC_ASYNC_RQ_SUCCESS == optcqe->status) {
8282 *index = optcqe->rq_element_index;
8285 *index = optcqe->rq_element_index;
8286 rc = optcqe->status;
8287 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x pdpl=%x hdpl=%x oox=%d agxr=%d xri=0x%x rpi=0x%x\n",
8288 optcqe->status, sli_fc_get_status_string(optcqe->status), optcqe->rq_id,
8289 optcqe->rq_element_index, optcqe->payload_data_placement_length,
8290 optcqe->header_data_placement_length, optcqe->oox, optcqe->agxr, optcqe->xri,
8293 } else if (code == SLI4_CQE_CODE_RQ_COALESCING) {
8294 sli4_fc_coalescing_rcqe_t *rcqe = (void *)cqe;
8296 *rq_id = rcqe->rq_id;
8297 if (SLI4_FC_COALESCE_RQ_SUCCESS == rcqe->status) {
8298 *index = rcqe->rq_element_index;
8301 *index = UINT32_MAX;
8304 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x rq_id=%#x sdpl=%x\n",
8305 rcqe->status, sli_fc_get_status_string(rcqe->status), rcqe->rq_id,
8306 rcqe->rq_element_index, rcqe->rq_id, rcqe->sequence_reporting_placement_length);
8309 *index = UINT32_MAX;
8313 ocs_log_debug(sli4->os, "status=%02x rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8314 rcqe->status, rcqe->rq_id, rcqe->rq_element_index, rcqe->payload_data_placement_length,
8315 rcqe->sof_byte, rcqe->eof_byte, rcqe->header_data_placement_length);
8323 * @brief Process an asynchronous FCoE event entry.
8326 * Parses Asynchronous Completion Queue Entry (ACQE),
8327 * creates an abstracted event, and calls the registered callback functions.
8329 * @param sli4 SLI context.
8330 * @param acqe Pointer to the ACQE.
8332 * @return Returns 0 on success, or a non-zero value on failure.
8335 sli_fc_process_fcoe(sli4_t *sli4, void *acqe)
8337 sli4_fcoe_fip_t *fcoe = acqe;
8338 sli4_fip_event_t event = { 0 };
8339 uint32_t mask = UINT32_MAX;
8341 ocs_log_debug(sli4->os, "ACQE FCoE FIP type=%02x count=%d tag=%#x\n",
8350 event.type = fcoe->event_type;
8351 event.index = UINT32_MAX;
8353 switch (fcoe->event_type) {
8354 case SLI4_FCOE_FIP_FCF_DISCOVERED:
8355 ocs_log_debug(sli4->os, "FCF Discovered index=%d\n", fcoe->event_information);
8357 case SLI4_FCOE_FIP_FCF_TABLE_FULL:
8358 ocs_log_debug(sli4->os, "FCF Table Full\n");
8361 case SLI4_FCOE_FIP_FCF_DEAD:
8362 ocs_log_debug(sli4->os, "FCF Dead/Gone index=%d\n", fcoe->event_information);
8364 case SLI4_FCOE_FIP_FCF_CLEAR_VLINK:
8366 ocs_log_debug(sli4->os, "Clear VLINK Received VPI=%#x\n", fcoe->event_information & mask);
8368 case SLI4_FCOE_FIP_FCF_MODIFIED:
8369 ocs_log_debug(sli4->os, "FCF Modified\n");
8372 ocs_log_test(sli4->os, "bad FCoE type %#x", fcoe->event_type);
8377 event.index = fcoe->event_information & mask;
8380 sli4->fip(sli4->fip_arg, &event);
8387 * @brief Allocate a receive queue.
8390 * Allocates DMA memory and configures the requested queue type.
8392 * @param sli4 SLI context.
8393 * @param q Pointer to the queue object for the header.
8394 * @param n_entries Number of entries to allocate.
8395 * @param buffer_size buffer size for the queue.
8396 * @param cq Associated CQ.
8397 * @param ulp The ULP to bind
8398 * @param is_hdr Used to validate the rq_id and set the type of queue
8400 * @return Returns 0 on success, or -1 on failure.
8403 sli_fc_rq_alloc(sli4_t *sli4, sli4_queue_t *q,
8404 uint32_t n_entries, uint32_t buffer_size,
8405 sli4_queue_t *cq, uint16_t ulp, uint8_t is_hdr)
8407 int32_t (*rq_create)(sli4_t *, void *, size_t, ocs_dma_t *, uint16_t, uint16_t, uint16_t);
8409 if ((sli4 == NULL) || (q == NULL)) {
8410 void *os = sli4 != NULL ? sli4->os : NULL;
8412 ocs_log_err(os, "bad parameter sli4=%p q=%p\n", sli4, q);
8416 if (__sli_queue_init(sli4, q, SLI_QTYPE_RQ, SLI4_FCOE_RQE_SIZE,
8417 n_entries, SLI_PAGE_SIZE)) {
8421 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) {
8422 rq_create = sli_cmd_fcoe_rq_create;
8424 rq_create = sli_cmd_fcoe_rq_create_v1;
8427 if (rq_create(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &q->dma,
8428 cq->id, ulp, buffer_size)) {
8429 if (__sli_create_queue(sli4, q)) {
8430 ocs_dma_free(sli4->os, &q->dma);
8433 if (is_hdr && q->id & 1) {
8434 ocs_log_test(sli4->os, "bad header RQ_ID %d\n", q->id);
8435 ocs_dma_free(sli4->os, &q->dma);
8437 } else if (!is_hdr && (q->id & 1) == 0) {
8438 ocs_log_test(sli4->os, "bad data RQ_ID %d\n", q->id);
8439 ocs_dma_free(sli4->os, &q->dma);
8445 q->u.flag.is_hdr = is_hdr;
8446 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
8447 q->u.flag.rq_batch = TRUE;
8455 * @brief Allocate a receive queue set.
8457 * @param sli4 SLI context.
8458 * @param num_rq_pairs to create
8459 * @param qs Pointers to the queue objects for both header and data.
8460 * Length of this arrays should be 2 * num_rq_pairs
8461 * @param base_cq_id. Assumes base_cq_id : (base_cq_id + num_rq_pairs) cqs as allotted.
8462 * @param n_entries number of entries in each RQ queue.
8463 * @param header_buffer_size
8464 * @param payload_buffer_size
8465 * @param ulp The ULP to bind
8467 * @return Returns 0 on success, or -1 on failure.
8470 sli_fc_rq_set_alloc(sli4_t *sli4, uint32_t num_rq_pairs,
8471 sli4_queue_t *qs[], uint32_t base_cq_id,
8472 uint32_t n_entries, uint32_t header_buffer_size,
8473 uint32_t payload_buffer_size, uint16_t ulp)
8475 uint32_t i, p, offset = 0;
8476 uint32_t payload_size, total_page_count = 0;
8479 sli4_res_common_create_queue_set_t *rsp = NULL;
8480 sli4_req_fcoe_rq_create_v2_t *req = NULL;
8482 ocs_memset(&dma, 0, sizeof(dma));
8484 for (i = 0; i < (num_rq_pairs * 2); i++) {
8485 if (__sli_queue_init(sli4, qs[i], SLI_QTYPE_RQ, SLI4_FCOE_RQE_SIZE,
8486 n_entries, SLI_PAGE_SIZE)) {
8491 total_page_count = sli_page_count(qs[0]->dma.size, SLI_PAGE_SIZE) * num_rq_pairs * 2;
8493 /* Payload length must accommodate both request and response */
8494 payload_size = max((sizeof(sli4_req_fcoe_rq_create_v1_t) + (8 * total_page_count)),
8495 sizeof(sli4_res_common_create_queue_set_t));
8497 if (ocs_dma_alloc(sli4->os, &dma, payload_size, SLI_PAGE_SIZE)) {
8498 ocs_log_err(sli4->os, "DMA allocation failed\n");
8501 ocs_memset(dma.virt, 0, payload_size);
8503 if (sli_cmd_sli_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
8504 payload_size, &dma) == -1) {
8507 req = (sli4_req_fcoe_rq_create_v2_t *)((uint8_t *)dma.virt);
8509 /* Fill Header fields */
8510 req->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
8511 req->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
8512 req->hdr.version = 2;
8513 req->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_v2_t) - sizeof(sli4_req_hdr_t)
8514 + (8 * total_page_count);
8516 /* Fill Payload fields */
8518 req->num_pages = sli_page_count(qs[0]->dma.size, SLI_PAGE_SIZE);
8519 req->rqe_count = qs[0]->dma.size / SLI4_FCOE_RQE_SIZE;
8520 req->rqe_size = SLI4_FCOE_RQE_SIZE_8;
8521 req->page_size = SLI4_FCOE_RQ_PAGE_SIZE_4096;
8522 req->rq_count = num_rq_pairs * 2;
8523 req->base_cq_id = base_cq_id;
8524 req->hdr_buffer_size = header_buffer_size;
8525 req->payload_buffer_size = payload_buffer_size;
8527 for (i = 0; i < (num_rq_pairs * 2); i++) {
8528 for (p = 0, addr = qs[i]->dma.phys; p < req->num_pages; p++, addr += SLI_PAGE_SIZE) {
8529 req->page_physical_address[offset].low = ocs_addr32_lo(addr);
8530 req->page_physical_address[offset].high = ocs_addr32_hi(addr);
8535 if (sli_bmbx_command(sli4)){
8536 ocs_log_crit(sli4->os, "bootstrap mailbox write faild RQSet\n");
8541 rsp = (void *)((uint8_t *)dma.virt);
8542 if (rsp->hdr.status) {
8543 ocs_log_err(sli4->os, "bad create RQSet status=%#x addl=%#x\n",
8544 rsp->hdr.status, rsp->hdr.additional_status);
8547 for (i = 0; i < (num_rq_pairs * 2); i++) {
8548 qs[i]->id = i + rsp->q_id;
8549 if ((qs[i]->id & 1) == 0) {
8550 qs[i]->u.flag.is_hdr = TRUE;
8552 qs[i]->u.flag.is_hdr = FALSE;
8554 qs[i]->doorbell_offset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].off;
8555 qs[i]->doorbell_rset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].rset;
8559 ocs_dma_free(sli4->os, &dma);
8564 for (i = 0; i < (num_rq_pairs * 2); i++) {
8565 if (qs[i]->dma.size) {
8566 ocs_dma_free(sli4->os, &qs[i]->dma);
8571 ocs_dma_free(sli4->os, &dma);
8579 * @brief Get the RPI resource requirements.
8581 * @param sli4 SLI context.
8582 * @param n_rpi Number of RPIs desired.
8584 * @return Returns the number of bytes needed. This value may be zero.
8587 sli_fc_get_rpi_requirements(sli4_t *sli4, uint32_t n_rpi)
8591 /* Check if header templates needed */
8592 if (sli4->config.hdr_template_req) {
8593 /* round up to a page */
8594 bytes = SLI_ROUND_PAGE(n_rpi * SLI4_FCOE_HDR_TEMPLATE_SIZE);
8602 * @brief Return a text string corresponding to a CQE status value
8604 * @param status Status value
8606 * @return Returns corresponding string, otherwise "unknown"
8609 sli_fc_get_status_string(uint32_t status)
8615 {SLI4_FC_WCQE_STATUS_SUCCESS, "SUCCESS"},
8616 {SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE, "FCP_RSP_FAILURE"},
8617 {SLI4_FC_WCQE_STATUS_REMOTE_STOP, "REMOTE_STOP"},
8618 {SLI4_FC_WCQE_STATUS_LOCAL_REJECT, "LOCAL_REJECT"},
8619 {SLI4_FC_WCQE_STATUS_NPORT_RJT, "NPORT_RJT"},
8620 {SLI4_FC_WCQE_STATUS_FABRIC_RJT, "FABRIC_RJT"},
8621 {SLI4_FC_WCQE_STATUS_NPORT_BSY, "NPORT_BSY"},
8622 {SLI4_FC_WCQE_STATUS_FABRIC_BSY, "FABRIC_BSY"},
8623 {SLI4_FC_WCQE_STATUS_LS_RJT, "LS_RJT"},
8624 {SLI4_FC_WCQE_STATUS_CMD_REJECT, "CMD_REJECT"},
8625 {SLI4_FC_WCQE_STATUS_FCP_TGT_LENCHECK, "FCP_TGT_LENCHECK"},
8626 {SLI4_FC_WCQE_STATUS_RQ_BUF_LEN_EXCEEDED, "BUF_LEN_EXCEEDED"},
8627 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_BUF_NEEDED, "RQ_INSUFF_BUF_NEEDED"},
8628 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_FRM_DISC, "RQ_INSUFF_FRM_DESC"},
8629 {SLI4_FC_WCQE_STATUS_RQ_DMA_FAILURE, "RQ_DMA_FAILURE"},
8630 {SLI4_FC_WCQE_STATUS_FCP_RSP_TRUNCATE, "FCP_RSP_TRUNCATE"},
8631 {SLI4_FC_WCQE_STATUS_DI_ERROR, "DI_ERROR"},
8632 {SLI4_FC_WCQE_STATUS_BA_RJT, "BA_RJT"},
8633 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_XRI_NEEDED, "RQ_INSUFF_XRI_NEEDED"},
8634 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_XRI_DISC, "INSUFF_XRI_DISC"},
8635 {SLI4_FC_WCQE_STATUS_RX_ERROR_DETECT, "RX_ERROR_DETECT"},
8636 {SLI4_FC_WCQE_STATUS_RX_ABORT_REQUEST, "RX_ABORT_REQUEST"},
8640 for (i = 0; i < ARRAY_SIZE(lookup); i++) {
8641 if (status == lookup[i].code) {
8642 return lookup[i].label;