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);
1871 ocs_log_test(sli4->os, "unsupported IF_TYPE %d\n", if_type);
1875 return (sli_config_off + cmd_size);
1879 * @brief Write a COMMON_DESTROY_CQ command.
1881 * @param sli4 SLI context.
1882 * @param buf Destination buffer for the command.
1883 * @param size Buffer size, in bytes.
1884 * @param cq_id CQ ID
1886 * @note This creates a Version 0 message.
1888 * @return Returns the number of bytes written.
1891 sli_cmd_common_destroy_cq(sli4_t *sli4, void *buf, size_t size, uint16_t cq_id)
1893 sli4_req_common_destroy_cq_t *cq = NULL;
1894 uint32_t sli_config_off = 0;
1896 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1897 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
1898 /* Payload length must accommodate both request and response */
1899 max(sizeof(sli4_req_common_destroy_cq_t),
1900 sizeof(sli4_res_hdr_t)),
1903 cq = (sli4_req_common_destroy_cq_t *)((uint8_t *)buf + sli_config_off);
1905 cq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_CQ;
1906 cq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1907 cq->hdr.request_length = sizeof(sli4_req_common_destroy_cq_t) -
1908 sizeof(sli4_req_hdr_t);
1911 return(sli_config_off + sizeof(sli4_req_common_destroy_cq_t));
1915 * @brief Write a COMMON_MODIFY_EQ_DELAY command.
1917 * @param sli4 SLI context.
1918 * @param buf Destination buffer for the command.
1919 * @param size Buffer size, in bytes.
1920 * @param q Queue object array.
1921 * @param num_q Queue object array count.
1922 * @param shift Phase shift for staggering interrupts.
1923 * @param delay_mult Delay multiplier for limiting interrupt frequency.
1925 * @return Returns the number of bytes written.
1928 sli_cmd_common_modify_eq_delay(sli4_t *sli4, void *buf, size_t size, sli4_queue_t *q, int num_q, uint32_t shift,
1929 uint32_t delay_mult)
1931 sli4_req_common_modify_eq_delay_t *modify_delay = NULL;
1932 uint32_t sli_config_off = 0;
1935 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1936 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
1937 /* Payload length must accommodate both request and response */
1938 max(sizeof(sli4_req_common_modify_eq_delay_t), sizeof(sli4_res_hdr_t)),
1942 modify_delay = (sli4_req_common_modify_eq_delay_t *)((uint8_t *)buf + sli_config_off);
1944 modify_delay->hdr.opcode = SLI4_OPC_COMMON_MODIFY_EQ_DELAY;
1945 modify_delay->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
1946 modify_delay->hdr.request_length = sizeof(sli4_req_common_modify_eq_delay_t) -
1947 sizeof(sli4_req_hdr_t);
1949 modify_delay->num_eq = num_q;
1951 for (i = 0; i<num_q; i++) {
1952 modify_delay->eq_delay_record[i].eq_id = q[i].id;
1953 modify_delay->eq_delay_record[i].phase = shift;
1954 modify_delay->eq_delay_record[i].delay_multiplier = delay_mult;
1957 return(sli_config_off + sizeof(sli4_req_common_modify_eq_delay_t));
1961 * @brief Write a COMMON_CREATE_EQ command.
1963 * @param sli4 SLI context.
1964 * @param buf Destination buffer for the command.
1965 * @param size Buffer size, in bytes.
1966 * @param qmem DMA memory for the queue.
1967 * @param ignored1 Ignored (used for consistency among queue creation functions).
1968 * @param ignored2 Ignored (used for consistency among queue creation functions).
1970 * @note Other queue creation routines use the last parameter to pass in
1971 * the associated Q_ID and ULP. EQ doesn't have an associated queue or ULP,
1972 * so these parameters are ignored
1974 * @note This creates a Version 0 message
1976 * @return Returns the number of bytes written.
1979 sli_cmd_common_create_eq(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *qmem,
1980 uint16_t ignored1, uint16_t ignored2)
1982 sli4_req_common_create_eq_t *eq = NULL;
1983 uint32_t sli_config_off = 0;
1987 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
1988 uint32_t payload_size;
1990 /* Payload length must accommodate both request and response */
1991 payload_size = max(sizeof(sli4_req_common_create_eq_t),
1992 sizeof(sli4_res_common_create_queue_t));
1994 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
1997 eq = (sli4_req_common_create_eq_t *)((uint8_t *)buf + sli_config_off);
1999 eq->hdr.opcode = SLI4_OPC_COMMON_CREATE_EQ;
2000 eq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2001 eq->hdr.request_length = sizeof(sli4_req_common_create_eq_t) -
2002 sizeof(sli4_req_hdr_t);
2003 /* valid values for number of pages: 1, 2, 4 (sec 4.4.3) */
2004 eq->num_pages = qmem->size / SLI_PAGE_SIZE;
2005 switch (eq->num_pages) {
2007 eq->eqesz = SLI4_EQE_SIZE_4;
2008 eq->count = SLI4_EQ_CNT_1024;
2011 eq->eqesz = SLI4_EQE_SIZE_4;
2012 eq->count = SLI4_EQ_CNT_2048;
2015 eq->eqesz = SLI4_EQE_SIZE_4;
2016 eq->count = SLI4_EQ_CNT_4096;
2019 ocs_log_test(sli4->os, "num_pages %d not valid\n", eq->num_pages);
2024 eq->delay_multiplier = 32;
2026 for (p = 0, addr = qmem->phys;
2028 p++, addr += SLI_PAGE_SIZE) {
2029 eq->page_address[p].low = ocs_addr32_lo(addr);
2030 eq->page_address[p].high = ocs_addr32_hi(addr);
2033 return(sli_config_off + sizeof(sli4_req_common_create_eq_t));
2038 * @brief Write a COMMON_DESTROY_EQ command.
2040 * @param sli4 SLI context.
2041 * @param buf Destination buffer for the command.
2042 * @param size Buffer size, in bytes.
2043 * @param eq_id Queue ID to destroy.
2045 * @note Other queue creation routines use the last parameter to pass in
2046 * the associated Q_ID. EQ doesn't have an associated queue so this
2047 * parameter is ignored.
2049 * @note This creates a Version 0 message.
2051 * @return Returns the number of bytes written.
2054 sli_cmd_common_destroy_eq(sli4_t *sli4, void *buf, size_t size, uint16_t eq_id)
2056 sli4_req_common_destroy_eq_t *eq = NULL;
2057 uint32_t sli_config_off = 0;
2059 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2060 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2061 /* Payload length must accommodate both request and response */
2062 max(sizeof(sli4_req_common_destroy_eq_t),
2063 sizeof(sli4_res_hdr_t)),
2066 eq = (sli4_req_common_destroy_eq_t *)((uint8_t *)buf + sli_config_off);
2068 eq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_EQ;
2069 eq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2070 eq->hdr.request_length = sizeof(sli4_req_common_destroy_eq_t) -
2071 sizeof(sli4_req_hdr_t);
2075 return(sli_config_off + sizeof(sli4_req_common_destroy_eq_t));
2079 * @brief Write a LOWLEVEL_SET_WATCHDOG command.
2081 * @param sli4 SLI context.
2082 * @param buf Destination buffer for the command.
2083 * @param size Buffer size, in bytes.
2084 * @param timeout watchdog timer timeout in seconds
2089 sli4_cmd_lowlevel_set_watchdog(sli4_t *sli4, void *buf, size_t size, uint16_t timeout)
2092 sli4_req_lowlevel_set_watchdog_t *req = NULL;
2093 uint32_t sli_config_off = 0;
2095 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2096 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2097 /* Payload length must accommodate both request and response */
2098 max(sizeof(sli4_req_lowlevel_set_watchdog_t),
2099 sizeof(sli4_res_lowlevel_set_watchdog_t)),
2102 req = (sli4_req_lowlevel_set_watchdog_t *)((uint8_t *)buf + sli_config_off);
2104 req->hdr.opcode = SLI4_OPC_LOWLEVEL_SET_WATCHDOG;
2105 req->hdr.subsystem = SLI4_SUBSYSTEM_LOWLEVEL;
2106 req->hdr.request_length = sizeof(sli4_req_lowlevel_set_watchdog_t) - sizeof(sli4_req_hdr_t);
2107 req->watchdog_timeout = timeout;
2113 sli_cmd_common_get_cntl_attributes(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2115 sli4_req_hdr_t *hdr = NULL;
2116 uint32_t sli_config_off = 0;
2118 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2119 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2120 sizeof(sli4_req_hdr_t),
2128 ocs_memset(dma->virt, 0, dma->size);
2132 hdr->opcode = SLI4_OPC_COMMON_GET_CNTL_ATTRIBUTES;
2133 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2134 hdr->request_length = dma->size;
2136 return(sli_config_off + sizeof(sli4_req_hdr_t));
2140 * @brief Write a COMMON_GET_CNTL_ADDL_ATTRIBUTES command.
2142 * @param sli4 SLI context.
2143 * @param buf Destination buffer for the command.
2144 * @param size Buffer size, in bytes.
2145 * @param dma DMA structure from which the data will be copied.
2147 * @note This creates a Version 0 message.
2149 * @return Returns the number of bytes written.
2152 sli_cmd_common_get_cntl_addl_attributes(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2154 sli4_req_hdr_t *hdr = NULL;
2155 uint32_t sli_config_off = 0;
2157 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2158 sli_config_off = sli_cmd_sli_config(sli4, buf, size, sizeof(sli4_req_hdr_t), dma);
2165 ocs_memset(dma->virt, 0, dma->size);
2169 hdr->opcode = SLI4_OPC_COMMON_GET_CNTL_ADDL_ATTRIBUTES;
2170 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2171 hdr->request_length = dma->size;
2173 return(sli_config_off + sizeof(sli4_req_hdr_t));
2177 * @brief Write a COMMON_CREATE_MQ_EXT command.
2179 * @param sli4 SLI context.
2180 * @param buf Destination buffer for the command.
2181 * @param size Buffer size, in bytes.
2182 * @param qmem DMA memory for the queue.
2183 * @param cq_id Associated CQ_ID.
2184 * @param ignored This parameter carries the ULP which is only used for WQ and RQs
2186 * @note This creates a Version 0 message.
2188 * @return Returns the number of bytes written.
2191 sli_cmd_common_create_mq_ext(sli4_t *sli4, void *buf, size_t size,
2192 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ignored)
2194 sli4_req_common_create_mq_ext_t *mq = NULL;
2195 uint32_t sli_config_off = 0;
2199 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2200 uint32_t payload_size;
2202 /* Payload length must accommodate both request and response */
2203 payload_size = max(sizeof(sli4_req_common_create_mq_ext_t),
2204 sizeof(sli4_res_common_create_queue_t));
2206 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
2209 mq = (sli4_req_common_create_mq_ext_t *)((uint8_t *)buf + sli_config_off);
2211 mq->hdr.opcode = SLI4_OPC_COMMON_CREATE_MQ_EXT;
2212 mq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2213 mq->hdr.request_length = sizeof(sli4_req_common_create_mq_ext_t) -
2214 sizeof(sli4_req_hdr_t);
2215 /* valid values for number of pages: 1, 2, 4, 8 (sec 4.4.12) */
2216 mq->num_pages = qmem->size / SLI_PAGE_SIZE;
2217 switch (mq->num_pages) {
2219 mq->ring_size = SLI4_MQE_SIZE_16;
2222 mq->ring_size = SLI4_MQE_SIZE_32;
2225 mq->ring_size = SLI4_MQE_SIZE_64;
2228 mq->ring_size = SLI4_MQE_SIZE_128;
2231 ocs_log_test(sli4->os, "num_pages %d not valid\n", mq->num_pages);
2235 /* TODO break this down by sli4->config.topology */
2236 mq->async_event_bitmap = SLI4_ASYNC_EVT_FC_FCOE;
2238 if (sli4->config.mq_create_version) {
2239 mq->cq_id_v1 = cq_id;
2240 mq->hdr.version = 1;
2243 mq->cq_id_v0 = cq_id;
2247 for (p = 0, addr = qmem->phys;
2249 p++, addr += SLI_PAGE_SIZE) {
2250 mq->page_physical_address[p].low = ocs_addr32_lo(addr);
2251 mq->page_physical_address[p].high = ocs_addr32_hi(addr);
2254 return(sli_config_off + sizeof(sli4_req_common_create_mq_ext_t));
2258 * @brief Write a COMMON_DESTROY_MQ command.
2260 * @param sli4 SLI context.
2261 * @param buf Destination buffer for the command.
2262 * @param size Buffer size, in bytes.
2263 * @param mq_id MQ ID
2265 * @note This creates a Version 0 message.
2267 * @return Returns the number of bytes written.
2270 sli_cmd_common_destroy_mq(sli4_t *sli4, void *buf, size_t size, uint16_t mq_id)
2272 sli4_req_common_destroy_mq_t *mq = NULL;
2273 uint32_t sli_config_off = 0;
2275 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2276 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2277 /* Payload length must accommodate both request and response */
2278 max(sizeof(sli4_req_common_destroy_mq_t),
2279 sizeof(sli4_res_hdr_t)),
2282 mq = (sli4_req_common_destroy_mq_t *)((uint8_t *)buf + sli_config_off);
2284 mq->hdr.opcode = SLI4_OPC_COMMON_DESTROY_MQ;
2285 mq->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2286 mq->hdr.request_length = sizeof(sli4_req_common_destroy_mq_t) -
2287 sizeof(sli4_req_hdr_t);
2291 return(sli_config_off + sizeof(sli4_req_common_destroy_mq_t));
2296 * @brief Write a COMMON_NOP command
2298 * @param sli4 SLI context.
2299 * @param buf Destination buffer for the command.
2300 * @param size Buffer size, in bytes.
2301 * @param context NOP context value (passed to response, except on FC/FCoE).
2303 * @return Returns the number of bytes written.
2306 sli_cmd_common_nop(sli4_t *sli4, void *buf, size_t size, uint64_t context)
2308 sli4_req_common_nop_t *nop = NULL;
2309 uint32_t sli_config_off = 0;
2311 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2312 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2313 /* Payload length must accommodate both request and response */
2314 max(sizeof(sli4_req_common_nop_t), sizeof(sli4_res_common_nop_t)),
2318 nop = (sli4_req_common_nop_t *)((uint8_t *)buf + sli_config_off);
2320 nop->hdr.opcode = SLI4_OPC_COMMON_NOP;
2321 nop->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2322 nop->hdr.request_length = 8;
2324 ocs_memcpy(&nop->context, &context, sizeof(context));
2326 return(sli_config_off + sizeof(sli4_req_common_nop_t));
2331 * @brief Write a COMMON_GET_RESOURCE_EXTENT_INFO command.
2333 * @param sli4 SLI context.
2334 * @param buf Destination buffer for the command.
2335 * @param size Buffer size, in bytes.
2336 * @param rtype Resource type (for example, XRI, VFI, VPI, and RPI).
2338 * @return Returns the number of bytes written.
2341 sli_cmd_common_get_resource_extent_info(sli4_t *sli4, void *buf, size_t size, uint16_t rtype)
2343 sli4_req_common_get_resource_extent_info_t *extent = NULL;
2344 uint32_t sli_config_off = 0;
2346 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2347 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2348 sizeof(sli4_req_common_get_resource_extent_info_t),
2352 extent = (sli4_req_common_get_resource_extent_info_t *)((uint8_t *)buf + sli_config_off);
2354 extent->hdr.opcode = SLI4_OPC_COMMON_GET_RESOURCE_EXTENT_INFO;
2355 extent->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2356 extent->hdr.request_length = 4;
2358 extent->resource_type = rtype;
2360 return(sli_config_off + sizeof(sli4_req_common_get_resource_extent_info_t));
2365 * @brief Write a COMMON_GET_SLI4_PARAMETERS command.
2367 * @param sli4 SLI context.
2368 * @param buf Destination buffer for the command.
2369 * @param size Buffer size, in bytes.
2371 * @return Returns the number of bytes written.
2374 sli_cmd_common_get_sli4_parameters(sli4_t *sli4, void *buf, size_t size)
2376 sli4_req_hdr_t *hdr = NULL;
2377 uint32_t sli_config_off = 0;
2379 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2380 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2381 sizeof(sli4_res_common_get_sli4_parameters_t),
2385 hdr = (sli4_req_hdr_t *)((uint8_t *)buf + sli_config_off);
2387 hdr->opcode = SLI4_OPC_COMMON_GET_SLI4_PARAMETERS;
2388 hdr->subsystem = SLI4_SUBSYSTEM_COMMON;
2389 hdr->request_length = 0x50;
2391 return(sli_config_off + sizeof(sli4_req_hdr_t));
2395 * @brief Write a COMMON_QUERY_FW_CONFIG command to the provided buffer.
2397 * @param sli4 SLI context pointer.
2398 * @param buf Virtual pointer to destination buffer.
2399 * @param size Buffer size in bytes.
2401 * @return Returns the number of bytes written
2404 sli_cmd_common_query_fw_config(sli4_t *sli4, void *buf, size_t size)
2406 sli4_req_common_query_fw_config_t *fw_config;
2407 uint32_t sli_config_off = 0;
2408 uint32_t payload_size;
2410 /* Payload length must accommodate both request and response */
2411 payload_size = max(sizeof(sli4_req_common_query_fw_config_t),
2412 sizeof(sli4_res_common_query_fw_config_t));
2414 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2415 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2420 fw_config = (sli4_req_common_query_fw_config_t*)((uint8_t*)buf + sli_config_off);
2421 fw_config->hdr.opcode = SLI4_OPC_COMMON_QUERY_FW_CONFIG;
2422 fw_config->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2423 fw_config->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2424 return sli_config_off + sizeof(sli4_req_common_query_fw_config_t);
2428 * @brief Write a COMMON_GET_PORT_NAME command to the provided buffer.
2430 * @param sli4 SLI context pointer.
2431 * @param buf Virtual pointer to destination buffer.
2432 * @param size Buffer size in bytes.
2434 * @note Function supports both version 0 and 1 forms of this command via
2437 * @return Returns the number of bytes written.
2440 sli_cmd_common_get_port_name(sli4_t *sli4, void *buf, size_t size)
2442 sli4_req_common_get_port_name_t *port_name;
2443 uint32_t sli_config_off = 0;
2444 uint32_t payload_size;
2445 uint8_t version = 0;
2448 /* Select command version according to IF_TYPE */
2449 switch (sli4->if_type) {
2450 case SLI4_IF_TYPE_BE3_SKH_PF:
2451 case SLI4_IF_TYPE_BE3_SKH_VF:
2454 case SLI4_IF_TYPE_LANCER_FC_ETH:
2455 case SLI4_IF_TYPE_LANCER_RDMA:
2459 ocs_log_test(sli4->os, "unsupported IF_TYPE %d\n", sli4->if_type);
2463 /* Payload length must accommodate both request and response */
2464 payload_size = max(sizeof(sli4_req_common_get_port_name_t),
2465 sizeof(sli4_res_common_get_port_name_t));
2467 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2468 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2475 port_name = (sli4_req_common_get_port_name_t *)((uint8_t *)buf + sli_config_off);
2477 port_name->hdr.opcode = SLI4_OPC_COMMON_GET_PORT_NAME;
2478 port_name->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2479 port_name->hdr.request_length = sizeof(sli4_req_hdr_t) + (version * sizeof(uint32_t));
2480 port_name->hdr.version = version;
2482 /* Set the port type value (ethernet=0, FC=1) for V1 commands */
2487 return sli_config_off + port_name->hdr.request_length;
2493 * @brief Write a COMMON_WRITE_OBJECT command.
2495 * @param sli4 SLI context.
2496 * @param buf Destination buffer for the command.
2497 * @param size Buffer size, in bytes.
2498 * @param noc True if the object should be written but not committed to flash.
2499 * @param eof True if this is the last write for this object.
2500 * @param desired_write_length Number of bytes of data to write to the object.
2501 * @param offset Offset, in bytes, from the start of the object.
2502 * @param object_name Name of the object to write.
2503 * @param dma DMA structure from which the data will be copied.
2505 * @return Returns the number of bytes written.
2508 sli_cmd_common_write_object(sli4_t *sli4, void *buf, size_t size,
2509 uint16_t noc, uint16_t eof, uint32_t desired_write_length,
2514 sli4_req_common_write_object_t *wr_obj = NULL;
2515 uint32_t sli_config_off = 0;
2516 sli4_bde_t *host_buffer;
2518 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2519 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2520 sizeof (sli4_req_common_write_object_t) + sizeof (sli4_bde_t),
2524 wr_obj = (sli4_req_common_write_object_t *)((uint8_t *)buf + sli_config_off);
2526 wr_obj->hdr.opcode = SLI4_OPC_COMMON_WRITE_OBJECT;
2527 wr_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2528 wr_obj->hdr.request_length = sizeof(*wr_obj) - 4*sizeof(uint32_t) + sizeof(sli4_bde_t);
2529 wr_obj->hdr.timeout = 0;
2530 wr_obj->hdr.version = 0;
2534 wr_obj->desired_write_length = desired_write_length;
2535 wr_obj->write_offset = offset;
2536 ocs_strncpy(wr_obj->object_name, object_name, sizeof(wr_obj->object_name));
2537 wr_obj->host_buffer_descriptor_count = 1;
2539 host_buffer = (sli4_bde_t *)wr_obj->host_buffer_descriptor;
2541 /* Setup to transfer xfer_size bytes to device */
2542 host_buffer->bde_type = SLI4_BDE_TYPE_BDE_64;
2543 host_buffer->buffer_length = desired_write_length;
2544 host_buffer->u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
2545 host_buffer->u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
2548 return(sli_config_off + sizeof(sli4_req_common_write_object_t) + sizeof (sli4_bde_t));
2554 * @brief Write a COMMON_DELETE_OBJECT command.
2556 * @param sli4 SLI context.
2557 * @param buf Destination buffer for the command.
2558 * @param size Buffer size, in bytes.
2559 * @param object_name Name of the object to write.
2561 * @return Returns the number of bytes written.
2564 sli_cmd_common_delete_object(sli4_t *sli4, void *buf, size_t size,
2567 sli4_req_common_delete_object_t *del_obj = NULL;
2568 uint32_t sli_config_off = 0;
2570 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2571 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2572 sizeof (sli4_req_common_delete_object_t),
2576 del_obj = (sli4_req_common_delete_object_t *)((uint8_t *)buf + sli_config_off);
2578 del_obj->hdr.opcode = SLI4_OPC_COMMON_DELETE_OBJECT;
2579 del_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2580 del_obj->hdr.request_length = sizeof(*del_obj);
2581 del_obj->hdr.timeout = 0;
2582 del_obj->hdr.version = 0;
2584 ocs_strncpy(del_obj->object_name, object_name, sizeof(del_obj->object_name));
2585 return(sli_config_off + sizeof(sli4_req_common_delete_object_t));
2590 * @brief Write a COMMON_READ_OBJECT command.
2592 * @param sli4 SLI context.
2593 * @param buf Destination buffer for the command.
2594 * @param size Buffer size, in bytes.
2595 * @param desired_read_length Number of bytes of data to read from the object.
2596 * @param offset Offset, in bytes, from the start of the object.
2597 * @param object_name Name of the object to read.
2598 * @param dma DMA structure from which the data will be copied.
2600 * @return Returns the number of bytes written.
2603 sli_cmd_common_read_object(sli4_t *sli4, void *buf, size_t size,
2604 uint32_t desired_read_length,
2609 sli4_req_common_read_object_t *rd_obj = NULL;
2610 uint32_t sli_config_off = 0;
2611 sli4_bde_t *host_buffer;
2613 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2614 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2615 sizeof (sli4_req_common_read_object_t) + sizeof (sli4_bde_t),
2619 rd_obj = (sli4_req_common_read_object_t *)((uint8_t *)buf + sli_config_off);
2621 rd_obj->hdr.opcode = SLI4_OPC_COMMON_READ_OBJECT;
2622 rd_obj->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2623 rd_obj->hdr.request_length = sizeof(*rd_obj) - 4*sizeof(uint32_t) + sizeof(sli4_bde_t);
2624 rd_obj->hdr.timeout = 0;
2625 rd_obj->hdr.version = 0;
2627 rd_obj->desired_read_length = desired_read_length;
2628 rd_obj->read_offset = offset;
2629 ocs_strncpy(rd_obj->object_name, object_name, sizeof(rd_obj->object_name));
2630 rd_obj->host_buffer_descriptor_count = 1;
2632 host_buffer = (sli4_bde_t *)rd_obj->host_buffer_descriptor;
2634 /* Setup to transfer xfer_size bytes to device */
2635 host_buffer->bde_type = SLI4_BDE_TYPE_BDE_64;
2636 host_buffer->buffer_length = desired_read_length;
2638 host_buffer->u.data.buffer_address_low = ocs_addr32_lo(dma->phys);
2639 host_buffer->u.data.buffer_address_high = ocs_addr32_hi(dma->phys);
2641 host_buffer->u.data.buffer_address_low = 0;
2642 host_buffer->u.data.buffer_address_high = 0;
2646 return(sli_config_off + sizeof(sli4_req_common_read_object_t) + sizeof (sli4_bde_t));
2651 * @brief Write a DMTF_EXEC_CLP_CMD command.
2653 * @param sli4 SLI context.
2654 * @param buf Destination buffer for the command.
2655 * @param size Buffer size, in bytes.
2656 * @param cmd DMA structure that describes the buffer for the command.
2657 * @param resp DMA structure that describes the buffer for the response.
2659 * @return Returns the number of bytes written.
2662 sli_cmd_dmtf_exec_clp_cmd(sli4_t *sli4, void *buf, size_t size,
2666 sli4_req_dmtf_exec_clp_cmd_t *clp_cmd = NULL;
2667 uint32_t sli_config_off = 0;
2669 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2670 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2671 sizeof (sli4_req_dmtf_exec_clp_cmd_t),
2675 clp_cmd = (sli4_req_dmtf_exec_clp_cmd_t*)((uint8_t *)buf + sli_config_off);
2677 clp_cmd->hdr.opcode = SLI4_OPC_DMTF_EXEC_CLP_CMD;
2678 clp_cmd->hdr.subsystem = SLI4_SUBSYSTEM_DMTF;
2679 clp_cmd->hdr.request_length = sizeof(sli4_req_dmtf_exec_clp_cmd_t) -
2680 sizeof(sli4_req_hdr_t);
2681 clp_cmd->hdr.timeout = 0;
2682 clp_cmd->hdr.version = 0;
2683 clp_cmd->cmd_buf_length = cmd->size;
2684 clp_cmd->cmd_buf_addr_low = ocs_addr32_lo(cmd->phys);
2685 clp_cmd->cmd_buf_addr_high = ocs_addr32_hi(cmd->phys);
2686 clp_cmd->resp_buf_length = resp->size;
2687 clp_cmd->resp_buf_addr_low = ocs_addr32_lo(resp->phys);
2688 clp_cmd->resp_buf_addr_high = ocs_addr32_hi(resp->phys);
2690 return(sli_config_off + sizeof(sli4_req_dmtf_exec_clp_cmd_t));
2695 * @brief Write a COMMON_SET_DUMP_LOCATION command.
2697 * @param sli4 SLI context.
2698 * @param buf Destination buffer for the command.
2699 * @param size Buffer size, in bytes.
2700 * @param query Zero to set dump location, non-zero to query dump size
2701 * @param is_buffer_list Set to one if the buffer is a set of buffer descriptors or
2702 * set to 0 if the buffer is a contiguous dump area.
2703 * @param buffer DMA structure to which the dump will be copied.
2705 * @return Returns the number of bytes written.
2708 sli_cmd_common_set_dump_location(sli4_t *sli4, void *buf, size_t size,
2709 uint8_t query, uint8_t is_buffer_list,
2710 ocs_dma_t *buffer, uint8_t fdb)
2712 sli4_req_common_set_dump_location_t *set_dump_loc = NULL;
2713 uint32_t sli_config_off = 0;
2715 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2716 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2717 sizeof (sli4_req_common_set_dump_location_t),
2721 set_dump_loc = (sli4_req_common_set_dump_location_t *)((uint8_t *)buf + sli_config_off);
2723 set_dump_loc->hdr.opcode = SLI4_OPC_COMMON_SET_DUMP_LOCATION;
2724 set_dump_loc->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2725 set_dump_loc->hdr.request_length = sizeof(sli4_req_common_set_dump_location_t) - sizeof(sli4_req_hdr_t);
2726 set_dump_loc->hdr.timeout = 0;
2727 set_dump_loc->hdr.version = 0;
2729 set_dump_loc->blp = is_buffer_list;
2730 set_dump_loc->qry = query;
2731 set_dump_loc->fdb = fdb;
2734 set_dump_loc->buf_addr_low = ocs_addr32_lo(buffer->phys);
2735 set_dump_loc->buf_addr_high = ocs_addr32_hi(buffer->phys);
2736 set_dump_loc->buffer_length = buffer->len;
2738 set_dump_loc->buf_addr_low = 0;
2739 set_dump_loc->buf_addr_high = 0;
2740 set_dump_loc->buffer_length = 0;
2743 return(sli_config_off + sizeof(sli4_req_common_set_dump_location_t));
2749 * @brief Write a COMMON_SET_FEATURES command.
2751 * @param sli4 SLI context.
2752 * @param buf Destination buffer for the command.
2753 * @param size Buffer size, in bytes.
2754 * @param feature Feature to set.
2755 * @param param_len Length of the parameter (must be a multiple of 4 bytes).
2756 * @param parameter Pointer to the parameter value.
2758 * @return Returns the number of bytes written.
2761 sli_cmd_common_set_features(sli4_t *sli4, void *buf, size_t size,
2766 sli4_req_common_set_features_t *cmd = NULL;
2767 uint32_t sli_config_off = 0;
2769 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2770 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2771 sizeof (sli4_req_common_set_features_t),
2775 cmd = (sli4_req_common_set_features_t *)((uint8_t *)buf + sli_config_off);
2777 cmd->hdr.opcode = SLI4_OPC_COMMON_SET_FEATURES;
2778 cmd->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2779 cmd->hdr.request_length = sizeof(sli4_req_common_set_features_t) - sizeof(sli4_req_hdr_t);
2780 cmd->hdr.timeout = 0;
2781 cmd->hdr.version = 0;
2783 cmd->feature = feature;
2784 cmd->param_len = param_len;
2785 ocs_memcpy(cmd->params, parameter, param_len);
2787 return(sli_config_off + sizeof(sli4_req_common_set_features_t));
2792 * @brief Write a COMMON_COMMON_GET_PROFILE_CONFIG command.
2794 * @param sli4 SLI context.
2795 * @param buf Destination buffer for the command.
2796 * @param size Buffer size in bytes.
2797 * @param dma DMA capable memory used to retrieve profile.
2799 * @return Returns the number of bytes written.
2802 sli_cmd_common_get_profile_config(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
2804 sli4_req_common_get_profile_config_t *req = NULL;
2805 uint32_t sli_config_off = 0;
2806 uint32_t payload_size;
2808 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2809 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
2810 sizeof (sli4_req_common_get_profile_config_t),
2816 ocs_memset(req, 0, dma->size);
2817 payload_size = dma->size;
2819 req = (sli4_req_common_get_profile_config_t *)((uint8_t *)buf + sli_config_off);
2820 payload_size = sizeof(sli4_req_common_get_profile_config_t);
2823 req->hdr.opcode = SLI4_OPC_COMMON_GET_PROFILE_CONFIG;
2824 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2825 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2826 req->hdr.version = 1;
2828 return(sli_config_off + sizeof(sli4_req_common_get_profile_config_t));
2833 * @brief Write a COMMON_COMMON_SET_PROFILE_CONFIG command.
2835 * @param sli4 SLI context.
2836 * @param buf Destination buffer for the command.
2837 * @param size Buffer size, in bytes.
2838 * @param dma DMA capable memory containing profile.
2839 * @param profile_id Profile ID to configure.
2840 * @param descriptor_count Number of descriptors in DMA buffer.
2841 * @param isap Implicit Set Active Profile value to use.
2843 * @return Returns the number of bytes written.
2846 sli_cmd_common_set_profile_config(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma,
2847 uint8_t profile_id, uint32_t descriptor_count, uint8_t isap)
2849 sli4_req_common_set_profile_config_t *req = NULL;
2850 uint32_t cmd_off = 0;
2851 uint32_t payload_size;
2853 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2854 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2855 sizeof (sli4_req_common_set_profile_config_t),
2861 ocs_memset(req, 0, dma->size);
2862 payload_size = dma->size;
2864 req = (sli4_req_common_set_profile_config_t *)((uint8_t *)buf + cmd_off);
2865 payload_size = sizeof(sli4_req_common_set_profile_config_t);
2868 req->hdr.opcode = SLI4_OPC_COMMON_SET_PROFILE_CONFIG;
2869 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2870 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2871 req->hdr.version = 1;
2872 req->profile_id = profile_id;
2873 req->desc_count = descriptor_count;
2876 return(cmd_off + sizeof(sli4_req_common_set_profile_config_t));
2881 * @brief Write a COMMON_COMMON_GET_PROFILE_LIST command.
2883 * @param sli4 SLI context.
2884 * @param buf Destination buffer for the command.
2885 * @param size Buffer size in bytes.
2886 * @param start_profile_index First profile index to return.
2887 * @param dma Buffer into which the list will be written.
2889 * @return Returns the number of bytes written.
2892 sli_cmd_common_get_profile_list(sli4_t *sli4, void *buf, size_t size,
2893 uint32_t start_profile_index, ocs_dma_t *dma)
2895 sli4_req_common_get_profile_list_t *req = NULL;
2896 uint32_t cmd_off = 0;
2897 uint32_t payload_size;
2899 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2900 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2901 sizeof (sli4_req_common_get_profile_list_t),
2907 ocs_memset(req, 0, dma->size);
2908 payload_size = dma->size;
2910 req = (sli4_req_common_get_profile_list_t *)((uint8_t *)buf + cmd_off);
2911 payload_size = sizeof(sli4_req_common_get_profile_list_t);
2914 req->hdr.opcode = SLI4_OPC_COMMON_GET_PROFILE_LIST;
2915 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2916 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2917 req->hdr.version = 0;
2919 req->start_profile_index = start_profile_index;
2921 return(cmd_off + sizeof(sli4_req_common_get_profile_list_t));
2926 * @brief Write a COMMON_COMMON_GET_ACTIVE_PROFILE command.
2928 * @param sli4 SLI context.
2929 * @param buf Destination buffer for the command.
2930 * @param size Buffer size in bytes.
2932 * @return Returns the number of bytes written.
2935 sli_cmd_common_get_active_profile(sli4_t *sli4, void *buf, size_t size)
2937 sli4_req_common_get_active_profile_t *req = NULL;
2938 uint32_t cmd_off = 0;
2939 uint32_t payload_size;
2941 /* Payload length must accommodate both request and response */
2942 payload_size = max(sizeof(sli4_req_common_get_active_profile_t),
2943 sizeof(sli4_res_common_get_active_profile_t));
2945 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2946 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2951 req = (sli4_req_common_get_active_profile_t *)
2952 ((uint8_t*)buf + cmd_off);
2954 req->hdr.opcode = SLI4_OPC_COMMON_GET_ACTIVE_PROFILE;
2955 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2956 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2957 req->hdr.version = 0;
2959 return(cmd_off + sizeof(sli4_req_common_get_active_profile_t));
2964 * @brief Write a COMMON_COMMON_SET_ACTIVE_PROFILE command.
2966 * @param sli4 SLI context.
2967 * @param buf Destination buffer for the command.
2968 * @param size Buffer size in bytes.
2969 * @param fd If non-zero, set profile to factory default.
2970 * @param active_profile_id ID of new active profile.
2972 * @return Returns the number of bytes written.
2975 sli_cmd_common_set_active_profile(sli4_t *sli4, void *buf, size_t size,
2976 uint32_t fd, uint32_t active_profile_id)
2978 sli4_req_common_set_active_profile_t *req = NULL;
2979 uint32_t cmd_off = 0;
2980 uint32_t payload_size;
2982 /* Payload length must accommodate both request and response */
2983 payload_size = max(sizeof(sli4_req_common_set_active_profile_t),
2984 sizeof(sli4_res_common_set_active_profile_t));
2986 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
2987 cmd_off = sli_cmd_sli_config(sli4, buf, size,
2992 req = (sli4_req_common_set_active_profile_t *)
2993 ((uint8_t*)buf + cmd_off);
2995 req->hdr.opcode = SLI4_OPC_COMMON_SET_ACTIVE_PROFILE;
2996 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
2997 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
2998 req->hdr.version = 0;
3000 req->active_profile_id = active_profile_id;
3002 return(cmd_off + sizeof(sli4_req_common_set_active_profile_t));
3007 * @brief Write a COMMON_GET_RECONFIG_LINK_INFO command.
3009 * @param sli4 SLI context.
3010 * @param buf Destination buffer for the command.
3011 * @param size Buffer size in bytes.
3012 * @param dma Buffer to store the supported link configuration modes from the physical device.
3014 * @return Returns the number of bytes written.
3017 sli_cmd_common_get_reconfig_link_info(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma)
3019 sli4_req_common_get_reconfig_link_info_t *req = NULL;
3020 uint32_t cmd_off = 0;
3021 uint32_t payload_size;
3023 /* Payload length must accommodate both request and response */
3024 payload_size = max(sizeof(sli4_req_common_get_reconfig_link_info_t),
3025 sizeof(sli4_res_common_get_reconfig_link_info_t));
3027 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3028 cmd_off = sli_cmd_sli_config(sli4, buf, size,
3035 ocs_memset(req, 0, dma->size);
3036 payload_size = dma->size;
3038 req = (sli4_req_common_get_reconfig_link_info_t *)((uint8_t *)buf + cmd_off);
3039 payload_size = sizeof(sli4_req_common_get_reconfig_link_info_t);
3042 req->hdr.opcode = SLI4_OPC_COMMON_GET_RECONFIG_LINK_INFO;
3043 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
3044 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
3045 req->hdr.version = 0;
3047 return(cmd_off + sizeof(sli4_req_common_get_reconfig_link_info_t));
3052 * @brief Write a COMMON_SET_RECONFIG_LINK_ID command.
3054 * @param sli4 SLI context.
3055 * @param buf destination buffer for the command.
3056 * @param size buffer size in bytes.
3057 * @param fd If non-zero, set link config to factory default.
3058 * @param active_link_config_id ID of new active profile.
3059 * @param dma Buffer to assign the link configuration mode that is to become active from the physical device.
3061 * @return Returns the number of bytes written.
3064 sli_cmd_common_set_reconfig_link_id(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma,
3065 uint32_t fd, uint32_t active_link_config_id)
3067 sli4_req_common_set_reconfig_link_id_t *req = NULL;
3068 uint32_t cmd_off = 0;
3069 uint32_t payload_size;
3071 /* Payload length must accommodate both request and response */
3072 payload_size = max(sizeof(sli4_req_common_set_reconfig_link_id_t),
3073 sizeof(sli4_res_common_set_reconfig_link_id_t));
3075 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3076 cmd_off = sli_cmd_sli_config(sli4, buf, size,
3083 ocs_memset(req, 0, dma->size);
3084 payload_size = dma->size;
3086 req = (sli4_req_common_set_reconfig_link_id_t *)((uint8_t *)buf + cmd_off);
3087 payload_size = sizeof(sli4_req_common_set_reconfig_link_id_t);
3090 req->hdr.opcode = SLI4_OPC_COMMON_SET_RECONFIG_LINK_ID;
3091 req->hdr.subsystem = SLI4_SUBSYSTEM_COMMON;
3092 req->hdr.request_length = payload_size - sizeof(sli4_req_hdr_t);
3093 req->hdr.version = 0;
3095 req->next_link_config_id = active_link_config_id;
3097 return(cmd_off + sizeof(sli4_req_common_set_reconfig_link_id_t));
3103 * @brief Check the mailbox/queue completion entry.
3105 * @param buf Pointer to the MCQE.
3107 * @return Returns 0 on success, or a non-zero value on failure.
3110 sli_cqe_mq(void *buf)
3112 sli4_mcqe_t *mcqe = buf;
3115 * Firmware can split mbx completions into two MCQEs: first with only
3116 * the "consumed" bit set and a second with the "complete" bit set.
3117 * Thus, ignore MCQE unless "complete" is set.
3123 if (mcqe->completion_status) {
3124 ocs_log_debug(NULL, "bad status (cmpl=%#x ext=%#x con=%d cmp=%d ae=%d val=%d)\n",
3125 mcqe->completion_status,
3126 mcqe->extended_status,
3133 return mcqe->completion_status;
3138 * @brief Check the asynchronous event completion entry.
3140 * @param sli4 SLI context.
3141 * @param buf Pointer to the ACQE.
3143 * @return Returns 0 on success, or a non-zero value on failure.
3146 sli_cqe_async(sli4_t *sli4, void *buf)
3148 sli4_acqe_t *acqe = buf;
3151 if (!sli4 || !buf) {
3152 ocs_log_err(NULL, "bad parameter sli4=%p buf=%p\n", sli4, buf);
3156 switch (acqe->event_code) {
3157 case SLI4_ACQE_EVENT_CODE_LINK_STATE:
3158 rc = sli_fc_process_link_state(sli4, buf);
3160 case SLI4_ACQE_EVENT_CODE_FCOE_FIP:
3161 rc = sli_fc_process_fcoe(sli4, buf);
3163 case SLI4_ACQE_EVENT_CODE_GRP_5:
3164 /*TODO*/ocs_log_debug(sli4->os, "ACQE GRP5\n");
3166 case SLI4_ACQE_EVENT_CODE_SLI_PORT_EVENT:
3167 ocs_log_debug(sli4->os,"ACQE SLI Port, type=0x%x, data1,2=0x%08x,0x%08x\n",
3168 acqe->event_type, acqe->event_data[0], acqe->event_data[1]);
3169 #if defined(OCS_INCLUDE_DEBUG)
3170 ocs_dump32(OCS_DEBUG_ALWAYS, sli4->os, "acq", acqe, sizeof(*acqe));
3173 case SLI4_ACQE_EVENT_CODE_FC_LINK_EVENT:
3174 rc = sli_fc_process_link_attention(sli4, buf);
3177 /*TODO*/ocs_log_test(sli4->os, "ACQE unknown=%#x\n", acqe->event_code);
3184 * @brief Check the SLI_CONFIG response.
3187 * Function checks the SLI_CONFIG response and the payload status.
3189 * @param buf Pointer to SLI_CONFIG response.
3191 * @return Returns 0 on success, or a non-zero value on failure.
3194 sli_res_sli_config(void *buf)
3196 sli4_cmd_sli_config_t *sli_config = buf;
3198 if (!buf || (SLI4_MBOX_COMMAND_SLI_CONFIG != sli_config->hdr.command)) {
3199 ocs_log_err(NULL, "bad parameter buf=%p cmd=%#x\n", buf,
3200 buf ? sli_config->hdr.command : -1);
3204 if (sli_config->hdr.status) {
3205 return sli_config->hdr.status;
3208 if (sli_config->emb) {
3209 return sli_config->payload.embed[4];
3211 ocs_log_test(NULL, "external buffers not supported\n");
3217 * @brief Issue a COMMON_FUNCTION_RESET command.
3219 * @param sli4 SLI context.
3221 * @return Returns 0 on success, or a non-zero value on failure.
3224 sli_common_function_reset(sli4_t *sli4)
3227 if (sli_cmd_common_function_reset(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3228 if (sli_bmbx_command(sli4)) {
3229 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COM_FUNC_RESET)\n");
3232 if (sli_res_sli_config(sli4->bmbx.virt)) {
3233 ocs_log_err(sli4->os, "bad status COM_FUNC_RESET\n");
3237 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3246 * @brief check to see if the FW is ready.
3249 * Based on <i>SLI-4 Architecture Specification, Revision 4.x0-13 (2012).</i>.
3251 * @param sli4 SLI context.
3252 * @param timeout_ms Time, in milliseconds, to wait for the port to be ready
3255 * @return Returns TRUE for ready, or FALSE otherwise.
3258 sli_wait_for_fw_ready(sli4_t *sli4, uint32_t timeout_ms)
3260 uint32_t iter = timeout_ms / (SLI4_INIT_PORT_DELAY_US / 1000);
3261 uint32_t ready = FALSE;
3265 ocs_udelay(SLI4_INIT_PORT_DELAY_US);
3266 if (sli_fw_ready(sli4) == 1) {
3269 } while (!ready && (iter > 0));
3275 * @brief Initialize the firmware.
3278 * Based on <i>SLI-4 Architecture Specification, Revision 4.x0-13 (2012).</i>.
3280 * @param sli4 SLI context.
3282 * @return Returns 0 on success, or a non-zero value on failure.
3285 sli_fw_init(sli4_t *sli4)
3291 * Is firmware ready for operation?
3293 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
3295 ocs_log_crit(sli4->os, "FW status is NOT ready\n");
3300 * Reset port to a known state
3302 switch (sli4->if_type) {
3303 case SLI4_IF_TYPE_BE3_SKH_PF:
3304 case SLI4_IF_TYPE_BE3_SKH_VF:
3305 /* No SLIPORT_CONTROL register so use command sequence instead */
3306 if (sli_bmbx_wait(sli4, SLI4_BMBX_DELAY_US)) {
3307 ocs_log_crit(sli4->os, "bootstrap mailbox not ready\n");
3311 if (sli_cmd_fw_initialize(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3312 if (sli_bmbx_command(sli4)) {
3313 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (FW_INIT)\n");
3317 ocs_log_crit(sli4->os, "bad FW_INIT write\n");
3321 if (sli_common_function_reset(sli4)) {
3322 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3326 case SLI4_IF_TYPE_LANCER_FC_ETH:
3327 #if BYTE_ORDER == LITTLE_ENDIAN
3328 endian = SLI4_SLIPORT_CONTROL_LITTLE_ENDIAN;
3330 endian = SLI4_SLIPORT_CONTROL_BIG_ENDIAN;
3333 if (sli_sliport_control(sli4, endian))
3337 ocs_log_test(sli4->os, "if_type %d not supported\n", sli4->if_type);
3345 * @brief Terminate the firmware.
3347 * @param sli4 SLI context.
3349 * @return Returns 0 on success, or a non-zero value on failure.
3352 sli_fw_term(sli4_t *sli4)
3356 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF ||
3357 sli4->if_type == SLI4_IF_TYPE_BE3_SKH_VF) {
3358 /* No SLIPORT_CONTROL register so use command sequence instead */
3359 if (sli_bmbx_wait(sli4, SLI4_BMBX_DELAY_US)) {
3360 ocs_log_crit(sli4->os, "bootstrap mailbox not ready\n");
3364 if (sli_common_function_reset(sli4)) {
3365 ocs_log_err(sli4->os, "bad COM_FUNC_RESET write\n");
3369 if (sli_cmd_fw_deinitialize(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3370 if (sli_bmbx_command(sli4)) {
3371 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (FW_DEINIT)\n");
3375 ocs_log_test(sli4->os, "bad FW_DEINIT write\n");
3379 #if BYTE_ORDER == LITTLE_ENDIAN
3380 endian = SLI4_SLIPORT_CONTROL_LITTLE_ENDIAN;
3382 endian = SLI4_SLIPORT_CONTROL_BIG_ENDIAN;
3384 /* type 2 etc. use SLIPORT_CONTROL to initialize port */
3385 sli_sliport_control(sli4, endian);
3391 * @brief Write the doorbell register associated with the queue object.
3393 * @param sli4 SLI context.
3394 * @param q Queue object.
3396 * @return Returns 0 on success, or a non-zero value on failure.
3399 sli_queue_doorbell(sli4_t *sli4, sli4_queue_t *q)
3405 val = sli_eq_doorbell(q->n_posted, q->id, FALSE);
3406 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3409 val = sli_cq_doorbell(q->n_posted, q->id, FALSE);
3410 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3413 val = SLI4_MQ_DOORBELL(q->n_posted, q->id);
3414 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3418 uint32_t n_posted = q->n_posted;
3420 * FC/FCoE has different rules for Receive Queues. The host
3421 * should only update the doorbell of the RQ-pair containing
3422 * the headers since the header / payload RQs are treated
3423 * as a matched unit.
3425 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
3427 * In RQ-pair, an RQ either contains the FC header
3428 * (i.e. is_hdr == TRUE) or the payload.
3430 * Don't ring doorbell for payload RQ
3432 if (!q->u.flag.is_hdr) {
3436 * Some RQ cannot be incremented one entry at a time. Instead,
3437 * the driver collects a number of entries and updates the
3440 if (q->u.flag.rq_batch) {
3441 if (((q->index + q->n_posted) % SLI4_QUEUE_RQ_BATCH)) {
3444 n_posted = SLI4_QUEUE_RQ_BATCH;
3448 val = SLI4_RQ_DOORBELL(n_posted, q->id);
3449 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3453 val = SLI4_WQ_DOORBELL(q->n_posted, q->index, q->id);
3454 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
3457 ocs_log_test(sli4->os, "bad queue type %d\n", q->type);
3465 sli_request_features(sli4_t *sli4, sli4_features_t *features, uint8_t query)
3468 if (sli_cmd_request_features(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
3469 *features, query)) {
3470 sli4_cmd_request_features_t *req_features = sli4->bmbx.virt;
3472 if (sli_bmbx_command(sli4)) {
3473 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (REQUEST_FEATURES)\n");
3476 if (req_features->hdr.status) {
3477 ocs_log_err(sli4->os, "REQUEST_FEATURES bad status %#x\n",
3478 req_features->hdr.status);
3481 features->dword = req_features->response.dword;
3483 ocs_log_err(sli4->os, "bad REQUEST_FEATURES write\n");
3491 * @brief Calculate max queue entries.
3493 * @param sli4 SLI context.
3495 * @return Returns 0 on success, or a non-zero value on failure.
3498 sli_calc_max_qentries(sli4_t *sli4)
3501 uint32_t alloc_size, qentries, qentry_size;
3503 for (q = SLI_QTYPE_EQ; q < SLI_QTYPE_MAX; q++) {
3504 sli4->config.max_qentries[q] = sli_convert_mask_to_count(sli4->config.count_method[q],
3505 sli4->config.count_mask[q]);
3508 /* single, continguous DMA allocations will be called for each queue
3509 * of size (max_qentries * queue entry size); since these can be large,
3510 * check against the OS max DMA allocation size
3512 for (q = SLI_QTYPE_EQ; q < SLI_QTYPE_MAX; q++) {
3513 qentries = sli4->config.max_qentries[q];
3514 qentry_size = sli_get_queue_entry_size(sli4, q);
3515 alloc_size = qentries * qentry_size;
3516 if (alloc_size > ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE)) {
3517 while (alloc_size > ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE)) {
3518 /* cut the qentries in hwf until alloc_size <= max DMA alloc size */
3520 alloc_size = qentries * qentry_size;
3522 ocs_log_debug(sli4->os, "[%s]: max_qentries from %d to %d (max dma %d)\n",
3523 SLI_QNAME[q], sli4->config.max_qentries[q],
3524 qentries, ocs_max_dma_alloc(sli4->os, SLI_PAGE_SIZE));
3525 sli4->config.max_qentries[q] = qentries;
3531 * @brief Issue a FW_CONFIG mailbox command and store the results.
3533 * @param sli4 SLI context.
3535 * @return Returns 0 on success, or a non-zero value on failure.
3538 sli_query_fw_config(sli4_t *sli4)
3541 * Read the device configuration
3543 * Note: Only ulp0 fields contain values
3545 if (sli_cmd_common_query_fw_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3546 sli4_res_common_query_fw_config_t *fw_config =
3547 (sli4_res_common_query_fw_config_t *)
3548 (((uint8_t *)sli4->bmbx.virt) + offsetof(sli4_cmd_sli_config_t, payload.embed));
3550 if (sli_bmbx_command(sli4)) {
3551 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (QUERY_FW_CONFIG)\n");
3554 if (fw_config->hdr.status) {
3555 ocs_log_err(sli4->os, "COMMON_QUERY_FW_CONFIG bad status %#x\n",
3556 fw_config->hdr.status);
3560 sli4->physical_port = fw_config->physical_port;
3561 sli4->config.dual_ulp_capable = ((fw_config->function_mode & SLI4_FUNCTION_MODE_DUA_MODE) == 0 ? 0 : 1);
3562 sli4->config.is_ulp_fc[0] = ((fw_config->ulp0_mode &
3563 (SLI4_ULP_MODE_FCOE_INI |
3564 SLI4_ULP_MODE_FCOE_TGT)) == 0 ? 0 : 1);
3565 sli4->config.is_ulp_fc[1] = ((fw_config->ulp1_mode &
3566 (SLI4_ULP_MODE_FCOE_INI |
3567 SLI4_ULP_MODE_FCOE_TGT)) == 0 ? 0 : 1);
3569 if (sli4->config.dual_ulp_capable) {
3571 * Lancer will not support this, so we use the values
3572 * from the READ_CONFIG.
3574 if (sli4->config.is_ulp_fc[0] &&
3575 sli4->config.is_ulp_fc[1]) {
3576 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp0_toe_wq_total + fw_config->ulp1_toe_wq_total;
3577 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp0_toe_defrq_total + fw_config->ulp1_toe_defrq_total;
3578 } else if (sli4->config.is_ulp_fc[0]) {
3579 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp0_toe_wq_total;
3580 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp0_toe_defrq_total;
3582 sli4->config.max_qcount[SLI_QTYPE_WQ] = fw_config->ulp1_toe_wq_total;
3583 sli4->config.max_qcount[SLI_QTYPE_RQ] = fw_config->ulp1_toe_defrq_total;
3587 ocs_log_err(sli4->os, "bad QUERY_FW_CONFIG write\n");
3595 sli_get_config(sli4_t *sli4)
3597 ocs_dma_t get_cntl_addl_data;
3600 * Read the device configuration
3602 if (sli_cmd_read_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3603 sli4_res_read_config_t *read_config = sli4->bmbx.virt;
3607 if (sli_bmbx_command(sli4)) {
3608 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_CONFIG)\n");
3611 if (read_config->hdr.status) {
3612 ocs_log_err(sli4->os, "READ_CONFIG bad status %#x\n",
3613 read_config->hdr.status);
3617 sli4->config.has_extents = read_config->ext;
3618 if (FALSE == sli4->config.has_extents) {
3620 uint32_t *base = sli4->config.extent[0].base;
3623 if (NULL == (base = ocs_malloc(sli4->os, SLI_RSRC_MAX * sizeof(uint32_t),
3624 OCS_M_ZERO | OCS_M_NOWAIT))) {
3625 ocs_log_err(sli4->os, "memory allocation failed for sli4_resource_t\n");
3630 for (i = 0; i < SLI_RSRC_MAX; i++) {
3631 sli4->config.extent[i].number = 1;
3632 sli4->config.extent[i].n_alloc = 0;
3633 sli4->config.extent[i].base = &base[i];
3636 sli4->config.extent[SLI_RSRC_FCOE_VFI].base[0] = read_config->vfi_base;
3637 sli4->config.extent[SLI_RSRC_FCOE_VFI].size = read_config->vfi_count;
3639 sli4->config.extent[SLI_RSRC_FCOE_VPI].base[0] = read_config->vpi_base;
3640 sli4->config.extent[SLI_RSRC_FCOE_VPI].size = read_config->vpi_count;
3642 sli4->config.extent[SLI_RSRC_FCOE_RPI].base[0] = read_config->rpi_base;
3643 sli4->config.extent[SLI_RSRC_FCOE_RPI].size = read_config->rpi_count;
3645 sli4->config.extent[SLI_RSRC_FCOE_XRI].base[0] = read_config->xri_base;
3646 sli4->config.extent[SLI_RSRC_FCOE_XRI].size = read_config->xri_count;
3648 sli4->config.extent[SLI_RSRC_FCOE_FCFI].base[0] = 0;
3649 sli4->config.extent[SLI_RSRC_FCOE_FCFI].size = read_config->fcfi_count;
3655 for (i = 0; i < SLI_RSRC_MAX; i++) {
3656 total = sli4->config.extent[i].number * sli4->config.extent[i].size;
3657 sli4->config.extent[i].use_map = ocs_bitmap_alloc(total);
3658 if (NULL == sli4->config.extent[i].use_map) {
3659 ocs_log_err(sli4->os, "bitmap memory allocation failed "
3660 "resource %d\n", i);
3663 sli4->config.extent[i].map_size = total;
3666 sli4->config.topology = read_config->topology;
3667 switch (sli4->config.topology) {
3668 case SLI4_READ_CFG_TOPO_FCOE:
3669 ocs_log_debug(sli4->os, "FCoE\n");
3671 case SLI4_READ_CFG_TOPO_FC:
3672 ocs_log_debug(sli4->os, "FC (unknown)\n");
3674 case SLI4_READ_CFG_TOPO_FC_DA:
3675 ocs_log_debug(sli4->os, "FC (direct attach)\n");
3677 case SLI4_READ_CFG_TOPO_FC_AL:
3678 ocs_log_debug(sli4->os, "FC (arbitrated loop)\n");
3681 ocs_log_test(sli4->os, "bad topology %#x\n", sli4->config.topology);
3684 sli4->config.e_d_tov = read_config->e_d_tov;
3685 sli4->config.r_a_tov = read_config->r_a_tov;
3687 sli4->config.link_module_type = read_config->lmt;
3689 sli4->config.max_qcount[SLI_QTYPE_EQ] = read_config->eq_count;
3690 sli4->config.max_qcount[SLI_QTYPE_CQ] = read_config->cq_count;
3691 sli4->config.max_qcount[SLI_QTYPE_WQ] = read_config->wq_count;
3692 sli4->config.max_qcount[SLI_QTYPE_RQ] = read_config->rq_count;
3695 * READ_CONFIG doesn't give the max number of MQ. Applications
3696 * will typically want 1, but we may need another at some future
3697 * date. Dummy up a "max" MQ count here.
3699 sli4->config.max_qcount[SLI_QTYPE_MQ] = SLI_USER_MQ_COUNT;
3701 ocs_log_err(sli4->os, "bad READ_CONFIG write\n");
3705 if (sli_cmd_common_get_sli4_parameters(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3706 sli4_res_common_get_sli4_parameters_t *parms = (sli4_res_common_get_sli4_parameters_t *)
3707 (((uint8_t *)sli4->bmbx.virt) + offsetof(sli4_cmd_sli_config_t, payload.embed));
3709 if (sli_bmbx_command(sli4)) {
3710 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_SLI4_PARAMETERS)\n");
3712 } else if (parms->hdr.status) {
3713 ocs_log_err(sli4->os, "COMMON_GET_SLI4_PARAMETERS bad status %#x att'l %#x\n",
3714 parms->hdr.status, parms->hdr.additional_status);
3718 sli4->config.auto_reg = parms->areg;
3719 sli4->config.auto_xfer_rdy = parms->agxf;
3720 sli4->config.hdr_template_req = parms->hdrr;
3721 sli4->config.t10_dif_inline_capable = parms->timm;
3722 sli4->config.t10_dif_separate_capable = parms->tsmm;
3724 sli4->config.mq_create_version = parms->mqv;
3725 sli4->config.cq_create_version = parms->cqv;
3726 sli4->config.rq_min_buf_size = parms->min_rq_buffer_size;
3727 sli4->config.rq_max_buf_size = parms->max_rq_buffer_size;
3729 sli4->config.qpage_count[SLI_QTYPE_EQ] = parms->eq_page_cnt;
3730 sli4->config.qpage_count[SLI_QTYPE_CQ] = parms->cq_page_cnt;
3731 sli4->config.qpage_count[SLI_QTYPE_MQ] = parms->mq_page_cnt;
3732 sli4->config.qpage_count[SLI_QTYPE_WQ] = parms->wq_page_cnt;
3733 sli4->config.qpage_count[SLI_QTYPE_RQ] = parms->rq_page_cnt;
3735 /* save count methods and masks for each queue type */
3736 sli4->config.count_mask[SLI_QTYPE_EQ] = parms->eqe_count_mask;
3737 sli4->config.count_method[SLI_QTYPE_EQ] = parms->eqe_count_method;
3738 sli4->config.count_mask[SLI_QTYPE_CQ] = parms->cqe_count_mask;
3739 sli4->config.count_method[SLI_QTYPE_CQ] = parms->cqe_count_method;
3740 sli4->config.count_mask[SLI_QTYPE_MQ] = parms->mqe_count_mask;
3741 sli4->config.count_method[SLI_QTYPE_MQ] = parms->mqe_count_method;
3742 sli4->config.count_mask[SLI_QTYPE_WQ] = parms->wqe_count_mask;
3743 sli4->config.count_method[SLI_QTYPE_WQ] = parms->wqe_count_method;
3744 sli4->config.count_mask[SLI_QTYPE_RQ] = parms->rqe_count_mask;
3745 sli4->config.count_method[SLI_QTYPE_RQ] = parms->rqe_count_method;
3747 /* now calculate max queue entries */
3748 sli_calc_max_qentries(sli4);
3750 sli4->config.max_sgl_pages = parms->sgl_page_cnt; /* max # of pages */
3751 sli4->config.sgl_page_sizes = parms->sgl_page_sizes; /* bit map of available sizes */
3752 /* ignore HLM here. Use value from REQUEST_FEATURES */
3754 sli4->config.sge_supported_length = parms->sge_supported_length;
3755 if (sli4->config.sge_supported_length > OCS_MAX_SGE_SIZE)
3756 sli4->config.sge_supported_length = OCS_MAX_SGE_SIZE;
3758 sli4->config.sgl_pre_registration_required = parms->sglr;
3759 /* default to using pre-registered SGL's */
3760 sli4->config.sgl_pre_registered = TRUE;
3762 sli4->config.perf_hint = parms->phon;
3763 sli4->config.perf_wq_id_association = parms->phwq;
3765 sli4->config.rq_batch = parms->rq_db_window;
3767 /* save the fields for skyhawk SGL chaining */
3768 sli4->config.sgl_chaining_params.chaining_capable =
3770 sli4->config.sgl_chaining_params.frag_num_field_offset =
3771 parms->frag_num_field_offset;
3772 sli4->config.sgl_chaining_params.frag_num_field_mask =
3773 (1ull << parms->frag_num_field_size) - 1;
3774 sli4->config.sgl_chaining_params.sgl_index_field_offset =
3775 parms->sgl_index_field_offset;
3776 sli4->config.sgl_chaining_params.sgl_index_field_mask =
3777 (1ull << parms->sgl_index_field_size) - 1;
3778 sli4->config.sgl_chaining_params.chain_sge_initial_value_lo =
3779 parms->chain_sge_initial_value_lo;
3780 sli4->config.sgl_chaining_params.chain_sge_initial_value_hi =
3781 parms->chain_sge_initial_value_hi;
3783 /* Use the highest available WQE size. */
3784 if (parms->wqe_sizes & SLI4_128BYTE_WQE_SUPPORT) {
3785 sli4->config.wqe_size = SLI4_WQE_EXT_BYTES;
3787 sli4->config.wqe_size = SLI4_WQE_BYTES;
3791 if (sli_query_fw_config(sli4)) {
3792 ocs_log_err(sli4->os, "Error sending QUERY_FW_CONFIG\n");
3796 sli4->config.port_number = 0;
3799 * Issue COMMON_GET_CNTL_ATTRIBUTES to get port_number. Temporarily
3800 * uses VPD DMA buffer as the response won't fit in the embedded
3803 if (sli_cmd_common_get_cntl_attributes(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &sli4->vpd.data)) {
3804 sli4_res_common_get_cntl_attributes_t *attr = sli4->vpd.data.virt;
3806 if (sli_bmbx_command(sli4)) {
3807 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_CNTL_ATTRIBUTES)\n");
3809 } else if (attr->hdr.status) {
3810 ocs_log_err(sli4->os, "COMMON_GET_CNTL_ATTRIBUTES bad status %#x att'l %#x\n",
3811 attr->hdr.status, attr->hdr.additional_status);
3815 sli4->config.port_number = attr->port_number;
3817 ocs_memcpy(sli4->config.bios_version_string, attr->bios_version_string,
3818 sizeof(sli4->config.bios_version_string));
3820 ocs_log_err(sli4->os, "bad COMMON_GET_CNTL_ATTRIBUTES write\n");
3824 if (ocs_dma_alloc(sli4->os, &get_cntl_addl_data, sizeof(sli4_res_common_get_cntl_addl_attributes_t),
3825 OCS_MIN_DMA_ALIGNMENT)) {
3826 ocs_log_err(sli4->os, "Failed to allocate memory for GET_CNTL_ADDL_ATTR data\n");
3828 if (sli_cmd_common_get_cntl_addl_attributes(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
3829 &get_cntl_addl_data)) {
3830 sli4_res_common_get_cntl_addl_attributes_t *attr = get_cntl_addl_data.virt;
3832 if (sli_bmbx_command(sli4)) {
3833 ocs_log_crit(sli4->os,
3834 "bootstrap mailbox write fail (COMMON_GET_CNTL_ADDL_ATTRIBUTES)\n");
3835 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3838 if (attr->hdr.status) {
3839 ocs_log_err(sli4->os, "COMMON_GET_CNTL_ADDL_ATTRIBUTES bad status %#x\n",
3841 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3845 ocs_memcpy(sli4->config.ipl_name, attr->ipl_file_name, sizeof(sli4->config.ipl_name));
3847 ocs_log_debug(sli4->os, "IPL:%s \n", (char*)sli4->config.ipl_name);
3849 ocs_log_err(sli4->os, "bad COMMON_GET_CNTL_ADDL_ATTRIBUTES write\n");
3850 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3854 ocs_dma_free(sli4->os, &get_cntl_addl_data);
3857 if (sli_cmd_common_get_port_name(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3858 sli4_res_common_get_port_name_t *port_name = (sli4_res_common_get_port_name_t *)(((uint8_t *)sli4->bmbx.virt) +
3859 offsetof(sli4_cmd_sli_config_t, payload.embed));
3861 if (sli_bmbx_command(sli4)) {
3862 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (COMMON_GET_PORT_NAME)\n");
3866 sli4->config.port_name[0] = port_name->port_name[sli4->config.port_number];
3868 sli4->config.port_name[1] = '\0';
3870 if (sli_cmd_read_rev(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &sli4->vpd.data)) {
3871 sli4_cmd_read_rev_t *read_rev = sli4->bmbx.virt;
3873 if (sli_bmbx_command(sli4)) {
3874 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_REV)\n");
3877 if (read_rev->hdr.status) {
3878 ocs_log_err(sli4->os, "READ_REV bad status %#x\n",
3879 read_rev->hdr.status);
3883 sli4->config.fw_rev[0] = read_rev->first_fw_id;
3884 ocs_memcpy(sli4->config.fw_name[0],read_rev->first_fw_name, sizeof(sli4->config.fw_name[0]));
3886 sli4->config.fw_rev[1] = read_rev->second_fw_id;
3887 ocs_memcpy(sli4->config.fw_name[1],read_rev->second_fw_name, sizeof(sli4->config.fw_name[1]));
3889 sli4->config.hw_rev[0] = read_rev->first_hw_revision;
3890 sli4->config.hw_rev[1] = read_rev->second_hw_revision;
3891 sli4->config.hw_rev[2] = read_rev->third_hw_revision;
3893 ocs_log_debug(sli4->os, "FW1:%s (%08x) / FW2:%s (%08x)\n",
3894 read_rev->first_fw_name, read_rev->first_fw_id,
3895 read_rev->second_fw_name, read_rev->second_fw_id);
3897 ocs_log_debug(sli4->os, "HW1: %08x / HW2: %08x\n", read_rev->first_hw_revision,
3898 read_rev->second_hw_revision);
3900 /* Check that all VPD data was returned */
3901 if (read_rev->returned_vpd_length != read_rev->actual_vpd_length) {
3902 ocs_log_test(sli4->os, "VPD length: available=%d returned=%d actual=%d\n",
3903 read_rev->available_length,
3904 read_rev->returned_vpd_length,
3905 read_rev->actual_vpd_length);
3907 sli4->vpd.length = read_rev->returned_vpd_length;
3909 ocs_log_err(sli4->os, "bad READ_REV write\n");
3913 if (sli_cmd_read_nvparms(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE)) {
3914 sli4_cmd_read_nvparms_t *read_nvparms = sli4->bmbx.virt;
3916 if (sli_bmbx_command(sli4)) {
3917 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (READ_NVPARMS)\n");
3920 if (read_nvparms->hdr.status) {
3921 ocs_log_err(sli4->os, "READ_NVPARMS bad status %#x\n",
3922 read_nvparms->hdr.status);
3926 ocs_memcpy(sli4->config.wwpn, read_nvparms->wwpn, sizeof(sli4->config.wwpn));
3927 ocs_memcpy(sli4->config.wwnn, read_nvparms->wwnn, sizeof(sli4->config.wwnn));
3929 ocs_log_debug(sli4->os, "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
3930 sli4->config.wwpn[0],
3931 sli4->config.wwpn[1],
3932 sli4->config.wwpn[2],
3933 sli4->config.wwpn[3],
3934 sli4->config.wwpn[4],
3935 sli4->config.wwpn[5],
3936 sli4->config.wwpn[6],
3937 sli4->config.wwpn[7]);
3938 ocs_log_debug(sli4->os, "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
3939 sli4->config.wwnn[0],
3940 sli4->config.wwnn[1],
3941 sli4->config.wwnn[2],
3942 sli4->config.wwnn[3],
3943 sli4->config.wwnn[4],
3944 sli4->config.wwnn[5],
3945 sli4->config.wwnn[6],
3946 sli4->config.wwnn[7]);
3948 ocs_log_err(sli4->os, "bad READ_NVPARMS write\n");
3955 /****************************************************************************
3961 * @brief Set up the SLI context.
3963 * @param sli4 SLI context.
3964 * @param os Device abstraction.
3965 * @param port_type Protocol type of port (for example, FC and NIC).
3967 * @return Returns 0 on success, or a non-zero value on failure.
3970 sli_setup(sli4_t *sli4, ocs_os_handle_t os, sli4_port_type_e port_type)
3972 uint32_t sli_intf = UINT32_MAX;
3973 uint32_t pci_class_rev = 0;
3974 uint32_t rev_id = 0;
3975 uint32_t family = 0;
3977 sli4_asic_entry_t *asic;
3979 ocs_memset(sli4, 0, sizeof(sli4_t));
3982 sli4->port_type = port_type;
3985 * Read the SLI_INTF register to discover the register layout
3986 * and other capability information
3988 sli_intf = ocs_config_read32(os, SLI4_INTF_REG);
3990 if (sli_intf_valid_check(sli_intf)) {
3991 ocs_log_err(os, "SLI_INTF is not valid\n");
3995 /* driver only support SLI-4 */
3996 sli4->sli_rev = sli_intf_sli_revision(sli_intf);
3997 if (4 != sli4->sli_rev) {
3998 ocs_log_err(os, "Unsupported SLI revision (intf=%#x)\n",
4003 sli4->sli_family = sli_intf_sli_family(sli_intf);
4005 sli4->if_type = sli_intf_if_type(sli_intf);
4007 if (SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type) {
4008 ocs_log_debug(os, "status=%#x error1=%#x error2=%#x\n",
4009 sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS),
4010 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR1),
4011 sli_reg_read(sli4, SLI4_REG_SLIPORT_ERROR2));
4015 * set the ASIC type and revision
4017 pci_class_rev = ocs_config_read32(os, SLI4_PCI_CLASS_REVISION);
4018 rev_id = sli_pci_rev_id(pci_class_rev);
4019 family = sli4->sli_family;
4020 if (family == SLI4_FAMILY_CHECK_ASIC_TYPE) {
4021 uint32_t asic_id = ocs_config_read32(os, SLI4_ASIC_ID_REG);
4022 family = sli_asic_gen(asic_id);
4025 for (i = 0, asic = sli4_asic_table; i < ARRAY_SIZE(sli4_asic_table); i++, asic++) {
4026 if ((rev_id == asic->rev_id) && (family == asic->family)) {
4027 sli4->asic_type = asic->type;
4028 sli4->asic_rev = asic->rev;
4032 /* Fail if no matching asic type/rev was found */
4033 if( (sli4->asic_type == 0) || (sli4->asic_rev == 0)) {
4034 ocs_log_err(os, "no matching asic family/rev found: %02x/%02x\n", family, rev_id);
4039 * The bootstrap mailbox is equivalent to a MQ with a single 256 byte
4040 * entry, a CQ with a single 16 byte entry, and no event queue.
4041 * Alignment must be 16 bytes as the low order address bits in the
4042 * address register are also control / status.
4044 if (ocs_dma_alloc(sli4->os, &sli4->bmbx, SLI4_BMBX_SIZE +
4045 sizeof(sli4_mcqe_t), 16)) {
4046 ocs_log_err(os, "bootstrap mailbox allocation failed\n");
4050 if (sli4->bmbx.phys & SLI4_BMBX_MASK_LO) {
4051 ocs_log_err(os, "bad alignment for bootstrap mailbox\n");
4055 ocs_log_debug(os, "bmbx v=%p p=0x%x %08x s=%zd\n", sli4->bmbx.virt,
4056 ocs_addr32_hi(sli4->bmbx.phys),
4057 ocs_addr32_lo(sli4->bmbx.phys),
4060 /* TODO 4096 is arbitrary. What should this value actually be? */
4061 if (ocs_dma_alloc(sli4->os, &sli4->vpd.data, 4096/*TODO*/, 4096)) {
4062 /* Note that failure isn't fatal in this specific case */
4063 sli4->vpd.data.size = 0;
4064 ocs_log_test(os, "VPD buffer allocation failed\n");
4067 if (sli_fw_init(sli4)) {
4068 ocs_log_err(sli4->os, "FW initialization failed\n");
4073 * Set one of fcpi(initiator), fcpt(target), fcpc(combined) to true
4074 * in addition to any other desired features
4076 sli4->config.features.flag.iaab = TRUE;
4077 sli4->config.features.flag.npiv = TRUE;
4078 sli4->config.features.flag.dif = TRUE;
4079 sli4->config.features.flag.vf = TRUE;
4080 sli4->config.features.flag.fcpc = TRUE;
4081 sli4->config.features.flag.iaar = TRUE;
4082 sli4->config.features.flag.hlm = TRUE;
4083 sli4->config.features.flag.perfh = TRUE;
4084 sli4->config.features.flag.rxseq = TRUE;
4085 sli4->config.features.flag.rxri = TRUE;
4086 sli4->config.features.flag.mrqp = TRUE;
4088 /* use performance hints if available */
4089 if (sli4->config.perf_hint) {
4090 sli4->config.features.flag.perfh = TRUE;
4093 if (sli_request_features(sli4, &sli4->config.features, TRUE)) {
4097 if (sli_get_config(sli4)) {
4105 sli_init(sli4_t *sli4)
4108 if (sli4->config.has_extents) {
4109 /* TODO COMMON_ALLOC_RESOURCE_EXTENTS */;
4110 ocs_log_test(sli4->os, "XXX need to implement extent allocation\n");
4114 sli4->config.features.flag.hlm = sli4->config.high_login_mode;
4115 sli4->config.features.flag.rxseq = FALSE;
4116 sli4->config.features.flag.rxri = FALSE;
4118 if (sli_request_features(sli4, &sli4->config.features, FALSE)) {
4126 sli_reset(sli4_t *sli4)
4130 if (sli_fw_init(sli4)) {
4131 ocs_log_crit(sli4->os, "FW initialization failed\n");
4135 if (sli4->config.extent[0].base) {
4136 ocs_free(sli4->os, sli4->config.extent[0].base, SLI_RSRC_MAX * sizeof(uint32_t));
4137 sli4->config.extent[0].base = NULL;
4140 for (i = 0; i < SLI_RSRC_MAX; i++) {
4141 if (sli4->config.extent[i].use_map) {
4142 ocs_bitmap_free(sli4->config.extent[i].use_map);
4143 sli4->config.extent[i].use_map = NULL;
4145 sli4->config.extent[i].base = NULL;
4148 if (sli_get_config(sli4)) {
4157 * @brief Issue a Firmware Reset.
4160 * Issues a Firmware Reset to the chip. This reset affects the entire chip,
4161 * so all PCI function on the same PCI bus and device are affected.
4162 * @n @n This type of reset can be used to activate newly downloaded firmware.
4163 * @n @n The driver should be considered to be in an unknown state after this
4164 * reset and should be reloaded.
4166 * @param sli4 SLI context.
4168 * @return Returns 0 on success, or -1 otherwise.
4172 sli_fw_reset(sli4_t *sli4)
4178 * Firmware must be ready before issuing the reset.
4180 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
4182 ocs_log_crit(sli4->os, "FW status is NOT ready\n");
4185 switch(sli4->if_type) {
4186 case SLI4_IF_TYPE_BE3_SKH_PF:
4187 /* BE3 / Skyhawk use PCICFG_SOFT_RESET_CSR */
4188 val = ocs_config_read32(sli4->os, SLI4_PCI_SOFT_RESET_CSR);
4189 val |= SLI4_PCI_SOFT_RESET_MASK;
4190 ocs_config_write32(sli4->os, SLI4_PCI_SOFT_RESET_CSR, val);
4192 case SLI4_IF_TYPE_LANCER_FC_ETH:
4193 /* Lancer uses PHYDEV_CONTROL */
4195 val = SLI4_PHYDEV_CONTROL_FRST;
4196 sli_reg_write(sli4, SLI4_REG_PHYSDEV_CONTROL, val);
4199 ocs_log_test(sli4->os, "Unexpected iftype %d\n", sli4->if_type);
4204 /* wait for the FW to become ready after the reset */
4205 ready = sli_wait_for_fw_ready(sli4, SLI4_FW_READY_TIMEOUT_MSEC);
4207 ocs_log_crit(sli4->os, "Failed to become ready after firmware reset\n");
4215 * @brief Tear down a SLI context.
4217 * @param sli4 SLI context.
4219 * @return Returns 0 on success, or non-zero otherwise.
4222 sli_teardown(sli4_t *sli4)
4226 if (sli4->config.extent[0].base) {
4227 ocs_free(sli4->os, sli4->config.extent[0].base, SLI_RSRC_MAX * sizeof(uint32_t));
4228 sli4->config.extent[0].base = NULL;
4231 for (i = 0; i < SLI_RSRC_MAX; i++) {
4232 if (sli4->config.has_extents) {
4233 /* TODO COMMON_DEALLOC_RESOURCE_EXTENTS */;
4236 sli4->config.extent[i].base = NULL;
4238 ocs_bitmap_free(sli4->config.extent[i].use_map);
4239 sli4->config.extent[i].use_map = NULL;
4242 if (sli_fw_term(sli4)) {
4243 ocs_log_err(sli4->os, "FW deinitialization failed\n");
4246 ocs_dma_free(sli4->os, &sli4->vpd.data);
4247 ocs_dma_free(sli4->os, &sli4->bmbx);
4254 * @brief Register a callback for the given event.
4256 * @param sli4 SLI context.
4257 * @param which Event of interest.
4258 * @param func Function to call when the event occurs.
4259 * @param arg Argument passed to the callback function.
4261 * @return Returns 0 on success, or non-zero otherwise.
4264 sli_callback(sli4_t *sli4, sli4_callback_e which, void *func, void *arg)
4267 if (!sli4 || !func || (which >= SLI4_CB_MAX)) {
4268 ocs_log_err(NULL, "bad parameter sli4=%p which=%#x func=%p\n",
4276 sli4->link_arg = arg;
4280 sli4->fip_arg = arg;
4283 ocs_log_test(sli4->os, "unknown callback %#x\n", which);
4292 * @brief Initialize a queue object.
4295 * This initializes the sli4_queue_t object members, including the underlying
4298 * @param sli4 SLI context.
4299 * @param q Pointer to queue object.
4300 * @param qtype Type of queue to create.
4301 * @param size Size of each entry.
4302 * @param n_entries Number of entries to allocate.
4303 * @param align Starting memory address alignment.
4305 * @note Checks if using the existing DMA memory (if any) is possible. If not,
4306 * it frees the existing memory and re-allocates.
4308 * @return Returns 0 on success, or non-zero otherwise.
4311 __sli_queue_init(sli4_t *sli4, sli4_queue_t *q, uint32_t qtype,
4312 size_t size, uint32_t n_entries, uint32_t align)
4315 if ((q->dma.virt == NULL) || (size != q->size) || (n_entries != q->length)) {
4317 ocs_dma_free(sli4->os, &q->dma);
4320 ocs_memset(q, 0, sizeof(sli4_queue_t));
4322 if (ocs_dma_alloc(sli4->os, &q->dma, size * n_entries, align)) {
4323 ocs_log_err(sli4->os, "%s allocation failed\n", SLI_QNAME[qtype]);
4327 ocs_memset(q->dma.virt, 0, size * n_entries);
4329 ocs_lock_init(sli4->os, &q->lock, "%s lock[%d:%p]",
4330 SLI_QNAME[qtype], ocs_instance(sli4->os), &q->lock);
4334 q->length = n_entries;
4336 /* Limit to hwf the queue size per interrupt */
4337 q->proc_limit = n_entries / 2;
4341 q->posted_limit = q->length / 2;
4344 if ((sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) ||
4345 (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_VF)) {
4346 /* For Skyhawk, ring the doorbell more often */
4347 q->posted_limit = 8;
4349 q->posted_limit = 64;
4360 * @brief Issue the command to create a queue.
4362 * @param sli4 SLI context.
4363 * @param q Pointer to queue object.
4365 * @return Returns 0 on success, or non-zero otherwise.
4368 __sli_create_queue(sli4_t *sli4, sli4_queue_t *q)
4370 sli4_res_common_create_queue_t *res_q = NULL;
4372 if (sli_bmbx_command(sli4)){
4373 ocs_log_crit(sli4->os, "bootstrap mailbox write fail %s\n",
4374 SLI_QNAME[q->type]);
4375 ocs_dma_free(sli4->os, &q->dma);
4378 if (sli_res_sli_config(sli4->bmbx.virt)) {
4379 ocs_log_err(sli4->os, "bad status create %s\n", SLI_QNAME[q->type]);
4380 ocs_dma_free(sli4->os, &q->dma);
4383 res_q = (void *)((uint8_t *)sli4->bmbx.virt +
4384 offsetof(sli4_cmd_sli_config_t, payload));
4386 if (res_q->hdr.status) {
4387 ocs_log_err(sli4->os, "bad create %s status=%#x addl=%#x\n",
4389 res_q->hdr.status, res_q->hdr.additional_status);
4390 ocs_dma_free(sli4->os, &q->dma);
4393 q->id = res_q->q_id;
4394 q->doorbell_offset = res_q->db_offset;
4395 q->doorbell_rset = res_q->db_rs;
4399 /* No doorbell information in response for EQs */
4400 q->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4401 q->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4404 /* No doorbell information in response for CQs */
4405 q->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4406 q->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4409 /* No doorbell information in response for MQs */
4410 q->doorbell_offset = regmap[SLI4_REG_MQ_DOORBELL][sli4->if_type].off;
4411 q->doorbell_rset = regmap[SLI4_REG_MQ_DOORBELL][sli4->if_type].rset;
4414 /* set the doorbell for non-skyhawks */
4415 if (!sli4->config.dual_ulp_capable) {
4416 q->doorbell_offset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].off;
4417 q->doorbell_rset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].rset;
4421 /* set the doorbell for non-skyhawks */
4422 if (!sli4->config.dual_ulp_capable) {
4423 q->doorbell_offset = regmap[SLI4_REG_IO_WQ_DOORBELL][sli4->if_type].off;
4424 q->doorbell_rset = regmap[SLI4_REG_IO_WQ_DOORBELL][sli4->if_type].rset;
4437 * @brief Get queue entry size.
4439 * Get queue entry size given queue type.
4441 * @param sli4 SLI context
4442 * @param qtype Type for which the entry size is returned.
4444 * @return Returns > 0 on success (queue entry size), or a negative value on failure.
4447 sli_get_queue_entry_size(sli4_t *sli4, uint32_t qtype)
4452 ocs_log_err(NULL, "bad parameter sli4=%p\n", sli4);
4458 size = sizeof(uint32_t);
4467 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4468 size = sli4->config.wqe_size;
4471 ocs_log_test(sli4->os, "unsupported queue entry size\n");
4476 size = SLI4_FCOE_RQE_SIZE;
4479 ocs_log_test(sli4->os, "unknown queue type %d\n", qtype);
4487 * @brief Modify the delay timer for all the EQs
4489 * @param sli4 SLI context.
4490 * @param eq Array of EQs.
4491 * @param num_eq Count of EQs.
4492 * @param shift Phase shift for staggering interrupts.
4493 * @param delay_mult Delay multiplier for limiting interrupt frequency.
4495 * @return Returns 0 on success, or -1 otherwise.
4498 sli_eq_modify_delay(sli4_t *sli4, sli4_queue_t *eq, uint32_t num_eq, uint32_t shift, uint32_t delay_mult)
4501 sli_cmd_common_modify_eq_delay(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, eq, num_eq, shift, delay_mult);
4503 if (sli_bmbx_command(sli4)) {
4504 ocs_log_crit(sli4->os, "bootstrap mailbox write fail (MODIFY EQ DELAY)\n");
4507 if (sli_res_sli_config(sli4->bmbx.virt)) {
4508 ocs_log_err(sli4->os, "bad status MODIFY EQ DELAY\n");
4517 * @brief Allocate a queue.
4520 * Allocates DMA memory and configures the requested queue type.
4522 * @param sli4 SLI context.
4523 * @param qtype Type of queue to create.
4524 * @param q Pointer to the queue object.
4525 * @param n_entries Number of entries to allocate.
4526 * @param assoc Associated queue (that is, the EQ for a CQ, the CQ for a MQ, and so on).
4527 * @param ulp The ULP to bind, which is only used for WQ and RQs
4529 * @return Returns 0 on success, or -1 otherwise.
4532 sli_queue_alloc(sli4_t *sli4, uint32_t qtype, sli4_queue_t *q, uint32_t n_entries,
4533 sli4_queue_t *assoc, uint16_t ulp)
4537 sli4_create_q_fn_t create = NULL;
4540 ocs_log_err(NULL, "bad parameter sli4=%p q=%p\n", sli4, q);
4544 /* get queue size */
4545 size = sli_get_queue_entry_size(sli4, qtype);
4548 align = SLI_PAGE_SIZE;
4552 create = sli_cmd_common_create_eq;
4555 create = sli_cmd_common_create_cq;
4558 /* Validate the number of entries */
4559 switch (n_entries) {
4566 ocs_log_test(sli4->os, "illegal n_entries value %d for MQ\n", n_entries);
4569 assoc->u.flag.is_mq = TRUE;
4570 create = sli_cmd_common_create_mq_ext;
4573 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4574 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) {
4575 create = sli_cmd_fcoe_wq_create;
4577 create = sli_cmd_fcoe_wq_create_v1;
4581 ocs_log_test(sli4->os, "unsupported WQ create\n");
4586 ocs_log_test(sli4->os, "unknown queue type %d\n", qtype);
4591 if (__sli_queue_init(sli4, q, qtype, size, n_entries, align)) {
4592 ocs_log_err(sli4->os, "%s allocation failed\n", SLI_QNAME[qtype]);
4596 if (create(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &q->dma, assoc ? assoc->id : 0, ulp)) {
4598 if (__sli_create_queue(sli4, q)) {
4599 ocs_log_err(sli4->os, "create %s failed\n", SLI_QNAME[qtype]);
4604 ocs_log_err(sli4->os, "cannot create %s\n", SLI_QNAME[qtype]);
4614 * @brief Allocate a c queue set.
4616 * @param sli4 SLI context.
4617 * @param num_cqs to create
4618 * @param qs Pointers to the queue objects.
4619 * @param n_entries Number of entries to allocate per CQ.
4620 * @param eqs Associated event queues
4622 * @return Returns 0 on success, or -1 otherwise.
4625 sli_cq_alloc_set(sli4_t *sli4, sli4_queue_t *qs[], uint32_t num_cqs,
4626 uint32_t n_entries, sli4_queue_t *eqs[])
4628 uint32_t i, offset = 0, page_bytes = 0, payload_size, cmd_size = 0;
4629 uint32_t p = 0, page_size = 0, n_cqe = 0, num_pages_cq;
4632 sli4_req_common_create_cq_set_v0_t *req = NULL;
4633 sli4_res_common_create_queue_set_t *res = NULL;
4636 ocs_log_err(NULL, "bad parameter sli4=%p\n", sli4);
4640 /* Align the queue DMA memory */
4641 for (i = 0; i < num_cqs; i++) {
4642 if (__sli_queue_init(sli4, qs[i], SLI_QTYPE_CQ, SLI4_CQE_BYTES,
4643 n_entries, SLI_PAGE_SIZE)) {
4644 ocs_log_err(sli4->os, "Queue init failed.\n");
4649 n_cqe = qs[0]->dma.size / SLI4_CQE_BYTES;
4664 page_bytes = page_size * SLI_PAGE_SIZE;
4665 num_pages_cq = sli_page_count(qs[0]->dma.size, page_bytes);
4666 cmd_size = sizeof(sli4_req_common_create_cq_set_v0_t) + (8 * num_pages_cq * num_cqs);
4667 payload_size = max((size_t)cmd_size, sizeof(sli4_res_common_create_queue_set_t));
4669 if (ocs_dma_alloc(sli4->os, &dma, payload_size, SLI_PAGE_SIZE)) {
4670 ocs_log_err(sli4->os, "DMA allocation failed\n");
4673 ocs_memset(dma.virt, 0, payload_size);
4675 if (sli_cmd_sli_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
4676 payload_size, &dma) == -1) {
4680 /* Fill the request structure */
4682 req = (sli4_req_common_create_cq_set_v0_t *)((uint8_t *)dma.virt);
4683 req->hdr.opcode = SLI4_OPC_COMMON_CREATE_CQ_SET;
4684 req->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
4685 req->hdr.version = 0;
4686 req->hdr.request_length = cmd_size - sizeof(sli4_req_hdr_t);
4687 req->page_size = page_size;
4689 req->num_pages = num_pages_cq;
4690 switch (req->num_pages) {
4692 req->cqecnt = SLI4_CQ_CNT_256;
4695 req->cqecnt = SLI4_CQ_CNT_512;
4698 req->cqecnt = SLI4_CQ_CNT_1024;
4701 req->cqecnt = SLI4_CQ_CNT_LARGE;
4702 req->cqe_count = n_cqe;
4705 ocs_log_test(sli4->os, "num_pages %d not valid\n", req->num_pages);
4712 req->num_cq_req = num_cqs;
4714 /* Fill page addresses of all the CQs. */
4715 for (i = 0; i < num_cqs; i++) {
4716 req->eq_id[i] = eqs[i]->id;
4717 for (p = 0, addr = qs[i]->dma.phys; p < req->num_pages; p++, addr += page_bytes) {
4718 req->page_physical_address[offset].low = ocs_addr32_lo(addr);
4719 req->page_physical_address[offset].high = ocs_addr32_hi(addr);
4724 if (sli_bmbx_command(sli4)) {
4725 ocs_log_crit(sli4->os, "bootstrap mailbox write fail CQSet\n");
4729 res = (void *)((uint8_t *)dma.virt);
4730 if (res->hdr.status) {
4731 ocs_log_err(sli4->os, "bad create CQSet status=%#x addl=%#x\n",
4732 res->hdr.status, res->hdr.additional_status);
4735 /* Check if we got all requested CQs. */
4736 if (res->num_q_allocated != num_cqs) {
4737 ocs_log_crit(sli4->os, "Requested count CQs doesnt match.\n");
4741 /* Fill the resp cq ids. */
4742 for (i = 0; i < num_cqs; i++) {
4743 qs[i]->id = res->q_id + i;
4744 qs[i]->doorbell_offset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].off;
4745 qs[i]->doorbell_rset = regmap[SLI4_REG_EQCQ_DOORBELL][sli4->if_type].rset;
4749 ocs_dma_free(sli4->os, &dma);
4754 for (i = 0; i < num_cqs; i++) {
4755 if (qs[i]->dma.size) {
4756 ocs_dma_free(sli4->os, &qs[i]->dma);
4761 ocs_dma_free(sli4->os, &dma);
4771 * @brief Free a queue.
4774 * Frees DMA memory and de-registers the requested queue.
4776 * @param sli4 SLI context.
4777 * @param q Pointer to the queue object.
4778 * @param destroy_queues Non-zero if the mailbox commands should be sent to destroy the queues.
4779 * @param free_memory Non-zero if the DMA memory associated with the queue should be freed.
4781 * @return Returns 0 on success, or -1 otherwise.
4784 sli_queue_free(sli4_t *sli4, sli4_queue_t *q, uint32_t destroy_queues, uint32_t free_memory)
4786 sli4_destroy_q_fn_t destroy = NULL;
4790 ocs_log_err(NULL, "bad parameter sli4=%p q=%p\n", sli4, q);
4794 if (destroy_queues) {
4797 destroy = sli_cmd_common_destroy_eq;
4800 destroy = sli_cmd_common_destroy_cq;
4803 destroy = sli_cmd_common_destroy_mq;
4806 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4807 destroy = sli_cmd_fcoe_wq_destroy;
4810 ocs_log_test(sli4->os, "unsupported WQ destroy\n");
4815 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
4816 destroy = sli_cmd_fcoe_rq_destroy;
4819 ocs_log_test(sli4->os, "unsupported RQ destroy\n");
4824 ocs_log_test(sli4->os, "bad queue type %d\n",
4830 * Destroying queues makes BE3 sad (version 0 interface type). Rely
4831 * on COMMON_FUNCTION_RESET to free host allocated queue resources
4832 * inside the SLI Port.
4834 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
4838 /* Destroy the queue if the operation is defined */
4839 if (destroy && destroy(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, q->id)) {
4840 sli4_res_hdr_t *res = NULL;
4842 if (sli_bmbx_command(sli4)){
4843 ocs_log_crit(sli4->os, "bootstrap mailbox write fail destroy %s\n",
4844 SLI_QNAME[q->type]);
4845 } else if (sli_res_sli_config(sli4->bmbx.virt)) {
4846 ocs_log_err(sli4->os, "bad status destroy %s\n", SLI_QNAME[q->type]);
4848 res = (void *)((uint8_t *)sli4->bmbx.virt +
4849 offsetof(sli4_cmd_sli_config_t, payload));
4852 ocs_log_err(sli4->os, "bad destroy %s status=%#x addl=%#x\n",
4854 res->status, res->additional_status);
4863 ocs_lock_free(&q->lock);
4865 if (ocs_dma_free(sli4->os, &q->dma)) {
4866 ocs_log_err(sli4->os, "%s queue ID %d free failed\n",
4867 SLI_QNAME[q->type], q->id);
4876 sli_queue_reset(sli4_t *sli4, sli4_queue_t *q)
4884 if (SLI_QTYPE_MQ == q->type) {
4888 if (q->dma.virt != NULL) {
4889 ocs_memset(q->dma.virt, 0, (q->size * q->length));
4892 ocs_unlock(&q->lock);
4899 * @brief Check if the given queue is empty.
4902 * If the valid bit of the current entry is unset, the queue is empty.
4904 * @param sli4 SLI context.
4905 * @param q Pointer to the queue object.
4907 * @return Returns TRUE if empty, or FALSE otherwise.
4910 sli_queue_is_empty(sli4_t *sli4, sli4_queue_t *q)
4913 uint8_t *qe = q->dma.virt;
4917 ocs_dma_sync(&q->dma, OCS_DMASYNC_POSTREAD);
4919 qe += q->index * q->size;
4921 rc = !sli_queue_entry_is_valid(q, qe, FALSE);
4923 ocs_unlock(&q->lock);
4932 * @param sli4 SLI context.
4933 * @param q Pointer to queue object.
4934 * @param arm If TRUE, arm the EQ.
4936 * @return Returns 0 on success, or non-zero otherwise.
4939 sli_queue_eq_arm(sli4_t *sli4, sli4_queue_t *q, uint8_t arm)
4944 val = sli_eq_doorbell(q->n_posted, q->id, arm);
4945 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4947 ocs_unlock(&q->lock);
4954 * @brief Arm a queue.
4956 * @param sli4 SLI context.
4957 * @param q Pointer to queue object.
4958 * @param arm If TRUE, arm the queue.
4960 * @return Returns 0 on success, or non-zero otherwise.
4963 sli_queue_arm(sli4_t *sli4, sli4_queue_t *q, uint8_t arm)
4971 val = sli_eq_doorbell(q->n_posted, q->id, arm);
4972 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4976 val = sli_cq_doorbell(q->n_posted, q->id, arm);
4977 ocs_reg_write32(sli4->os, q->doorbell_rset, q->doorbell_offset, val);
4981 ocs_log_test(sli4->os, "should only be used for EQ/CQ, not %s\n",
4982 SLI_QNAME[q->type]);
4985 ocs_unlock(&q->lock);
4992 * @brief Write an entry to the queue object.
4994 * Note: Assumes the q->lock will be locked and released by the caller.
4996 * @param sli4 SLI context.
4997 * @param q Pointer to the queue object.
4998 * @param entry Pointer to the entry contents.
5000 * @return Returns queue index on success, or negative error value otherwise.
5003 _sli_queue_write(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5006 uint8_t *qe = q->dma.virt;
5010 qe += q->index * q->size;
5013 if ((SLI_QTYPE_WQ == q->type) && sli4->config.perf_wq_id_association) {
5014 sli_set_wq_id_association(entry, q->id);
5016 #if defined(OCS_INCLUDE_DEBUG)
5018 case SLI_QTYPE_WQ: {
5019 ocs_dump32(OCS_DEBUG_ENABLE_WQ_DUMP, sli4->os, "wqe", entry, q->size);
5024 /* Note: we don't really need to dump the whole
5025 * 256 bytes, just do 64 */
5026 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, "mqe outbound", entry, 64);
5033 ocs_memcpy(qe, entry, q->size);
5037 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5039 rc = sli_queue_doorbell(sli4, q);
5041 q->index = (q->index + q->n_posted) & (q->length - 1);
5047 } else if (rc > 0) {
5048 /* failure, but we need to return a negative value on failure */
5057 * @brief Write an entry to the queue object.
5059 * Note: Assumes the q->lock will be locked and released by the caller.
5061 * @param sli4 SLI context.
5062 * @param q Pointer to the queue object.
5063 * @param entry Pointer to the entry contents.
5065 * @return Returns queue index on success, or negative error value otherwise.
5068 sli_queue_write(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5073 rc = _sli_queue_write(sli4, q, entry);
5074 ocs_unlock(&q->lock);
5080 * @brief Check if the current queue entry is valid.
5082 * @param q Pointer to the queue object.
5083 * @param qe Pointer to the queue entry.
5084 * @param clear Boolean to clear valid bit.
5086 * @return Returns TRUE if the entry is valid, or FALSE otherwise.
5089 sli_queue_entry_is_valid(sli4_queue_t *q, uint8_t *qe, uint8_t clear)
5091 uint8_t valid = FALSE;
5095 valid = ((sli4_eqe_t *)qe)->vld;
5096 if (valid && clear) {
5097 ((sli4_eqe_t *)qe)->vld = 0;
5102 * For both MCQE and WCQE/RCQE, the valid bit
5103 * is bit 31 of dword 3 (0 based)
5105 valid = (qe[15] & 0x80) != 0;
5106 if (valid & clear) {
5111 valid = q->index != q->u.r_idx;
5118 ocs_log_test(NULL, "doesn't handle type=%#x\n", q->type);
5122 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5130 * @brief Read an entry from the queue object.
5132 * @param sli4 SLI context.
5133 * @param q Pointer to the queue object.
5134 * @param entry Destination pointer for the queue entry contents.
5136 * @return Returns 0 on success, or non-zero otherwise.
5139 sli_queue_read(sli4_t *sli4, sli4_queue_t *q, uint8_t *entry)
5142 uint8_t *qe = q->dma.virt;
5143 uint32_t *qindex = NULL;
5145 if (SLI_QTYPE_MQ == q->type) {
5146 qindex = &q->u.r_idx;
5153 ocs_dma_sync(&q->dma, OCS_DMASYNC_POSTREAD);
5155 qe += *qindex * q->size;
5157 if (!sli_queue_entry_is_valid(q, qe, TRUE)) {
5158 ocs_unlock(&q->lock);
5163 ocs_memcpy(entry, qe, q->size);
5164 #if defined(OCS_INCLUDE_DEBUG)
5167 ocs_dump32(OCS_DEBUG_ENABLE_CQ_DUMP, sli4->os, "cq", entry, q->size);
5170 ocs_dump32(OCS_DEBUG_ENABLE_MQ_DUMP, sli4->os, "mq Compl", entry, 64);
5173 ocs_dump32(OCS_DEBUG_ENABLE_EQ_DUMP, sli4->os, "eq Compl", entry, q->size);
5185 *qindex = (*qindex + 1) & (q->length - 1);
5186 if (SLI_QTYPE_MQ != q->type) {
5191 /* reads don't update the index */
5195 ocs_unlock(&q->lock);
5201 sli_queue_index(sli4_t *sli4, sli4_queue_t *q)
5212 sli_queue_poke(sli4_t *sli4, sli4_queue_t *q, uint32_t index, uint8_t *entry)
5217 rc = _sli_queue_poke(sli4, q, index, entry);
5218 ocs_unlock(&q->lock);
5224 _sli_queue_poke(sli4_t *sli4, sli4_queue_t *q, uint32_t index, uint8_t *entry)
5227 uint8_t *qe = q->dma.virt;
5229 if (index >= q->length) {
5233 qe += index * q->size;
5236 ocs_memcpy(qe, entry, q->size);
5239 ocs_dma_sync(&q->dma, OCS_DMASYNC_PREWRITE);
5246 * @brief Allocate SLI Port resources.
5249 * Allocate port-related resources, such as VFI, RPI, XRI, and so on.
5250 * Resources are modeled using extents, regardless of whether the underlying
5251 * device implements resource extents. If the device does not implement
5252 * extents, the SLI layer models this as a single (albeit large) extent.
5254 * @param sli4 SLI context.
5255 * @param rtype Resource type (for example, RPI or XRI)
5256 * @param rid Allocated resource ID.
5257 * @param index Index into the bitmap.
5259 * @return Returns 0 on success, or a non-zero value on failure.
5262 sli_resource_alloc(sli4_t *sli4, sli4_resource_e rtype, uint32_t *rid, uint32_t *index)
5266 uint32_t extent_idx;
5271 *index = UINT32_MAX;
5274 case SLI_RSRC_FCOE_VFI:
5275 case SLI_RSRC_FCOE_VPI:
5276 case SLI_RSRC_FCOE_RPI:
5277 case SLI_RSRC_FCOE_XRI:
5278 status = ocs_bitmap_find(sli4->config.extent[rtype].use_map,
5279 sli4->config.extent[rtype].map_size);
5281 ocs_log_err(sli4->os, "out of resource %d (alloc=%d)\n",
5282 rtype, sli4->config.extent[rtype].n_alloc);
5289 size = sli4->config.extent[rtype].size;
5291 extent_idx = *index / size;
5292 item_idx = *index % size;
5294 *rid = sli4->config.extent[rtype].base[extent_idx] + item_idx;
5296 sli4->config.extent[rtype].n_alloc++;
5307 * @brief Free the SLI Port resources.
5310 * Free port-related resources, such as VFI, RPI, XRI, and so. See discussion of
5311 * "extent" usage in sli_resource_alloc.
5313 * @param sli4 SLI context.
5314 * @param rtype Resource type (for example, RPI or XRI).
5315 * @param rid Allocated resource ID.
5317 * @return Returns 0 on success, or a non-zero value on failure.
5320 sli_resource_free(sli4_t *sli4, sli4_resource_e rtype, uint32_t rid)
5324 uint32_t size, *base;
5327 case SLI_RSRC_FCOE_VFI:
5328 case SLI_RSRC_FCOE_VPI:
5329 case SLI_RSRC_FCOE_RPI:
5330 case SLI_RSRC_FCOE_XRI:
5332 * Figure out which extent contains the resource ID. I.e. find
5333 * the extent such that
5334 * extent->base <= resource ID < extent->base + extent->size
5336 base = sli4->config.extent[rtype].base;
5337 size = sli4->config.extent[rtype].size;
5340 * In the case of FW reset, this may be cleared but the force_free path will
5341 * still attempt to free the resource. Prevent a NULL pointer access.
5344 for (x = 0; x < sli4->config.extent[rtype].number; x++) {
5345 if ((rid >= base[x]) && (rid < (base[x] + size))) {
5347 ocs_bitmap_clear(sli4->config.extent[rtype].use_map,
5363 sli_resource_reset(sli4_t *sli4, sli4_resource_e rtype)
5369 case SLI_RSRC_FCOE_VFI:
5370 case SLI_RSRC_FCOE_VPI:
5371 case SLI_RSRC_FCOE_RPI:
5372 case SLI_RSRC_FCOE_XRI:
5373 for (i = 0; i < sli4->config.extent[rtype].map_size; i++) {
5374 ocs_bitmap_clear(sli4->config.extent[rtype].use_map, i);
5387 * @brief Parse an EQ entry to retrieve the CQ_ID for this event.
5389 * @param sli4 SLI context.
5390 * @param buf Pointer to the EQ entry.
5391 * @param cq_id CQ_ID for this entry (only valid on success).
5396 * - > 0 if firmware detects EQ overflow.
5399 sli_eq_parse(sli4_t *sli4, uint8_t *buf, uint16_t *cq_id)
5401 sli4_eqe_t *eqe = (void *)buf;
5404 if (!sli4 || !buf || !cq_id) {
5405 ocs_log_err(NULL, "bad parameters sli4=%p buf=%p cq_id=%p\n",
5410 switch (eqe->major_code) {
5411 case SLI4_MAJOR_CODE_STANDARD:
5412 *cq_id = eqe->resource_id;
5414 case SLI4_MAJOR_CODE_SENTINEL:
5415 ocs_log_debug(sli4->os, "sentinel EQE\n");
5419 ocs_log_test(sli4->os, "Unsupported EQE: major %x minor %x\n",
5420 eqe->major_code, eqe->minor_code);
5429 * @brief Parse a CQ entry to retrieve the event type and the associated queue.
5431 * @param sli4 SLI context.
5432 * @param cq CQ to process.
5433 * @param cqe Pointer to the CQ entry.
5434 * @param etype CQ event type.
5435 * @param q_id Queue ID associated with this completion message
5436 * (that is, MQ_ID, RQ_ID, and so on).
5439 * - 0 if call completed correctly and CQE status is SUCCESS.
5440 * - -1 if call failed (no CQE status).
5441 * - Other value if call completed correctly and return value is a CQE status value.
5444 sli_cq_parse(sli4_t *sli4, sli4_queue_t *cq, uint8_t *cqe, sli4_qentry_e *etype,
5449 if (!sli4 || !cq || !cqe || !etype) {
5450 ocs_log_err(NULL, "bad parameters sli4=%p cq=%p cqe=%p etype=%p q_id=%p\n",
5451 sli4, cq, cqe, etype, q_id);
5455 if (cq->u.flag.is_mq) {
5456 sli4_mcqe_t *mcqe = (void *)cqe;
5459 *etype = SLI_QENTRY_ASYNC;
5461 *etype = SLI_QENTRY_MQ;
5462 rc = sli_cqe_mq(mcqe);
5465 } else if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5466 rc = sli_fc_cqe_parse(sli4, cq, cqe, etype, q_id);
5468 ocs_log_test(sli4->os, "implement CQE parsing type = %#x\n",
5478 * @brief Cause chip to enter an unrecoverable error state.
5481 * Cause chip to enter an unrecoverable error state. This is
5482 * used when detecting unexpected FW behavior so FW can be
5483 * hwted from the driver as soon as error is detected.
5485 * @param sli4 SLI context.
5486 * @param dump Generate dump as part of reset.
5488 * @return Returns 0 if call completed correctly, or -1 if call failed (unsupported chip).
5490 int32_t sli_raise_ue(sli4_t *sli4, uint8_t dump)
5493 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5494 switch(sli_get_asic_type(sli4)) {
5495 case SLI4_ASIC_TYPE_BE3: {
5496 sli_reg_write(sli4, SLI4_REG_SW_UE_CSR1, 0xffffffff);
5497 sli_reg_write(sli4, SLI4_REG_SW_UE_CSR2, 0);
5500 case SLI4_ASIC_TYPE_SKYHAWK: {
5502 value = ocs_config_read32(sli4->os, SLI4_SW_UE_REG);
5503 ocs_config_write32(sli4->os, SLI4_SW_UE_REG, (value | (1U << 24)));
5507 ocs_log_test(sli4->os, "invalid asic type %d\n", sli_get_asic_type(sli4));
5510 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli_get_if_type(sli4)) {
5512 sli_reg_write(sli4, SLI4_REG_SLIPORT_CONTROL, SLI4_SLIPORT_CONTROL_FDD | SLI4_SLIPORT_CONTROL_IP);
5514 uint32_t value = SLI4_PHYDEV_CONTROL_FRST;
5516 value |= SLI4_PHYDEV_CONTROL_DD;
5518 sli_reg_write(sli4, SLI4_REG_PHYSDEV_CONTROL, value);
5521 ocs_log_test(sli4->os, "invalid iftype=%d\n", sli_get_if_type(sli4));
5529 * @brief Read the SLIPORT_STATUS register to to check if a dump is present.
5531 * @param sli4 SLI context.
5533 * @return Returns 1 if the chip is ready, or 0 if the chip is not ready, 2 if fdp is present.
5535 int32_t sli_dump_is_ready(sli4_t *sli4)
5542 uint32_t uerr_mask_lo;
5543 uint32_t uerr_mask_hi;
5545 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5546 /* for iftype=0, dump ready when UE is encountered */
5547 uerr_lo = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_LO);
5548 uerr_hi = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_HI);
5549 uerr_mask_lo = sli_reg_read(sli4, SLI4_REG_UERR_MASK_LO);
5550 uerr_mask_hi = sli_reg_read(sli4, SLI4_REG_UERR_MASK_HI);
5551 if ((uerr_lo & ~uerr_mask_lo) || (uerr_hi & ~uerr_mask_hi)) {
5555 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli_get_if_type(sli4)) {
5557 * Ensure that the port is ready AND the mailbox is
5558 * ready before signaling that the dump is ready to go.
5560 port_val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5561 bmbx_val = sli_reg_read(sli4, SLI4_REG_BMBX);
5563 if ((bmbx_val & SLI4_BMBX_RDY) &&
5564 SLI4_PORT_STATUS_READY(port_val)) {
5565 if(SLI4_PORT_STATUS_DUMP_PRESENT(port_val)) {
5567 }else if( SLI4_PORT_STATUS_FDP_PRESENT(port_val)) {
5572 ocs_log_test(sli4->os, "invalid iftype=%d\n", sli_get_if_type(sli4));
5580 * @brief Read the SLIPORT_STATUS register to check if a dump is present.
5582 * @param sli4 SLI context.
5585 * - 0 if call completed correctly and no dump is present.
5586 * - 1 if call completed and dump is present.
5587 * - -1 if call failed (unsupported chip).
5589 int32_t sli_dump_is_present(sli4_t *sli4)
5594 if (SLI4_IF_TYPE_LANCER_FC_ETH != sli_get_if_type(sli4)) {
5595 ocs_log_test(sli4->os, "Function only supported for I/F type 2");
5599 /* If the chip is not ready, then there cannot be a dump */
5600 ready = sli_wait_for_fw_ready(sli4, SLI4_INIT_PORT_DELAY_US);
5605 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5606 if (UINT32_MAX == val) {
5607 ocs_log_err(sli4->os, "error reading SLIPORT_STATUS\n");
5610 return ((val & SLI4_PORT_STATUS_DIP) ? 1 : 0);
5616 * @brief Read the SLIPORT_STATUS register to check if the reset required is set.
5618 * @param sli4 SLI context.
5621 * - 0 if call completed correctly and reset is not required.
5622 * - 1 if call completed and reset is required.
5623 * - -1 if call failed.
5625 int32_t sli_reset_required(sli4_t *sli4)
5629 if (SLI4_IF_TYPE_BE3_SKH_PF == sli_get_if_type(sli4)) {
5630 ocs_log_test(sli4->os, "reset required N/A for iftype 0\n");
5634 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5635 if (UINT32_MAX == val) {
5636 ocs_log_err(sli4->os, "error reading SLIPORT_STATUS\n");
5639 return ((val & SLI4_PORT_STATUS_RN) ? 1 : 0);
5645 * @brief Read the SLIPORT_SEMAPHORE and SLIPORT_STATUS registers to check if
5646 * the port status indicates that a FW error has occurred.
5648 * @param sli4 SLI context.
5651 * - 0 if call completed correctly and no FW error occurred.
5652 * - > 0 which indicates that a FW error has occurred.
5653 * - -1 if call failed.
5655 int32_t sli_fw_error_status(sli4_t *sli4)
5657 uint32_t sliport_semaphore;
5660 sliport_semaphore = sli_reg_read(sli4, SLI4_REG_SLIPORT_SEMAPHORE);
5661 if (UINT32_MAX == sliport_semaphore) {
5662 ocs_log_err(sli4->os, "error reading SLIPORT_SEMAPHORE register\n");
5665 rc = (SLI4_PORT_SEMAPHORE_IN_ERR(sliport_semaphore) ? 1 : 0);
5668 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type ||
5669 (SLI4_IF_TYPE_BE3_SKH_VF == sli4->if_type)) {
5670 uint32_t uerr_mask_lo, uerr_mask_hi;
5671 uint32_t uerr_status_lo, uerr_status_hi;
5673 uerr_mask_lo = sli_reg_read(sli4, SLI4_REG_UERR_MASK_LO);
5674 uerr_mask_hi = sli_reg_read(sli4, SLI4_REG_UERR_MASK_HI);
5675 uerr_status_lo = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_LO);
5676 uerr_status_hi = sli_reg_read(sli4, SLI4_REG_UERR_STATUS_HI);
5677 if ((uerr_mask_lo & uerr_status_lo) != 0 ||
5678 (uerr_mask_hi & uerr_status_hi) != 0) {
5681 } else if ((SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type)) {
5682 uint32_t sliport_status;
5684 sliport_status = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5685 rc = (SLI4_PORT_STATUS_ERROR(sliport_status) ? 1 : 0);
5693 * @brief Determine if the chip FW is in a ready state
5695 * @param sli4 SLI context.
5698 * - 0 if call completed correctly and FW is not ready.
5699 * - 1 if call completed correctly and FW is ready.
5700 * - -1 if call failed.
5703 sli_fw_ready(sli4_t *sli4)
5709 * Is firmware ready for operation? Check needed depends on IF_TYPE
5711 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type ||
5712 SLI4_IF_TYPE_BE3_SKH_VF == sli4->if_type) {
5713 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_SEMAPHORE);
5714 rc = ((SLI4_PORT_SEMAPHORE_STATUS_POST_READY ==
5715 SLI4_PORT_SEMAPHORE_PORT(val)) &&
5716 (!SLI4_PORT_SEMAPHORE_IN_ERR(val)) ? 1 : 0);
5717 } else if (SLI4_IF_TYPE_LANCER_FC_ETH == sli4->if_type) {
5718 val = sli_reg_read(sli4, SLI4_REG_SLIPORT_STATUS);
5719 rc = (SLI4_PORT_STATUS_READY(val) ? 1 : 0);
5726 * @brief Determine if the link can be configured
5728 * @param sli4 SLI context.
5731 * - 0 if link is not configurable.
5732 * - 1 if link is configurable.
5734 int32_t sli_link_is_configurable(sli4_t *sli)
5738 * Link config works on: Skyhawk and Lancer
5739 * Link config does not work on: LancerG6
5742 switch (sli_get_asic_type(sli)) {
5743 case SLI4_ASIC_TYPE_SKYHAWK:
5744 case SLI4_ASIC_TYPE_LANCER:
5745 case SLI4_ASIC_TYPE_CORSAIR:
5748 case SLI4_ASIC_TYPE_LANCERG6:
5749 case SLI4_ASIC_TYPE_BE3:
5759 /* vim: set noexpandtab textwidth=120: */
5763 * @brief Write an FCOE_WQ_CREATE command.
5765 * @param sli4 SLI context.
5766 * @param buf Destination buffer for the command.
5767 * @param size Buffer size, in bytes.
5768 * @param qmem DMA memory for the queue.
5769 * @param cq_id Associated CQ_ID.
5770 * @param ulp The ULP to bind
5772 * @note This creates a Version 0 message.
5774 * @return Returns the number of bytes written.
5777 sli_cmd_fcoe_wq_create(sli4_t *sli4, void *buf, size_t size,
5778 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp)
5780 sli4_req_fcoe_wq_create_t *wq = NULL;
5781 uint32_t sli_config_off = 0;
5785 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5786 uint32_t payload_size;
5788 /* Payload length must accommodate both request and response */
5789 payload_size = max(sizeof(sli4_req_fcoe_wq_create_t),
5790 sizeof(sli4_res_common_create_queue_t));
5792 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5795 wq = (sli4_req_fcoe_wq_create_t *)((uint8_t *)buf + sli_config_off);
5797 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_CREATE;
5798 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5799 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_create_t) -
5800 sizeof(sli4_req_hdr_t);
5801 /* valid values for number of pages: 1-4 (sec 4.5.1) */
5802 wq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
5803 if (!wq->num_pages || (wq->num_pages > SLI4_FCOE_WQ_CREATE_V0_MAX_PAGES)) {
5809 if (sli4->config.dual_ulp_capable) {
5815 for (p = 0, addr = qmem->phys;
5817 p++, addr += SLI_PAGE_SIZE) {
5818 wq->page_physical_address[p].low = ocs_addr32_lo(addr);
5819 wq->page_physical_address[p].high = ocs_addr32_hi(addr);
5822 return(sli_config_off + sizeof(sli4_req_fcoe_wq_create_t));
5827 * @brief Write an FCOE_WQ_CREATE_V1 command.
5829 * @param sli4 SLI context.
5830 * @param buf Destination buffer for the command.
5831 * @param size Buffer size, in bytes.
5832 * @param qmem DMA memory for the queue.
5833 * @param cq_id Associated CQ_ID.
5834 * @param ignored This parameter carries the ULP for WQ (ignored for V1)
5837 * @return Returns the number of bytes written.
5840 sli_cmd_fcoe_wq_create_v1(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *qmem,
5841 uint16_t cq_id, uint16_t ignored)
5843 sli4_req_fcoe_wq_create_v1_t *wq = NULL;
5844 uint32_t sli_config_off = 0;
5847 uint32_t page_size = 0;
5848 uint32_t page_bytes = 0;
5851 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5852 uint32_t payload_size;
5854 /* Payload length must accommodate both request and response */
5855 payload_size = max(sizeof(sli4_req_fcoe_wq_create_v1_t),
5856 sizeof(sli4_res_common_create_queue_t));
5858 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5861 wq = (sli4_req_fcoe_wq_create_v1_t *)((uint8_t *)buf + sli_config_off);
5863 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_CREATE;
5864 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5865 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_create_v1_t) -
5866 sizeof(sli4_req_hdr_t);
5867 wq->hdr.version = 1;
5869 n_wqe = qmem->size / sli4->config.wqe_size;
5871 /* This heuristic to determine the page size is simplistic
5872 * but could be made more sophisticated
5874 switch (qmem->size) {
5896 page_bytes = page_size * SLI_PAGE_SIZE;
5898 /* valid values for number of pages: 1-8 */
5899 wq->num_pages = sli_page_count(qmem->size, page_bytes);
5900 if (!wq->num_pages || (wq->num_pages > SLI4_FCOE_WQ_CREATE_V1_MAX_PAGES)) {
5906 wq->page_size = page_size;
5908 if (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) {
5909 wq->wqe_size = SLI4_WQE_EXT_SIZE;
5911 wq->wqe_size = SLI4_WQE_SIZE;
5914 wq->wqe_count = n_wqe;
5916 for (p = 0, addr = qmem->phys;
5918 p++, addr += page_bytes) {
5919 wq->page_physical_address[p].low = ocs_addr32_lo(addr);
5920 wq->page_physical_address[p].high = ocs_addr32_hi(addr);
5923 return(sli_config_off + sizeof(sli4_req_fcoe_wq_create_v1_t));
5928 * @brief Write an FCOE_WQ_DESTROY command.
5930 * @param sli4 SLI context.
5931 * @param buf Destination buffer for the command.
5932 * @param size Buffer size, in bytes.
5933 * @param wq_id WQ_ID.
5935 * @return Returns the number of bytes written.
5938 sli_cmd_fcoe_wq_destroy(sli4_t *sli4, void *buf, size_t size, uint16_t wq_id)
5940 sli4_req_fcoe_wq_destroy_t *wq = NULL;
5941 uint32_t sli_config_off = 0;
5943 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5944 uint32_t payload_size;
5946 /* Payload length must accommodate both request and response */
5947 payload_size = max(sizeof(sli4_req_fcoe_wq_destroy_t),
5948 sizeof(sli4_res_hdr_t));
5950 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
5953 wq = (sli4_req_fcoe_wq_destroy_t *)((uint8_t *)buf + sli_config_off);
5955 wq->hdr.opcode = SLI4_OPC_FCOE_WQ_DESTROY;
5956 wq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
5957 wq->hdr.request_length = sizeof(sli4_req_fcoe_wq_destroy_t) -
5958 sizeof(sli4_req_hdr_t);
5962 return(sli_config_off + sizeof(sli4_req_fcoe_wq_destroy_t));
5967 * @brief Write an FCOE_POST_SGL_PAGES command.
5969 * @param sli4 SLI context.
5970 * @param buf Destination buffer for the command.
5971 * @param size Buffer size, in bytes.
5972 * @param xri starting XRI
5973 * @param xri_count XRI
5974 * @param page0 First SGL memory page.
5975 * @param page1 Second SGL memory page (optional).
5976 * @param dma DMA buffer for non-embedded mailbox command (options)
5978 * if non-embedded mbx command is used, dma buffer must be at least (32 + xri_count*16) in length
5980 * @return Returns the number of bytes written.
5983 sli_cmd_fcoe_post_sgl_pages(sli4_t *sli4, void *buf, size_t size,
5984 uint16_t xri, uint32_t xri_count, ocs_dma_t *page0[], ocs_dma_t *page1[], ocs_dma_t *dma)
5986 sli4_req_fcoe_post_sgl_pages_t *post = NULL;
5987 uint32_t sli_config_off = 0;
5990 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
5991 uint32_t payload_size;
5993 /* Payload length must accommodate both request and response */
5994 payload_size = max(sizeof(sli4_req_fcoe_post_sgl_pages_t),
5995 sizeof(sli4_res_hdr_t));
5997 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6002 ocs_memset(post, 0, dma->size);
6004 post = (sli4_req_fcoe_post_sgl_pages_t *)((uint8_t *)buf + sli_config_off);
6007 post->hdr.opcode = SLI4_OPC_FCOE_POST_SGL_PAGES;
6008 post->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6009 /* payload size calculation
6010 * 4 = xri_start + xri_count
6011 * xri_count = # of XRI's registered
6012 * sizeof(uint64_t) = physical address size
6013 * 2 = # of physical addresses per page set
6015 post->hdr.request_length = 4 + (xri_count * (sizeof(uint64_t) * 2));
6017 post->xri_start = xri;
6018 post->xri_count = xri_count;
6020 for (i = 0; i < xri_count; i++) {
6021 post->page_set[i].page0_low = ocs_addr32_lo(page0[i]->phys);
6022 post->page_set[i].page0_high = ocs_addr32_hi(page0[i]->phys);
6026 for (i = 0; i < xri_count; i++) {
6027 post->page_set[i].page1_low = ocs_addr32_lo(page1[i]->phys);
6028 post->page_set[i].page1_high = ocs_addr32_hi(page1[i]->phys);
6032 return dma ? sli_config_off : (sli_config_off + sizeof(sli4_req_fcoe_post_sgl_pages_t));
6037 * @brief Write an FCOE_RQ_CREATE command.
6039 * @param sli4 SLI context.
6040 * @param buf Destination buffer for the command.
6041 * @param size Buffer size, in bytes.
6042 * @param qmem DMA memory for the queue.
6043 * @param cq_id Associated CQ_ID.
6044 * @param ulp This parameter carries the ULP for the RQ
6045 * @param buffer_size Buffer size pointed to by each RQE.
6047 * @note This creates a Version 0 message.
6049 * @return Returns the number of bytes written.
6052 sli_cmd_fcoe_rq_create(sli4_t *sli4, void *buf, size_t size,
6053 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp, uint16_t buffer_size)
6055 sli4_req_fcoe_rq_create_t *rq = NULL;
6056 uint32_t sli_config_off = 0;
6060 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6061 uint32_t payload_size;
6063 /* Payload length must accommodate both request and response */
6064 payload_size = max(sizeof(sli4_req_fcoe_rq_create_t),
6065 sizeof(sli4_res_common_create_queue_t));
6067 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6070 rq = (sli4_req_fcoe_rq_create_t *)((uint8_t *)buf + sli_config_off);
6072 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
6073 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6074 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_t) -
6075 sizeof(sli4_req_hdr_t);
6076 /* valid values for number of pages: 1-8 (sec 4.5.6) */
6077 rq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
6078 if (!rq->num_pages || (rq->num_pages > SLI4_FCOE_RQ_CREATE_V0_MAX_PAGES)) {
6079 ocs_log_test(sli4->os, "num_pages %d not valid\n", rq->num_pages);
6084 * RQE count is the log base 2 of the total number of entries
6086 rq->rqe_count = ocs_lg2(qmem->size / SLI4_FCOE_RQE_SIZE);
6088 if ((buffer_size < SLI4_FCOE_RQ_CREATE_V0_MIN_BUF_SIZE) ||
6089 (buffer_size > SLI4_FCOE_RQ_CREATE_V0_MAX_BUF_SIZE)) {
6090 ocs_log_err(sli4->os, "buffer_size %d out of range (%d-%d)\n",
6092 SLI4_FCOE_RQ_CREATE_V0_MIN_BUF_SIZE,
6093 SLI4_FCOE_RQ_CREATE_V0_MAX_BUF_SIZE);
6096 rq->buffer_size = buffer_size;
6100 if (sli4->config.dual_ulp_capable) {
6106 for (p = 0, addr = qmem->phys;
6108 p++, addr += SLI_PAGE_SIZE) {
6109 rq->page_physical_address[p].low = ocs_addr32_lo(addr);
6110 rq->page_physical_address[p].high = ocs_addr32_hi(addr);
6113 return(sli_config_off + sizeof(sli4_req_fcoe_rq_create_t));
6118 * @brief Write an FCOE_RQ_CREATE_V1 command.
6120 * @param sli4 SLI context.
6121 * @param buf Destination buffer for the command.
6122 * @param size Buffer size, in bytes.
6123 * @param qmem DMA memory for the queue.
6124 * @param cq_id Associated CQ_ID.
6125 * @param ulp This parameter carries the ULP for RQ (ignored for V1)
6126 * @param buffer_size Buffer size pointed to by each RQE.
6128 * @note This creates a Version 0 message
6130 * @return Returns the number of bytes written.
6133 sli_cmd_fcoe_rq_create_v1(sli4_t *sli4, void *buf, size_t size,
6134 ocs_dma_t *qmem, uint16_t cq_id, uint16_t ulp,
6135 uint16_t buffer_size)
6137 sli4_req_fcoe_rq_create_v1_t *rq = NULL;
6138 uint32_t sli_config_off = 0;
6142 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6143 uint32_t payload_size;
6145 /* Payload length must accommodate both request and response */
6146 payload_size = max(sizeof(sli4_req_fcoe_rq_create_v1_t),
6147 sizeof(sli4_res_common_create_queue_t));
6149 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6152 rq = (sli4_req_fcoe_rq_create_v1_t *)((uint8_t *)buf + sli_config_off);
6154 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
6155 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6156 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_v1_t) -
6157 sizeof(sli4_req_hdr_t);
6158 rq->hdr.version = 1;
6160 /* Disable "no buffer warnings" to avoid Lancer bug */
6163 /* valid values for number of pages: 1-8 (sec 4.5.6) */
6164 rq->num_pages = sli_page_count(qmem->size, SLI_PAGE_SIZE);
6165 if (!rq->num_pages || (rq->num_pages > SLI4_FCOE_RQ_CREATE_V1_MAX_PAGES)) {
6166 ocs_log_test(sli4->os, "num_pages %d not valid, max %d\n",
6167 rq->num_pages, SLI4_FCOE_RQ_CREATE_V1_MAX_PAGES);
6172 * RQE count is the total number of entries (note not lg2(# entries))
6174 rq->rqe_count = qmem->size / SLI4_FCOE_RQE_SIZE;
6176 rq->rqe_size = SLI4_FCOE_RQE_SIZE_8;
6178 rq->page_size = SLI4_FCOE_RQ_PAGE_SIZE_4096;
6180 if ((buffer_size < sli4->config.rq_min_buf_size) ||
6181 (buffer_size > sli4->config.rq_max_buf_size)) {
6182 ocs_log_err(sli4->os, "buffer_size %d out of range (%d-%d)\n",
6184 sli4->config.rq_min_buf_size,
6185 sli4->config.rq_max_buf_size);
6188 rq->buffer_size = buffer_size;
6192 for (p = 0, addr = qmem->phys;
6194 p++, addr += SLI_PAGE_SIZE) {
6195 rq->page_physical_address[p].low = ocs_addr32_lo(addr);
6196 rq->page_physical_address[p].high = ocs_addr32_hi(addr);
6199 return(sli_config_off + sizeof(sli4_req_fcoe_rq_create_v1_t));
6204 * @brief Write an FCOE_RQ_DESTROY command.
6206 * @param sli4 SLI context.
6207 * @param buf Destination buffer for the command.
6208 * @param size Buffer size, in bytes.
6209 * @param rq_id RQ_ID.
6211 * @return Returns the number of bytes written.
6214 sli_cmd_fcoe_rq_destroy(sli4_t *sli4, void *buf, size_t size, uint16_t rq_id)
6216 sli4_req_fcoe_rq_destroy_t *rq = NULL;
6217 uint32_t sli_config_off = 0;
6219 if (SLI4_PORT_TYPE_FC == sli4->port_type) {
6220 uint32_t payload_size;
6222 /* Payload length must accommodate both request and response */
6223 payload_size = max(sizeof(sli4_req_fcoe_rq_destroy_t),
6224 sizeof(sli4_res_hdr_t));
6226 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size,
6229 rq = (sli4_req_fcoe_rq_destroy_t *)((uint8_t *)buf + sli_config_off);
6231 rq->hdr.opcode = SLI4_OPC_FCOE_RQ_DESTROY;
6232 rq->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6233 rq->hdr.request_length = sizeof(sli4_req_fcoe_rq_destroy_t) -
6234 sizeof(sli4_req_hdr_t);
6238 return(sli_config_off + sizeof(sli4_req_fcoe_rq_destroy_t));
6243 * @brief Write an FCOE_READ_FCF_TABLE command.
6246 * The response of this command exceeds the size of an embedded
6247 * command and requires an external buffer with DMA capability to hold the results.
6248 * The caller should allocate the ocs_dma_t structure / memory.
6250 * @param sli4 SLI context.
6251 * @param buf Destination buffer for the command.
6252 * @param size Buffer size, in bytes.
6253 * @param dma Pointer to DMA memory structure. This is allocated by the caller.
6254 * @param index FCF table index to retrieve.
6256 * @return Returns the number of bytes written.
6259 sli_cmd_fcoe_read_fcf_table(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *dma, uint16_t index)
6261 sli4_req_fcoe_read_fcf_table_t *read_fcf = NULL;
6263 if (SLI4_PORT_TYPE_FC != sli4->port_type) {
6264 ocs_log_test(sli4->os, "FCOE_READ_FCF_TABLE only supported on FC\n");
6268 read_fcf = dma->virt;
6270 ocs_memset(read_fcf, 0, sizeof(sli4_req_fcoe_read_fcf_table_t));
6272 read_fcf->hdr.opcode = SLI4_OPC_FCOE_READ_FCF_TABLE;
6273 read_fcf->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6274 read_fcf->hdr.request_length = dma->size -
6275 sizeof(sli4_req_fcoe_read_fcf_table_t);
6276 read_fcf->fcf_index = index;
6278 return sli_cmd_sli_config(sli4, buf, size, 0, dma);
6283 * @brief Write an FCOE_POST_HDR_TEMPLATES command.
6285 * @param sli4 SLI context.
6286 * @param buf Destination buffer for the command.
6287 * @param size Buffer size, in bytes.
6288 * @param dma Pointer to DMA memory structure. This is allocated by the caller.
6289 * @param rpi Starting RPI index for the header templates.
6290 * @param payload_dma Pointer to DMA memory used to hold larger descriptor counts.
6292 * @return Returns the number of bytes written.
6295 sli_cmd_fcoe_post_hdr_templates(sli4_t *sli4, void *buf, size_t size,
6296 ocs_dma_t *dma, uint16_t rpi, ocs_dma_t *payload_dma)
6298 sli4_req_fcoe_post_hdr_templates_t *template = NULL;
6299 uint32_t sli_config_off = 0;
6302 uint32_t page_count;
6303 uint32_t payload_size;
6305 page_count = sli_page_count(dma->size, SLI_PAGE_SIZE);
6307 payload_size = sizeof(sli4_req_fcoe_post_hdr_templates_t) +
6308 page_count * sizeof(sli4_physical_page_descriptor_t);
6310 if (page_count > 16) {
6311 /* We can't fit more than 16 descriptors into an embedded mailbox
6312 command, it has to be non-embedded */
6313 if (ocs_dma_alloc(sli4->os, payload_dma, payload_size, 4)) {
6314 ocs_log_err(sli4->os, "mailbox payload memory allocation fail\n");
6317 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size, payload_dma);
6318 template = (sli4_req_fcoe_post_hdr_templates_t *)payload_dma->virt;
6320 sli_config_off = sli_cmd_sli_config(sli4, buf, size, payload_size, NULL);
6321 template = (sli4_req_fcoe_post_hdr_templates_t *)((uint8_t *)buf + sli_config_off);
6324 if (UINT16_MAX == rpi) {
6325 rpi = sli4->config.extent[SLI_RSRC_FCOE_RPI].base[0];
6328 template->hdr.opcode = SLI4_OPC_FCOE_POST_HDR_TEMPLATES;
6329 template->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6330 template->hdr.request_length = sizeof(sli4_req_fcoe_post_hdr_templates_t) -
6331 sizeof(sli4_req_hdr_t);
6333 template->rpi_offset = rpi;
6334 template->page_count = page_count;
6336 for (i = 0; i < template->page_count; i++) {
6337 template->page_descriptor[i].low = ocs_addr32_lo(phys);
6338 template->page_descriptor[i].high = ocs_addr32_hi(phys);
6340 phys += SLI_PAGE_SIZE;
6343 return(sli_config_off + payload_size);
6347 sli_cmd_fcoe_rediscover_fcf(sli4_t *sli4, void *buf, size_t size, uint16_t index)
6349 sli4_req_fcoe_rediscover_fcf_t *redisc = NULL;
6350 uint32_t sli_config_off = 0;
6352 sli_config_off = sli_cmd_sli_config(sli4, buf, size,
6353 sizeof(sli4_req_fcoe_rediscover_fcf_t),
6356 redisc = (sli4_req_fcoe_rediscover_fcf_t *)((uint8_t *)buf + sli_config_off);
6358 redisc->hdr.opcode = SLI4_OPC_FCOE_REDISCOVER_FCF;
6359 redisc->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
6360 redisc->hdr.request_length = sizeof(sli4_req_fcoe_rediscover_fcf_t) -
6361 sizeof(sli4_req_hdr_t);
6363 if (index == UINT16_MAX) {
6364 redisc->fcf_count = 0;
6366 redisc->fcf_count = 1;
6367 redisc->fcf_index[0] = index;
6370 return(sli_config_off + sizeof(sli4_req_fcoe_rediscover_fcf_t));
6375 * @brief Write an ABORT_WQE work queue entry.
6377 * @param sli4 SLI context.
6378 * @param buf Destination buffer for the WQE.
6379 * @param size Buffer size, in bytes.
6380 * @param type Abort type, such as XRI, abort tag, and request tag.
6381 * @param send_abts Boolean to cause the hardware to automatically generate an ABTS.
6382 * @param ids ID of IOs to abort.
6383 * @param mask Mask applied to the ID values to abort.
6384 * @param tag Tag value associated with this abort.
6385 * @param cq_id The id of the completion queue where the WQE response is sent.
6386 * @param dnrx When set to 1, this field indicates that the SLI Port must not return the associated XRI to the SLI
6387 * Port's optimized write XRI pool.
6389 * @return Returns 0 on success, or a non-zero value on failure.
6392 sli_abort_wqe(sli4_t *sli4, void *buf, size_t size, sli4_abort_type_e type, uint32_t send_abts,
6393 uint32_t ids, uint32_t mask, uint16_t tag, uint16_t cq_id)
6395 sli4_abort_wqe_t *abort = buf;
6397 ocs_memset(buf, 0, size);
6401 abort->criteria = SLI4_ABORT_CRITERIA_XRI_TAG;
6403 ocs_log_warn(sli4->os, "warning non-zero mask %#x when aborting XRI %#x\n", mask, ids);
6407 case SLI_ABORT_ABORT_ID:
6408 abort->criteria = SLI4_ABORT_CRITERIA_ABORT_TAG;
6410 case SLI_ABORT_REQUEST_ID:
6411 abort->criteria = SLI4_ABORT_CRITERIA_REQUEST_TAG;
6414 ocs_log_test(sli4->os, "unsupported type %#x\n", type);
6418 abort->ia = send_abts ? 0 : 1;
6420 /* Suppress ABTS retries */
6423 abort->t_mask = mask;
6425 abort->command = SLI4_WQE_ABORT;
6426 abort->request_tag = tag;
6428 abort->cq_id = cq_id;
6429 abort->cmd_type = SLI4_CMD_ABORT_WQE;
6436 * @brief Write an ELS_REQUEST64_WQE work queue entry.
6438 * @param sli4 SLI context.
6439 * @param buf Destination buffer for the WQE.
6440 * @param size Buffer size, in bytes.
6441 * @param sgl DMA memory for the ELS request.
6442 * @param req_type ELS request type.
6443 * @param req_len Length of ELS request in bytes.
6444 * @param max_rsp_len Max length of ELS response in bytes.
6445 * @param timeout Time, in seconds, before an IO times out. Zero means 2 * R_A_TOV.
6446 * @param xri XRI for this exchange.
6447 * @param tag IO tag value.
6448 * @param cq_id The id of the completion queue where the WQE response is sent.
6449 * @param rnode Destination of ELS request (that is, the remote node).
6451 * @return Returns 0 on success, or a non-zero value on failure.
6454 sli_els_request64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint8_t req_type,
6455 uint32_t req_len, uint32_t max_rsp_len, uint8_t timeout,
6456 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode)
6458 sli4_els_request64_wqe_t *els = buf;
6459 sli4_sge_t *sge = sgl->virt;
6460 uint8_t is_fabric = FALSE;
6462 ocs_memset(buf, 0, size);
6464 if (sli4->config.sgl_pre_registered) {
6468 els->els_request_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
6470 els->els_request_payload.buffer_length = req_len;
6471 els->els_request_payload.u.data.buffer_address_low = sge[0].buffer_address_low;
6472 els->els_request_payload.u.data.buffer_address_high = sge[0].buffer_address_high;
6476 els->els_request_payload.bde_type = SLI4_BDE_TYPE_BLP;
6478 els->els_request_payload.buffer_length = 2 * sizeof(sli4_sge_t);
6479 els->els_request_payload.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6480 els->els_request_payload.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6483 els->els_request_payload_length = req_len;
6484 els->max_response_payload_length = max_rsp_len;
6487 els->timer = timeout;
6488 els->class = SLI4_ELS_REQUEST64_CLASS_3;
6490 els->command = SLI4_WQE_ELS_REQUEST64;
6492 els->request_tag = tag;
6494 if (rnode->node_group) {
6496 els->remote_id = rnode->fc_id & 0x00ffffff;
6499 els->iod = SLI4_ELS_REQUEST64_DIR_READ;
6503 /* figure out the ELS_ID value from the request buffer */
6506 case FC_ELS_CMD_LOGO:
6507 els->els_id = SLI4_ELS_REQUEST64_LOGO;
6508 if (rnode->attached) {
6509 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6510 els->context_tag = rnode->indicator;
6512 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6513 els->context_tag = rnode->sport->indicator;
6515 if (FC_ADDR_FABRIC == rnode->fc_id) {
6519 case FC_ELS_CMD_FDISC:
6520 if (FC_ADDR_FABRIC == rnode->fc_id) {
6523 if (0 == rnode->sport->fc_id) {
6524 els->els_id = SLI4_ELS_REQUEST64_FDISC;
6527 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6529 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6530 els->context_tag = rnode->sport->indicator;
6533 case FC_ELS_CMD_FLOGI:
6534 els->els_id = SLI4_ELS_REQUEST64_FLOGIN;
6536 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
6537 if (!rnode->sport->domain) {
6538 ocs_log_test(sli4->os, "invalid domain handle\n");
6542 * IF_TYPE 0 skips INIT_VFI/INIT_VPI and therefore must use the
6545 els->ct = SLI4_ELS_REQUEST64_CONTEXT_FCFI;
6546 els->context_tag = rnode->sport->domain->fcf_indicator;
6549 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6550 els->context_tag = rnode->sport->indicator;
6553 * Set SP here ... we haven't done a REG_VPI yet
6554 * TODO: need to maybe not set this when we have
6555 * completed VFI/VPI registrations ...
6557 * Use the FC_ID of the SPORT if it has been allocated, otherwise
6558 * use an S_ID of zero.
6561 if (rnode->sport->fc_id != UINT32_MAX) {
6562 els->sid = rnode->sport->fc_id;
6566 case FC_ELS_CMD_PLOGI:
6567 els->els_id = SLI4_ELS_REQUEST64_PLOGI;
6568 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6569 els->context_tag = rnode->sport->indicator;
6571 case FC_ELS_CMD_SCR:
6572 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6573 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6574 els->context_tag = rnode->sport->indicator;
6577 els->els_id = SLI4_ELS_REQUEST64_OTHER;
6578 if (rnode->attached) {
6579 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6580 els->context_tag = rnode->indicator;
6582 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
6583 els->context_tag = rnode->sport->indicator;
6589 els->cmd_type = SLI4_ELS_REQUEST64_CMD_FABRIC;
6591 els->cmd_type = SLI4_ELS_REQUEST64_CMD_NON_FABRIC;
6596 if (SLI4_ELS_REQUEST64_CONTEXT_RPI != els->ct) {
6597 els->remote_id = rnode->fc_id;
6599 if (SLI4_ELS_REQUEST64_CONTEXT_VPI == els->ct) {
6600 els->temporary_rpi = rnode->indicator;
6609 * @brief Write an FCP_ICMND64_WQE work queue entry.
6611 * @param sli4 SLI context.
6612 * @param buf Destination buffer for the WQE.
6613 * @param size Buffer size, in bytes.
6614 * @param sgl DMA memory for the scatter gather list.
6615 * @param xri XRI for this exchange.
6616 * @param tag IO tag value.
6617 * @param cq_id The id of the completion queue where the WQE response is sent.
6618 * @param rpi remote node indicator (RPI)
6619 * @param rnode Destination request (that is, the remote node).
6620 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6622 * @return Returns 0 on success, or a non-zero value on failure.
6625 sli_fcp_icmnd64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl,
6626 uint16_t xri, uint16_t tag, uint16_t cq_id,
6627 uint32_t rpi, ocs_remote_node_t *rnode, uint8_t timeout)
6629 sli4_fcp_icmnd64_wqe_t *icmnd = buf;
6630 sli4_sge_t *sge = NULL;
6632 ocs_memset(buf, 0, size);
6634 if (!sgl || !sgl->virt) {
6635 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6636 sgl, sgl ? sgl->virt : NULL);
6641 if (sli4->config.sgl_pre_registered) {
6645 icmnd->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6647 icmnd->bde.buffer_length = sge[0].buffer_length;
6648 icmnd->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6649 icmnd->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6653 icmnd->bde.bde_type = SLI4_BDE_TYPE_BLP;
6655 icmnd->bde.buffer_length = sgl->size;
6656 icmnd->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6657 icmnd->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6660 icmnd->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6661 icmnd->xri_tag = xri;
6662 icmnd->context_tag = rpi;
6663 icmnd->timer = timeout;
6665 icmnd->pu = 2; /* WQE word 4 contains read transfer length */
6666 icmnd->class = SLI4_ELS_REQUEST64_CLASS_3;
6667 icmnd->command = SLI4_WQE_FCP_ICMND64;
6668 icmnd->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6670 icmnd->abort_tag = xri;
6672 icmnd->request_tag = tag;
6674 if (rnode->node_group) {
6676 icmnd->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6678 if (((ocs_node_t *)rnode->node)->fcp2device) {
6681 icmnd->cmd_type = SLI4_CMD_FCP_ICMND64_WQE;
6682 icmnd->cq_id = cq_id;
6689 * @brief Write an FCP_IREAD64_WQE work queue entry.
6691 * @param sli4 SLI context.
6692 * @param buf Destination buffer for the WQE.
6693 * @param size Buffer size, in bytes.
6694 * @param sgl DMA memory for the scatter gather list.
6695 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6696 * @param xfer_len Data transfer length.
6697 * @param xri XRI for this exchange.
6698 * @param tag IO tag value.
6699 * @param cq_id The id of the completion queue where the WQE response is sent.
6700 * @param rpi remote node indicator (RPI)
6701 * @param rnode Destination request (i.e. remote node).
6702 * @param dif T10 DIF operation, or 0 to disable.
6703 * @param bs T10 DIF block size, or 0 if DIF is disabled.
6704 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6706 * @return Returns 0 on success, or a non-zero value on failure.
6709 sli_fcp_iread64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6710 uint32_t xfer_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
6711 uint32_t rpi, ocs_remote_node_t *rnode,
6712 uint8_t dif, uint8_t bs, uint8_t timeout)
6714 sli4_fcp_iread64_wqe_t *iread = buf;
6715 sli4_sge_t *sge = NULL;
6717 ocs_memset(buf, 0, size);
6719 if (!sgl || !sgl->virt) {
6720 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6721 sgl, sgl ? sgl->virt : NULL);
6726 if (sli4->config.sgl_pre_registered) {
6730 iread->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6732 iread->bde.buffer_length = sge[0].buffer_length;
6733 iread->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6734 iread->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6738 iread->bde.bde_type = SLI4_BDE_TYPE_BLP;
6740 iread->bde.buffer_length = sgl->size;
6741 iread->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6742 iread->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6744 /* fill out fcp_cmnd buffer len and change resp buffer to be of type
6745 * "skip" (note: response will still be written to sge[1] if necessary) */
6746 iread->fcp_cmd_buffer_length = sge[0].buffer_length;
6747 sge[1].sge_type = SLI4_SGE_TYPE_SKIP;
6750 iread->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6751 iread->total_transfer_length = xfer_len;
6753 iread->xri_tag = xri;
6754 iread->context_tag = rpi;
6756 iread->timer = timeout;
6758 iread->pu = 2; /* WQE word 4 contains read transfer length */
6759 iread->class = SLI4_ELS_REQUEST64_CLASS_3;
6760 iread->command = SLI4_WQE_FCP_IREAD64;
6761 iread->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6765 iread->abort_tag = xri;
6767 iread->request_tag = tag;
6769 if (rnode->node_group) {
6771 iread->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6773 if (((ocs_node_t *)rnode->node)->fcp2device) {
6777 iread->cmd_type = SLI4_CMD_FCP_IREAD64_WQE;
6778 iread->cq_id = cq_id;
6780 if (sli4->config.perf_hint) {
6781 iread->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6782 iread->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
6783 iread->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
6784 iread->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
6793 * @brief Write an FCP_IWRITE64_WQE work queue entry.
6795 * @param sli4 SLI context.
6796 * @param buf Destination buffer for the WQE.
6797 * @param size Buffer size, in bytes.
6798 * @param sgl DMA memory for the scatter gather list.
6799 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6800 * @param xfer_len Data transfer length.
6801 * @param first_burst The number of first burst bytes
6802 * @param xri XRI for this exchange.
6803 * @param tag IO tag value.
6804 * @param cq_id The id of the completion queue where the WQE response is sent.
6805 * @param rpi remote node indicator (RPI)
6806 * @param rnode Destination request (i.e. remote node)
6807 * @param dif T10 DIF operation, or 0 to disable
6808 * @param bs T10 DIF block size, or 0 if DIF is disabled
6809 * @param timeout Time, in seconds, before an IO times out. Zero means no timeout.
6811 * @return Returns 0 on success, or a non-zero value on failure.
6814 sli_fcp_iwrite64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6815 uint32_t xfer_len, uint32_t first_burst, uint16_t xri, uint16_t tag, uint16_t cq_id,
6816 uint32_t rpi, ocs_remote_node_t *rnode,
6817 uint8_t dif, uint8_t bs, uint8_t timeout)
6819 sli4_fcp_iwrite64_wqe_t *iwrite = buf;
6820 sli4_sge_t *sge = NULL;
6822 ocs_memset(buf, 0, size);
6824 if (!sgl || !sgl->virt) {
6825 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6826 sgl, sgl ? sgl->virt : NULL);
6831 if (sli4->config.sgl_pre_registered) {
6832 iwrite->xbl = FALSE;
6834 iwrite->dbde = TRUE;
6835 iwrite->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6837 iwrite->bde.buffer_length = sge[0].buffer_length;
6838 iwrite->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6839 iwrite->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6843 iwrite->bde.bde_type = SLI4_BDE_TYPE_BLP;
6845 iwrite->bde.buffer_length = sgl->size;
6846 iwrite->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6847 iwrite->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6849 /* fill out fcp_cmnd buffer len and change resp buffer to be of type
6850 * "skip" (note: response will still be written to sge[1] if necessary) */
6851 iwrite->fcp_cmd_buffer_length = sge[0].buffer_length;
6852 sge[1].sge_type = SLI4_SGE_TYPE_SKIP;
6855 iwrite->payload_offset_length = sge[0].buffer_length + sge[1].buffer_length;
6856 iwrite->total_transfer_length = xfer_len;
6857 iwrite->initial_transfer_length = MIN(xfer_len, first_burst);
6859 iwrite->xri_tag = xri;
6860 iwrite->context_tag = rpi;
6862 iwrite->timer = timeout;
6864 iwrite->pu = 2; /* WQE word 4 contains read transfer length */
6865 iwrite->class = SLI4_ELS_REQUEST64_CLASS_3;
6866 iwrite->command = SLI4_WQE_FCP_IWRITE64;
6867 iwrite->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6871 iwrite->abort_tag = xri;
6873 iwrite->request_tag = tag;
6874 iwrite->len_loc = 3;
6875 if (rnode->node_group) {
6877 iwrite->remote_n_port_id = rnode->fc_id & 0x00ffffff;
6879 if (((ocs_node_t *)rnode->node)->fcp2device) {
6882 iwrite->cmd_type = SLI4_CMD_FCP_IWRITE64_WQE;
6883 iwrite->cq_id = cq_id;
6885 if (sli4->config.perf_hint) {
6886 iwrite->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6887 iwrite->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
6888 iwrite->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
6889 iwrite->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
6897 * @brief Write an FCP_TRECEIVE64_WQE work queue entry.
6899 * @param sli4 SLI context.
6900 * @param buf Destination buffer for the WQE.
6901 * @param size Buffer size, in bytes.
6902 * @param sgl DMA memory for the Scatter-Gather List.
6903 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
6904 * @param relative_off Relative offset of the IO (if any).
6905 * @param xfer_len Data transfer length.
6906 * @param xri XRI for this exchange.
6907 * @param tag IO tag value.
6908 * @param xid OX_ID for the exchange.
6909 * @param cq_id The id of the completion queue where the WQE response is sent.
6910 * @param rpi remote node indicator (RPI)
6911 * @param rnode Destination request (i.e. remote node).
6912 * @param flags Optional attributes, including:
6913 * - ACTIVE - IO is already active.
6914 * - AUTO RSP - Automatically generate a good FCP_RSP.
6915 * @param dif T10 DIF operation, or 0 to disable.
6916 * @param bs T10 DIF block size, or 0 if DIF is disabled.
6917 * @param csctl value of csctl field.
6918 * @param app_id value for VM application header.
6920 * @return Returns 0 on success, or a non-zero value on failure.
6923 sli_fcp_treceive64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
6924 uint32_t relative_off, uint32_t xfer_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
6925 uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode, uint32_t flags, uint8_t dif, uint8_t bs,
6926 uint8_t csctl, uint32_t app_id)
6928 sli4_fcp_treceive64_wqe_t *trecv = buf;
6929 sli4_fcp_128byte_wqe_t *trecv_128 = buf;
6930 sli4_sge_t *sge = NULL;
6932 ocs_memset(buf, 0, size);
6934 if (!sgl || !sgl->virt) {
6935 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
6936 sgl, sgl ? sgl->virt : NULL);
6941 if (sli4->config.sgl_pre_registered) {
6945 trecv->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6947 trecv->bde.buffer_length = sge[0].buffer_length;
6948 trecv->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
6949 trecv->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
6951 trecv->payload_offset_length = sge[0].buffer_length;
6955 /* if data is a single physical address, use a BDE */
6956 if (!dif && (xfer_len <= sge[2].buffer_length)) {
6958 trecv->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
6960 trecv->bde.buffer_length = sge[2].buffer_length;
6961 trecv->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
6962 trecv->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
6964 trecv->bde.bde_type = SLI4_BDE_TYPE_BLP;
6965 trecv->bde.buffer_length = sgl->size;
6966 trecv->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
6967 trecv->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
6971 trecv->relative_offset = relative_off;
6973 if (flags & SLI4_IO_CONTINUATION) {
6976 trecv->xri_tag = xri;
6978 trecv->context_tag = rpi;
6980 trecv->pu = TRUE; /* WQE uses relative offset */
6982 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
6986 trecv->command = SLI4_WQE_FCP_TRECEIVE64;
6987 trecv->class = SLI4_ELS_REQUEST64_CLASS_3;
6988 trecv->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
6992 trecv->remote_xid = xid;
6994 trecv->request_tag = tag;
6998 trecv->len_loc = 0x2;
7000 if (rnode->node_group) {
7002 trecv->dword5.dword = rnode->fc_id & 0x00ffffff;
7005 trecv->cmd_type = SLI4_CMD_FCP_TRECEIVE64_WQE;
7007 trecv->cq_id = cq_id;
7009 trecv->fcp_data_receive_length = xfer_len;
7011 if (sli4->config.perf_hint) {
7012 trecv->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7013 trecv->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
7014 trecv->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
7015 trecv->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
7018 /* The upper 7 bits of csctl is the priority */
7019 if (csctl & SLI4_MASK_CCP) {
7021 trecv->ccp = (csctl & SLI4_MASK_CCP);
7024 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !trecv->eat) {
7025 trecv->app_id_valid = 1;
7027 trecv_128->dw[31] = app_id;
7034 * @brief Write an FCP_CONT_TRECEIVE64_WQE work queue entry.
7036 * @param sli4 SLI context.
7037 * @param buf Destination buffer for the WQE.
7038 * @param size Buffer size, in bytes.
7039 * @param sgl DMA memory for the Scatter-Gather List.
7040 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
7041 * @param relative_off Relative offset of the IO (if any).
7042 * @param xfer_len Data transfer length.
7043 * @param xri XRI for this exchange.
7044 * @param sec_xri Secondary XRI for this exchange. (BZ 161832 workaround)
7045 * @param tag IO tag value.
7046 * @param xid OX_ID for the exchange.
7047 * @param cq_id The id of the completion queue where the WQE response is sent.
7048 * @param rpi remote node indicator (RPI)
7049 * @param rnode Destination request (i.e. remote node).
7050 * @param flags Optional attributes, including:
7051 * - ACTIVE - IO is already active.
7052 * - AUTO RSP - Automatically generate a good FCP_RSP.
7053 * @param dif T10 DIF operation, or 0 to disable.
7054 * @param bs T10 DIF block size, or 0 if DIF is disabled.
7055 * @param csctl value of csctl field.
7056 * @param app_id value for VM application header.
7058 * @return Returns 0 on success, or a non-zero value on failure.
7061 sli_fcp_cont_treceive64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
7062 uint32_t relative_off, uint32_t xfer_len, uint16_t xri, uint16_t sec_xri, uint16_t tag,
7063 uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode, uint32_t flags,
7064 uint8_t dif, uint8_t bs, uint8_t csctl, uint32_t app_id)
7068 rc = sli_fcp_treceive64_wqe(sli4, buf, size, sgl, first_data_sge, relative_off, xfer_len, xri, tag,
7069 cq_id, xid, rpi, rnode, flags, dif, bs, csctl, app_id);
7071 sli4_fcp_treceive64_wqe_t *trecv = buf;
7073 trecv->command = SLI4_WQE_FCP_CONT_TRECEIVE64;
7074 trecv->dword5.sec_xri_tag = sec_xri;
7081 * @brief Write an FCP_TRSP64_WQE work queue entry.
7083 * @param sli4 SLI context.
7084 * @param buf Destination buffer for the WQE.
7085 * @param size Buffer size, in bytes.
7086 * @param sgl DMA memory for the Scatter-Gather List.
7087 * @param rsp_len Response data length.
7088 * @param xri XRI for this exchange.
7089 * @param tag IO tag value.
7090 * @param cq_id The id of the completion queue where the WQE response is sent.
7091 * @param xid OX_ID for the exchange.
7092 * @param rpi remote node indicator (RPI)
7093 * @param rnode Destination request (i.e. remote node).
7094 * @param flags Optional attributes, including:
7095 * - ACTIVE - IO is already active
7096 * - AUTO RSP - Automatically generate a good FCP_RSP.
7097 * @param csctl value of csctl field.
7098 * @param port_owned 0/1 to indicate if the XRI is port owned (used to set XBL=0)
7099 * @param app_id value for VM application header.
7101 * @return Returns 0 on success, or a non-zero value on failure.
7104 sli_fcp_trsp64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t rsp_len,
7105 uint16_t xri, uint16_t tag, uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode,
7106 uint32_t flags, uint8_t csctl, uint8_t port_owned, uint32_t app_id)
7108 sli4_fcp_trsp64_wqe_t *trsp = buf;
7109 sli4_fcp_128byte_wqe_t *trsp_128 = buf;
7111 ocs_memset(buf, 0, size);
7113 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
7116 * The SLI-4 documentation states that the BDE is ignored when
7117 * using auto-good response, but, at least for IF_TYPE 0 devices,
7118 * this does not appear to be true.
7120 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
7121 trsp->bde.buffer_length = 12; /* byte size of RSP */
7124 sli4_sge_t *sge = sgl->virt;
7126 if (sli4->config.sgl_pre_registered || port_owned) {
7132 trsp->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7133 trsp->bde.buffer_length = sge[0].buffer_length;
7134 trsp->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
7135 trsp->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
7137 trsp->fcp_response_length = rsp_len;
7140 if (flags & SLI4_IO_CONTINUATION) {
7144 if (rnode->node_group) {
7146 trsp->dword5 = rnode->fc_id & 0x00ffffff;
7149 trsp->xri_tag = xri;
7152 trsp->command = SLI4_WQE_FCP_TRSP64;
7153 trsp->class = SLI4_ELS_REQUEST64_CLASS_3;
7155 trsp->remote_xid = xid;
7156 trsp->request_tag = tag;
7157 trsp->dnrx = ((flags & SLI4_IO_DNRX) == 0 ? 0 : 1);
7158 trsp->len_loc = 0x1;
7159 trsp->cq_id = cq_id;
7160 trsp->cmd_type = SLI4_CMD_FCP_TRSP64_WQE;
7162 /* The upper 7 bits of csctl is the priority */
7163 if (csctl & SLI4_MASK_CCP) {
7165 trsp->ccp = (csctl & SLI4_MASK_CCP);
7168 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !trsp->eat) {
7169 trsp->app_id_valid = 1;
7171 trsp_128->dw[31] = app_id;
7178 * @brief Write an FCP_TSEND64_WQE work queue entry.
7180 * @param sli4 SLI context.
7181 * @param buf Destination buffer for the WQE.
7182 * @param size Buffer size, in bytes.
7183 * @param sgl DMA memory for the scatter gather list.
7184 * @param first_data_sge Index of first data sge (used if perf hints are enabled)
7185 * @param relative_off Relative offset of the IO (if any).
7186 * @param xfer_len Data transfer length.
7187 * @param xri XRI for this exchange.
7188 * @param tag IO tag value.
7189 * @param cq_id The id of the completion queue where the WQE response is sent.
7190 * @param xid OX_ID for the exchange.
7191 * @param rpi remote node indicator (RPI)
7192 * @param rnode Destination request (i.e. remote node).
7193 * @param flags Optional attributes, including:
7194 * - ACTIVE - IO is already active.
7195 * - AUTO RSP - Automatically generate a good FCP_RSP.
7196 * @param dif T10 DIF operation, or 0 to disable.
7197 * @param bs T10 DIF block size, or 0 if DIF is disabled.
7198 * @param csctl value of csctl field.
7199 * @param app_id value for VM application header.
7201 * @return Returns 0 on success, or a non-zero value on failure.
7204 sli_fcp_tsend64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl, uint32_t first_data_sge,
7205 uint32_t relative_off, uint32_t xfer_len,
7206 uint16_t xri, uint16_t tag, uint16_t cq_id, uint16_t xid, uint32_t rpi, ocs_remote_node_t *rnode,
7207 uint32_t flags, uint8_t dif, uint8_t bs, uint8_t csctl, uint32_t app_id)
7209 sli4_fcp_tsend64_wqe_t *tsend = buf;
7210 sli4_fcp_128byte_wqe_t *tsend_128 = buf;
7211 sli4_sge_t *sge = NULL;
7213 ocs_memset(buf, 0, size);
7215 if (!sgl || !sgl->virt) {
7216 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7217 sgl, sgl ? sgl->virt : NULL);
7222 if (sli4->config.sgl_pre_registered) {
7226 tsend->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7228 /* TSEND64_WQE specifies first two SGE are skipped
7229 * (i.e. 3rd is valid) */
7230 tsend->bde.buffer_length = sge[2].buffer_length;
7231 tsend->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
7232 tsend->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
7236 /* if data is a single physical address, use a BDE */
7237 if (!dif && (xfer_len <= sge[2].buffer_length)) {
7239 tsend->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7240 /* TSEND64_WQE specifies first two SGE are skipped
7241 * (i.e. 3rd is valid) */
7242 tsend->bde.buffer_length = sge[2].buffer_length;
7243 tsend->bde.u.data.buffer_address_low = sge[2].buffer_address_low;
7244 tsend->bde.u.data.buffer_address_high = sge[2].buffer_address_high;
7246 tsend->bde.bde_type = SLI4_BDE_TYPE_BLP;
7247 tsend->bde.buffer_length = sgl->size;
7248 tsend->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
7249 tsend->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
7253 tsend->relative_offset = relative_off;
7255 if (flags & SLI4_IO_CONTINUATION) {
7258 tsend->xri_tag = xri;
7262 tsend->pu = TRUE; /* WQE uses relative offset */
7264 if (flags & SLI4_IO_AUTO_GOOD_RESPONSE) {
7268 tsend->command = SLI4_WQE_FCP_TSEND64;
7269 tsend->class = SLI4_ELS_REQUEST64_CLASS_3;
7270 tsend->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7274 tsend->remote_xid = xid;
7276 tsend->request_tag = tag;
7278 tsend->len_loc = 0x2;
7280 if (rnode->node_group) {
7282 tsend->dword5 = rnode->fc_id & 0x00ffffff;
7285 tsend->cq_id = cq_id;
7287 tsend->cmd_type = SLI4_CMD_FCP_TSEND64_WQE;
7289 tsend->fcp_data_transmit_length = xfer_len;
7291 if (sli4->config.perf_hint) {
7292 tsend->first_data_bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7293 tsend->first_data_bde.buffer_length = sge[first_data_sge].buffer_length;
7294 tsend->first_data_bde.u.data.buffer_address_low = sge[first_data_sge].buffer_address_low;
7295 tsend->first_data_bde.u.data.buffer_address_high = sge[first_data_sge].buffer_address_high;
7298 /* The upper 7 bits of csctl is the priority */
7299 if (csctl & SLI4_MASK_CCP) {
7301 tsend->ccp = (csctl & SLI4_MASK_CCP);
7304 if (app_id && (sli4->config.wqe_size == SLI4_WQE_EXT_BYTES) && !tsend->eat) {
7305 tsend->app_id_valid = 1;
7307 tsend_128->dw[31] = app_id;
7314 * @brief Write a GEN_REQUEST64 work queue entry.
7316 * @note This WQE is only used to send FC-CT commands.
7318 * @param sli4 SLI context.
7319 * @param buf Destination buffer for the WQE.
7320 * @param size Buffer size, in bytes.
7321 * @param sgl DMA memory for the request.
7322 * @param req_len Length of request.
7323 * @param max_rsp_len Max length of response.
7324 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7325 * @param xri XRI for this exchange.
7326 * @param tag IO tag value.
7327 * @param cq_id The id of the completion queue where the WQE response is sent.
7328 * @param rnode Destination of request (that is, the remote node).
7329 * @param r_ctl R_CTL value for sequence.
7330 * @param type TYPE value for sequence.
7331 * @param df_ctl DF_CTL value for sequence.
7333 * @return Returns 0 on success, or a non-zero value on failure.
7336 sli_gen_request64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *sgl,
7337 uint32_t req_len, uint32_t max_rsp_len, uint8_t timeout,
7338 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode,
7339 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7341 sli4_gen_request64_wqe_t *gen = buf;
7342 sli4_sge_t *sge = NULL;
7344 ocs_memset(buf, 0, size);
7346 if (!sgl || !sgl->virt) {
7347 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7348 sgl, sgl ? sgl->virt : NULL);
7353 if (sli4->config.sgl_pre_registered) {
7357 gen->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7359 gen->bde.buffer_length = req_len;
7360 gen->bde.u.data.buffer_address_low = sge[0].buffer_address_low;
7361 gen->bde.u.data.buffer_address_high = sge[0].buffer_address_high;
7365 gen->bde.bde_type = SLI4_BDE_TYPE_BLP;
7367 gen->bde.buffer_length = 2 * sizeof(sli4_sge_t);
7368 gen->bde.u.blp.sgl_segment_address_low = ocs_addr32_lo(sgl->phys);
7369 gen->bde.u.blp.sgl_segment_address_high = ocs_addr32_hi(sgl->phys);
7372 gen->request_payload_length = req_len;
7373 gen->max_response_payload_length = max_rsp_len;
7375 gen->df_ctl = df_ctl;
7381 gen->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7382 gen->context_tag = rnode->indicator;
7384 gen->class = SLI4_ELS_REQUEST64_CLASS_3;
7386 gen->command = SLI4_WQE_GEN_REQUEST64;
7388 gen->timer = timeout;
7390 gen->request_tag = tag;
7392 gen->iod = SLI4_ELS_REQUEST64_DIR_READ;
7396 if (rnode->node_group) {
7398 gen->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7401 gen->cmd_type = SLI4_CMD_GEN_REQUEST64_WQE;
7410 * @brief Write a SEND_FRAME work queue entry
7412 * @param sli4 SLI context.
7413 * @param buf Destination buffer for the WQE.
7414 * @param size Buffer size, in bytes.
7415 * @param sof Start of frame value
7416 * @param eof End of frame value
7417 * @param hdr Pointer to FC header data
7418 * @param payload DMA memory for the payload.
7419 * @param req_len Length of payload.
7420 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7421 * @param xri XRI for this exchange.
7422 * @param req_tag IO tag value.
7424 * @return Returns 0 on success, or a non-zero value on failure.
7427 sli_send_frame_wqe(sli4_t *sli4, void *buf, size_t size, uint8_t sof, uint8_t eof, uint32_t *hdr,
7428 ocs_dma_t *payload, uint32_t req_len, uint8_t timeout,
7429 uint16_t xri, uint16_t req_tag)
7431 sli4_send_frame_wqe_t *sf = buf;
7433 ocs_memset(buf, 0, size);
7436 sf->bde.buffer_length = req_len;
7437 sf->bde.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7438 sf->bde.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7440 /* Copy FC header */
7441 sf->fc_header_0_1[0] = hdr[0];
7442 sf->fc_header_0_1[1] = hdr[1];
7443 sf->fc_header_2_5[0] = hdr[2];
7444 sf->fc_header_2_5[1] = hdr[3];
7445 sf->fc_header_2_5[2] = hdr[4];
7446 sf->fc_header_2_5[3] = hdr[5];
7448 sf->frame_length = req_len;
7452 sf->context_tag = 0;
7456 sf->command = SLI4_WQE_SEND_FRAME;
7457 sf->class = SLI4_ELS_REQUEST64_CLASS_3;
7458 sf->timer = timeout;
7460 sf->request_tag = req_tag;
7470 sf->cmd_type = SLI4_CMD_SEND_FRAME_WQE;
7478 * @brief Write a XMIT_SEQUENCE64 work queue entry.
7480 * This WQE is used to send FC-CT response frames.
7482 * @note This API implements a restricted use for this WQE, a TODO: would
7483 * include passing in sequence initiative, and full SGL's
7485 * @param sli4 SLI context.
7486 * @param buf Destination buffer for the WQE.
7487 * @param size Buffer size, in bytes.
7488 * @param payload DMA memory for the request.
7489 * @param payload_len Length of request.
7490 * @param timeout Time, in seconds, before an IO times out. Zero means infinite.
7491 * @param ox_id originator exchange ID
7492 * @param xri XRI for this exchange.
7493 * @param tag IO tag value.
7494 * @param rnode Destination of request (that is, the remote node).
7495 * @param r_ctl R_CTL value for sequence.
7496 * @param type TYPE value for sequence.
7497 * @param df_ctl DF_CTL value for sequence.
7499 * @return Returns 0 on success, or a non-zero value on failure.
7502 sli_xmit_sequence64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *payload,
7503 uint32_t payload_len, uint8_t timeout, uint16_t ox_id,
7504 uint16_t xri, uint16_t tag, ocs_remote_node_t *rnode,
7505 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7507 sli4_xmit_sequence64_wqe_t *xmit = buf;
7509 ocs_memset(buf, 0, size);
7511 if ((payload == NULL) || (payload->virt == NULL)) {
7512 ocs_log_err(sli4->os, "bad parameter sgl=%p virt=%p\n",
7513 payload, payload ? payload->virt : NULL);
7517 if (sli4->config.sgl_pre_registered) {
7523 xmit->bde.bde_type = SLI4_BDE_TYPE_BDE_64;
7524 xmit->bde.buffer_length = payload_len;
7525 xmit->bde.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7526 xmit->bde.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7527 xmit->sequence_payload_len = payload_len;
7529 xmit->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7531 xmit->relative_offset = 0;
7533 xmit->si = 0; /* sequence initiative - this matches what is seen from
7534 * FC switches in response to FCGS commands */
7535 xmit->ft = 0; /* force transmit */
7536 xmit->xo = 0; /* exchange responder */
7537 xmit->ls = 1; /* last in seqence */
7538 xmit->df_ctl = df_ctl;
7540 xmit->r_ctl = r_ctl;
7542 xmit->xri_tag = xri;
7543 xmit->context_tag = rnode->indicator;
7546 xmit->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7549 xmit->command = SLI4_WQE_XMIT_SEQUENCE64;
7550 xmit->class = SLI4_ELS_REQUEST64_CLASS_3;
7552 xmit->timer = timeout;
7554 xmit->abort_tag = 0;
7555 xmit->request_tag = tag;
7556 xmit->remote_xid = ox_id;
7558 xmit->iod = SLI4_ELS_REQUEST64_DIR_READ;
7560 if (rnode->node_group) {
7562 xmit->remote_n_port_id = rnode->fc_id & 0x00ffffff;
7565 xmit->cmd_type = SLI4_CMD_XMIT_SEQUENCE64_WQE;
7569 xmit->cq_id = 0xFFFF;
7576 * @brief Write a REQUEUE_XRI_WQE work queue entry.
7578 * @param sli4 SLI context.
7579 * @param buf Destination buffer for the WQE.
7580 * @param size Buffer size, in bytes.
7581 * @param xri XRI for this exchange.
7582 * @param tag IO tag value.
7583 * @param cq_id The id of the completion queue where the WQE response is sent.
7585 * @return Returns 0 on success, or a non-zero value on failure.
7588 sli_requeue_xri_wqe(sli4_t *sli4, void *buf, size_t size, uint16_t xri, uint16_t tag, uint16_t cq_id)
7590 sli4_requeue_xri_wqe_t *requeue = buf;
7592 ocs_memset(buf, 0, size);
7594 requeue->command = SLI4_WQE_REQUEUE_XRI;
7595 requeue->xri_tag = xri;
7596 requeue->request_tag = tag;
7599 requeue->cq_id = cq_id;
7600 requeue->cmd_type = SLI4_CMD_REQUEUE_XRI_WQE;
7605 sli_xmit_bcast64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *payload,
7606 uint32_t payload_len, uint8_t timeout, uint16_t xri, uint16_t tag,
7607 uint16_t cq_id, ocs_remote_node_t *rnode,
7608 uint8_t r_ctl, uint8_t type, uint8_t df_ctl)
7610 sli4_xmit_bcast64_wqe_t *bcast = buf;
7612 /* Command requires a temporary RPI (i.e. unused remote node) */
7613 if (rnode->attached) {
7614 ocs_log_test(sli4->os, "remote node %d in use\n", rnode->indicator);
7618 ocs_memset(buf, 0, size);
7621 bcast->sequence_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
7622 bcast->sequence_payload.buffer_length = payload_len;
7623 bcast->sequence_payload.u.data.buffer_address_low = ocs_addr32_lo(payload->phys);
7624 bcast->sequence_payload.u.data.buffer_address_high = ocs_addr32_hi(payload->phys);
7626 bcast->sequence_payload_length = payload_len;
7628 bcast->df_ctl = df_ctl;
7630 bcast->r_ctl = r_ctl;
7632 bcast->xri_tag = xri;
7634 bcast->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7635 bcast->context_tag = rnode->sport->indicator;
7637 bcast->class = SLI4_ELS_REQUEST64_CLASS_3;
7639 bcast->command = SLI4_WQE_XMIT_BCAST64;
7641 bcast->timer = timeout;
7643 bcast->request_tag = tag;
7645 bcast->temporary_rpi = rnode->indicator;
7647 bcast->len_loc = 0x1;
7649 bcast->iod = SLI4_ELS_REQUEST64_DIR_WRITE;
7651 bcast->cmd_type = SLI4_CMD_XMIT_BCAST64_WQE;
7653 bcast->cq_id = cq_id;
7660 * @brief Write an XMIT_BLS_RSP64_WQE work queue entry.
7662 * @param sli4 SLI context.
7663 * @param buf Destination buffer for the WQE.
7664 * @param size Buffer size, in bytes.
7665 * @param payload Contents of the BLS payload to be sent.
7666 * @param xri XRI for this exchange.
7667 * @param tag IO tag value.
7668 * @param cq_id The id of the completion queue where the WQE response is sent.
7669 * @param rnode Destination of request (that is, the remote node).
7670 * @param s_id Source ID to use in the response. If UINT32_MAX, use SLI Port's ID.
7672 * @return Returns 0 on success, or a non-zero value on failure.
7675 sli_xmit_bls_rsp64_wqe(sli4_t *sli4, void *buf, size_t size, sli_bls_payload_t *payload,
7676 uint16_t xri, uint16_t tag, uint16_t cq_id, ocs_remote_node_t *rnode, uint32_t s_id)
7678 sli4_xmit_bls_rsp_wqe_t *bls = buf;
7681 * Callers can either specify RPI or S_ID, but not both
7683 if (rnode->attached && (s_id != UINT32_MAX)) {
7684 ocs_log_test(sli4->os, "S_ID specified for attached remote node %d\n",
7689 ocs_memset(buf, 0, size);
7691 if (SLI_BLS_ACC == payload->type) {
7692 bls->payload_word0 = (payload->u.acc.seq_id_last << 16) |
7693 (payload->u.acc.seq_id_validity << 24);
7694 bls->high_seq_cnt = payload->u.acc.high_seq_cnt;
7695 bls->low_seq_cnt = payload->u.acc.low_seq_cnt;
7696 } else if (SLI_BLS_RJT == payload->type) {
7697 bls->payload_word0 = *((uint32_t *)&payload->u.rjt);
7700 ocs_log_test(sli4->os, "bad BLS type %#x\n",
7705 bls->ox_id = payload->ox_id;
7706 bls->rx_id = payload->rx_id;
7708 if (rnode->attached) {
7709 bls->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7710 bls->context_tag = rnode->indicator;
7712 bls->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7713 bls->context_tag = rnode->sport->indicator;
7715 if (UINT32_MAX != s_id) {
7716 bls->local_n_port_id = s_id & 0x00ffffff;
7718 bls->local_n_port_id = rnode->sport->fc_id & 0x00ffffff;
7720 bls->remote_id = rnode->fc_id & 0x00ffffff;
7722 bls->temporary_rpi = rnode->indicator;
7727 bls->class = SLI4_ELS_REQUEST64_CLASS_3;
7729 bls->command = SLI4_WQE_XMIT_BLS_RSP;
7731 bls->request_tag = tag;
7735 if (rnode->node_group) {
7737 bls->remote_id = rnode->fc_id & 0x00ffffff;
7742 bls->cmd_type = SLI4_CMD_XMIT_BLS_RSP64_WQE;
7749 * @brief Write a XMIT_ELS_RSP64_WQE work queue entry.
7751 * @param sli4 SLI context.
7752 * @param buf Destination buffer for the WQE.
7753 * @param size Buffer size, in bytes.
7754 * @param rsp DMA memory for the ELS response.
7755 * @param rsp_len Length of ELS response, in bytes.
7756 * @param xri XRI for this exchange.
7757 * @param tag IO tag value.
7758 * @param cq_id The id of the completion queue where the WQE response is sent.
7759 * @param ox_id OX_ID of the exchange containing the request.
7760 * @param rnode Destination of the ELS response (that is, the remote node).
7761 * @param flags Optional attributes, including:
7762 * - SLI4_IO_CONTINUATION - IO is already active.
7763 * @param s_id S_ID used for special responses.
7765 * @return Returns 0 on success, or a non-zero value on failure.
7768 sli_xmit_els_rsp64_wqe(sli4_t *sli4, void *buf, size_t size, ocs_dma_t *rsp,
7769 uint32_t rsp_len, uint16_t xri, uint16_t tag, uint16_t cq_id,
7770 uint16_t ox_id, ocs_remote_node_t *rnode, uint32_t flags, uint32_t s_id)
7772 sli4_xmit_els_rsp64_wqe_t *els = buf;
7774 ocs_memset(buf, 0, size);
7776 if (sli4->config.sgl_pre_registered) {
7782 els->els_response_payload.bde_type = SLI4_BDE_TYPE_BDE_64;
7783 els->els_response_payload.buffer_length = rsp_len;
7784 els->els_response_payload.u.data.buffer_address_low = ocs_addr32_lo(rsp->phys);
7785 els->els_response_payload.u.data.buffer_address_high = ocs_addr32_hi(rsp->phys);
7787 els->els_response_payload_length = rsp_len;
7791 els->class = SLI4_ELS_REQUEST64_CLASS_3;
7793 els->command = SLI4_WQE_ELS_RSP64;
7795 els->request_tag = tag;
7799 els->iod = SLI4_ELS_REQUEST64_DIR_WRITE;
7803 if (flags & SLI4_IO_CONTINUATION) {
7807 if (rnode->attached) {
7808 els->ct = SLI4_ELS_REQUEST64_CONTEXT_RPI;
7809 els->context_tag = rnode->indicator;
7811 els->ct = SLI4_ELS_REQUEST64_CONTEXT_VPI;
7812 els->context_tag = rnode->sport->indicator;
7813 els->remote_id = rnode->fc_id & 0x00ffffff;
7814 els->temporary_rpi = rnode->indicator;
7815 if (UINT32_MAX != s_id) {
7817 els->s_id = s_id & 0x00ffffff;
7821 if (rnode->node_group) {
7823 els->remote_id = rnode->fc_id & 0x00ffffff;
7826 els->cmd_type = SLI4_ELS_REQUEST64_CMD_GEN;
7835 * @brief Process an asynchronous Link State event entry.
7838 * Parses Asynchronous Completion Queue Entry (ACQE),
7839 * creates an abstracted event, and calls registered callback functions.
7841 * @param sli4 SLI context.
7842 * @param acqe Pointer to the ACQE.
7844 * @return Returns 0 on success, or a non-zero value on failure.
7847 sli_fc_process_link_state(sli4_t *sli4, void *acqe)
7849 sli4_link_state_t *link_state = acqe;
7850 sli4_link_event_t event = { 0 };
7854 /* bail if there is no callback */
7858 if (SLI4_LINK_TYPE_ETHERNET == link_state->link_type) {
7859 event.topology = SLI_LINK_TOPO_NPORT;
7860 event.medium = SLI_LINK_MEDIUM_ETHERNET;
7862 /* TODO is this supported for anything other than FCoE? */
7863 ocs_log_test(sli4->os, "unsupported link type %#x\n",
7864 link_state->link_type);
7865 event.topology = SLI_LINK_TOPO_MAX;
7866 event.medium = SLI_LINK_MEDIUM_MAX;
7870 switch (link_state->port_link_status) {
7871 case SLI4_PORT_LINK_STATUS_PHYSICAL_DOWN:
7872 case SLI4_PORT_LINK_STATUS_LOGICAL_DOWN:
7873 event.status = SLI_LINK_STATUS_DOWN;
7875 case SLI4_PORT_LINK_STATUS_PHYSICAL_UP:
7876 case SLI4_PORT_LINK_STATUS_LOGICAL_UP:
7877 event.status = SLI_LINK_STATUS_UP;
7880 ocs_log_test(sli4->os, "unsupported link status %#x\n",
7881 link_state->port_link_status);
7882 event.status = SLI_LINK_STATUS_MAX;
7886 switch (link_state->port_speed) {
7900 event.speed = 10000;
7903 event.speed = 20000;
7906 event.speed = 25000;
7909 event.speed = 40000;
7912 event.speed = 100000;
7915 ocs_log_test(sli4->os, "unsupported port_speed %#x\n",
7916 link_state->port_speed);
7920 sli4->link(sli4->link_arg, (void *)&event);
7927 * @brief Process an asynchronous Link Attention event entry.
7930 * Parses Asynchronous Completion Queue Entry (ACQE),
7931 * creates an abstracted event, and calls the registered callback functions.
7933 * @param sli4 SLI context.
7934 * @param acqe Pointer to the ACQE.
7936 * @todo XXX all events return LINK_UP.
7938 * @return Returns 0 on success, or a non-zero value on failure.
7941 sli_fc_process_link_attention(sli4_t *sli4, void *acqe)
7943 sli4_link_attention_t *link_attn = acqe;
7944 sli4_link_event_t event = { 0 };
7946 ocs_log_debug(sli4->os, "link_number=%d attn_type=%#x topology=%#x port_speed=%#x "
7947 "port_fault=%#x shared_link_status=%#x logical_link_speed=%#x "
7948 "event_tag=%#x\n", link_attn->link_number, link_attn->attn_type,
7949 link_attn->topology, link_attn->port_speed, link_attn->port_fault,
7950 link_attn->shared_link_status, link_attn->logical_link_speed,
7951 link_attn->event_tag);
7957 event.medium = SLI_LINK_MEDIUM_FC;
7959 switch (link_attn->attn_type) {
7960 case SLI4_LINK_ATTN_TYPE_LINK_UP:
7961 event.status = SLI_LINK_STATUS_UP;
7963 case SLI4_LINK_ATTN_TYPE_LINK_DOWN:
7964 event.status = SLI_LINK_STATUS_DOWN;
7966 case SLI4_LINK_ATTN_TYPE_NO_HARD_ALPA:
7967 ocs_log_debug(sli4->os, "attn_type: no hard alpa\n");
7968 event.status = SLI_LINK_STATUS_NO_ALPA;
7971 ocs_log_test(sli4->os, "attn_type: unknown\n");
7975 switch (link_attn->event_type) {
7976 case SLI4_FC_EVENT_LINK_ATTENTION:
7978 case SLI4_FC_EVENT_SHARED_LINK_ATTENTION:
7979 ocs_log_debug(sli4->os, "event_type: FC shared link event \n");
7982 ocs_log_test(sli4->os, "event_type: unknown\n");
7986 switch (link_attn->topology) {
7987 case SLI4_LINK_ATTN_P2P:
7988 event.topology = SLI_LINK_TOPO_NPORT;
7990 case SLI4_LINK_ATTN_FC_AL:
7991 event.topology = SLI_LINK_TOPO_LOOP;
7993 case SLI4_LINK_ATTN_INTERNAL_LOOPBACK:
7994 ocs_log_debug(sli4->os, "topology Internal loopback\n");
7995 event.topology = SLI_LINK_TOPO_LOOPBACK_INTERNAL;
7997 case SLI4_LINK_ATTN_SERDES_LOOPBACK:
7998 ocs_log_debug(sli4->os, "topology serdes loopback\n");
7999 event.topology = SLI_LINK_TOPO_LOOPBACK_EXTERNAL;
8002 ocs_log_test(sli4->os, "topology: unknown\n");
8006 event.speed = link_attn->port_speed * 1000;
8008 sli4->link(sli4->link_arg, (void *)&event);
8015 * @brief Parse an FC/FCoE work queue CQ entry.
8017 * @param sli4 SLI context.
8018 * @param cq CQ to process.
8019 * @param cqe Pointer to the CQ entry.
8020 * @param etype CQ event type.
8021 * @param r_id Resource ID associated with this completion message (such as the IO tag).
8023 * @return Returns 0 on success, or a non-zero value on failure.
8026 sli_fc_cqe_parse(sli4_t *sli4, sli4_queue_t *cq, uint8_t *cqe, sli4_qentry_e *etype,
8029 uint8_t code = cqe[SLI4_CQE_CODE_OFFSET];
8033 case SLI4_CQE_CODE_WORK_REQUEST_COMPLETION:
8035 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8037 *etype = SLI_QENTRY_WQ;
8038 *r_id = wcqe->request_tag;
8041 /* Flag errors except for FCP_RSP_FAILURE */
8042 if (rc && (rc != SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE)) {
8044 ocs_log_test(sli4->os, "WCQE: status=%#x hw_status=%#x tag=%#x w1=%#x w2=%#x xb=%d\n",
8045 wcqe->status, wcqe->hw_status,
8046 wcqe->request_tag, wcqe->wqe_specific_1,
8047 wcqe->wqe_specific_2, wcqe->xb);
8048 ocs_log_test(sli4->os, " %08X %08X %08X %08X\n", ((uint32_t*) cqe)[0], ((uint32_t*) cqe)[1],
8049 ((uint32_t*) cqe)[2], ((uint32_t*) cqe)[3]);
8052 /* TODO: need to pass additional status back out of here as well
8053 * as status (could overload rc as status/addlstatus are only 8 bits each)
8058 case SLI4_CQE_CODE_RQ_ASYNC:
8060 sli4_fc_async_rcqe_t *rcqe = (void *)cqe;
8062 *etype = SLI_QENTRY_RQ;
8063 *r_id = rcqe->rq_id;
8067 case SLI4_CQE_CODE_RQ_ASYNC_V1:
8069 sli4_fc_async_rcqe_v1_t *rcqe = (void *)cqe;
8071 *etype = SLI_QENTRY_RQ;
8072 *r_id = rcqe->rq_id;
8076 case SLI4_CQE_CODE_OPTIMIZED_WRITE_CMD:
8078 sli4_fc_optimized_write_cmd_cqe_t *optcqe = (void *)cqe;
8080 *etype = SLI_QENTRY_OPT_WRITE_CMD;
8081 *r_id = optcqe->rq_id;
8082 rc = optcqe->status;
8085 case SLI4_CQE_CODE_OPTIMIZED_WRITE_DATA:
8087 sli4_fc_optimized_write_data_cqe_t *dcqe = (void *)cqe;
8089 *etype = SLI_QENTRY_OPT_WRITE_DATA;
8094 if (rc != SLI4_FC_WCQE_STATUS_SUCCESS) {
8095 ocs_log_test(sli4->os, "Optimized DATA CQE: status=%#x hw_status=%#x xri=%#x dpl=%#x w3=%#x xb=%d\n",
8096 dcqe->status, dcqe->hw_status,
8097 dcqe->xri, dcqe->total_data_placed,
8098 ((uint32_t*) cqe)[3], dcqe->xb);
8102 case SLI4_CQE_CODE_RQ_COALESCING:
8104 sli4_fc_coalescing_rcqe_t *rcqe = (void *)cqe;
8106 *etype = SLI_QENTRY_RQ;
8107 *r_id = rcqe->rq_id;
8111 case SLI4_CQE_CODE_XRI_ABORTED:
8113 sli4_fc_xri_aborted_cqe_t *xa = (void *)cqe;
8115 *etype = SLI_QENTRY_XABT;
8120 case SLI4_CQE_CODE_RELEASE_WQE: {
8121 sli4_fc_wqec_t *wqec = (void*) cqe;
8123 *etype = SLI_QENTRY_WQ_RELEASE;
8124 *r_id = wqec->wq_id;
8129 ocs_log_test(sli4->os, "CQE completion code %d not handled\n", code);
8130 *etype = SLI_QENTRY_MAX;
8139 * @brief Return the ELS/CT response length.
8141 * @param sli4 SLI context.
8142 * @param cqe Pointer to the CQ entry.
8144 * @return Returns the length, in bytes.
8147 sli_fc_response_length(sli4_t *sli4, uint8_t *cqe)
8149 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8151 return wcqe->wqe_specific_1;
8156 * @brief Return the FCP IO length.
8158 * @param sli4 SLI context.
8159 * @param cqe Pointer to the CQ entry.
8161 * @return Returns the length, in bytes.
8164 sli_fc_io_length(sli4_t *sli4, uint8_t *cqe)
8166 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8168 return wcqe->wqe_specific_1;
8173 * @brief Retrieve the D_ID from the completion.
8175 * @param sli4 SLI context.
8176 * @param cqe Pointer to the CQ entry.
8177 * @param d_id Pointer where the D_ID is written.
8179 * @return Returns 0 on success, or a non-zero value on failure.
8182 sli_fc_els_did(sli4_t *sli4, uint8_t *cqe, uint32_t *d_id)
8184 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8191 *d_id = wcqe->wqe_specific_2 & 0x00ffffff;
8197 sli_fc_ext_status(sli4_t *sli4, uint8_t *cqe)
8199 sli4_fc_wcqe_t *wcqe = (void *)cqe;
8202 switch (wcqe->status) {
8203 case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE:
8206 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
8207 case SLI4_FC_WCQE_STATUS_CMD_REJECT:
8210 case SLI4_FC_WCQE_STATUS_NPORT_RJT:
8211 case SLI4_FC_WCQE_STATUS_FABRIC_RJT:
8212 case SLI4_FC_WCQE_STATUS_NPORT_BSY:
8213 case SLI4_FC_WCQE_STATUS_FABRIC_BSY:
8214 case SLI4_FC_WCQE_STATUS_LS_RJT:
8217 case SLI4_FC_WCQE_STATUS_DI_ERROR:
8224 return wcqe->wqe_specific_2 & mask;
8229 * @brief Retrieve the RQ index from the completion.
8231 * @param sli4 SLI context.
8232 * @param cqe Pointer to the CQ entry.
8233 * @param rq_id Pointer where the rq_id is written.
8234 * @param index Pointer where the index is written.
8236 * @return Returns 0 on success, or a non-zero value on failure.
8239 sli_fc_rqe_rqid_and_index(sli4_t *sli4, uint8_t *cqe, uint16_t *rq_id, uint32_t *index)
8241 sli4_fc_async_rcqe_t *rcqe = (void *)cqe;
8242 sli4_fc_async_rcqe_v1_t *rcqe_v1 = (void *)cqe;
8247 *index = UINT32_MAX;
8249 code = cqe[SLI4_CQE_CODE_OFFSET];
8251 if (code == SLI4_CQE_CODE_RQ_ASYNC) {
8252 *rq_id = rcqe->rq_id;
8253 if (SLI4_FC_ASYNC_RQ_SUCCESS == rcqe->status) {
8254 *index = rcqe->rq_element_index;
8257 *index = rcqe->rq_element_index;
8259 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8260 rcqe->status, sli_fc_get_status_string(rcqe->status), rcqe->rq_id,
8261 rcqe->rq_element_index, rcqe->payload_data_placement_length, rcqe->sof_byte,
8262 rcqe->eof_byte, rcqe->header_data_placement_length);
8264 } else if (code == SLI4_CQE_CODE_RQ_ASYNC_V1) {
8265 *rq_id = rcqe_v1->rq_id;
8266 if (SLI4_FC_ASYNC_RQ_SUCCESS == rcqe_v1->status) {
8267 *index = rcqe_v1->rq_element_index;
8270 *index = rcqe_v1->rq_element_index;
8271 rc = rcqe_v1->status;
8272 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8273 rcqe_v1->status, sli_fc_get_status_string(rcqe_v1->status),
8274 rcqe_v1->rq_id, rcqe_v1->rq_element_index,
8275 rcqe_v1->payload_data_placement_length, rcqe_v1->sof_byte,
8276 rcqe_v1->eof_byte, rcqe_v1->header_data_placement_length);
8278 } else if (code == SLI4_CQE_CODE_OPTIMIZED_WRITE_CMD) {
8279 sli4_fc_optimized_write_cmd_cqe_t *optcqe = (void *)cqe;
8281 *rq_id = optcqe->rq_id;
8282 if (SLI4_FC_ASYNC_RQ_SUCCESS == optcqe->status) {
8283 *index = optcqe->rq_element_index;
8286 *index = optcqe->rq_element_index;
8287 rc = optcqe->status;
8288 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",
8289 optcqe->status, sli_fc_get_status_string(optcqe->status), optcqe->rq_id,
8290 optcqe->rq_element_index, optcqe->payload_data_placement_length,
8291 optcqe->header_data_placement_length, optcqe->oox, optcqe->agxr, optcqe->xri,
8294 } else if (code == SLI4_CQE_CODE_RQ_COALESCING) {
8295 sli4_fc_coalescing_rcqe_t *rcqe = (void *)cqe;
8297 *rq_id = rcqe->rq_id;
8298 if (SLI4_FC_COALESCE_RQ_SUCCESS == rcqe->status) {
8299 *index = rcqe->rq_element_index;
8302 *index = UINT32_MAX;
8305 ocs_log_test(sli4->os, "status=%02x (%s) rq_id=%d, index=%x rq_id=%#x sdpl=%x\n",
8306 rcqe->status, sli_fc_get_status_string(rcqe->status), rcqe->rq_id,
8307 rcqe->rq_element_index, rcqe->rq_id, rcqe->sequence_reporting_placement_length);
8310 *index = UINT32_MAX;
8314 ocs_log_debug(sli4->os, "status=%02x rq_id=%d, index=%x pdpl=%x sof=%02x eof=%02x hdpl=%x\n",
8315 rcqe->status, rcqe->rq_id, rcqe->rq_element_index, rcqe->payload_data_placement_length,
8316 rcqe->sof_byte, rcqe->eof_byte, rcqe->header_data_placement_length);
8324 * @brief Process an asynchronous FCoE event entry.
8327 * Parses Asynchronous Completion Queue Entry (ACQE),
8328 * creates an abstracted event, and calls the registered callback functions.
8330 * @param sli4 SLI context.
8331 * @param acqe Pointer to the ACQE.
8333 * @return Returns 0 on success, or a non-zero value on failure.
8336 sli_fc_process_fcoe(sli4_t *sli4, void *acqe)
8338 sli4_fcoe_fip_t *fcoe = acqe;
8339 sli4_fip_event_t event = { 0 };
8340 uint32_t mask = UINT32_MAX;
8342 ocs_log_debug(sli4->os, "ACQE FCoE FIP type=%02x count=%d tag=%#x\n",
8351 event.type = fcoe->event_type;
8352 event.index = UINT32_MAX;
8354 switch (fcoe->event_type) {
8355 case SLI4_FCOE_FIP_FCF_DISCOVERED:
8356 ocs_log_debug(sli4->os, "FCF Discovered index=%d\n", fcoe->event_information);
8358 case SLI4_FCOE_FIP_FCF_TABLE_FULL:
8359 ocs_log_debug(sli4->os, "FCF Table Full\n");
8362 case SLI4_FCOE_FIP_FCF_DEAD:
8363 ocs_log_debug(sli4->os, "FCF Dead/Gone index=%d\n", fcoe->event_information);
8365 case SLI4_FCOE_FIP_FCF_CLEAR_VLINK:
8367 ocs_log_debug(sli4->os, "Clear VLINK Received VPI=%#x\n", fcoe->event_information & mask);
8369 case SLI4_FCOE_FIP_FCF_MODIFIED:
8370 ocs_log_debug(sli4->os, "FCF Modified\n");
8373 ocs_log_test(sli4->os, "bad FCoE type %#x", fcoe->event_type);
8378 event.index = fcoe->event_information & mask;
8381 sli4->fip(sli4->fip_arg, &event);
8388 * @brief Allocate a receive queue.
8391 * Allocates DMA memory and configures the requested queue type.
8393 * @param sli4 SLI context.
8394 * @param q Pointer to the queue object for the header.
8395 * @param n_entries Number of entries to allocate.
8396 * @param buffer_size buffer size for the queue.
8397 * @param cq Associated CQ.
8398 * @param ulp The ULP to bind
8399 * @param is_hdr Used to validate the rq_id and set the type of queue
8401 * @return Returns 0 on success, or -1 on failure.
8404 sli_fc_rq_alloc(sli4_t *sli4, sli4_queue_t *q,
8405 uint32_t n_entries, uint32_t buffer_size,
8406 sli4_queue_t *cq, uint16_t ulp, uint8_t is_hdr)
8408 int32_t (*rq_create)(sli4_t *, void *, size_t, ocs_dma_t *, uint16_t, uint16_t, uint16_t);
8410 if ((sli4 == NULL) || (q == NULL)) {
8411 void *os = sli4 != NULL ? sli4->os : NULL;
8413 ocs_log_err(os, "bad parameter sli4=%p q=%p\n", sli4, q);
8417 if (__sli_queue_init(sli4, q, SLI_QTYPE_RQ, SLI4_FCOE_RQE_SIZE,
8418 n_entries, SLI_PAGE_SIZE)) {
8422 if (sli4->if_type == SLI4_IF_TYPE_BE3_SKH_PF) {
8423 rq_create = sli_cmd_fcoe_rq_create;
8425 rq_create = sli_cmd_fcoe_rq_create_v1;
8428 if (rq_create(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE, &q->dma,
8429 cq->id, ulp, buffer_size)) {
8430 if (__sli_create_queue(sli4, q)) {
8431 ocs_dma_free(sli4->os, &q->dma);
8434 if (is_hdr && q->id & 1) {
8435 ocs_log_test(sli4->os, "bad header RQ_ID %d\n", q->id);
8436 ocs_dma_free(sli4->os, &q->dma);
8438 } else if (!is_hdr && (q->id & 1) == 0) {
8439 ocs_log_test(sli4->os, "bad data RQ_ID %d\n", q->id);
8440 ocs_dma_free(sli4->os, &q->dma);
8446 q->u.flag.is_hdr = is_hdr;
8447 if (SLI4_IF_TYPE_BE3_SKH_PF == sli4->if_type) {
8448 q->u.flag.rq_batch = TRUE;
8456 * @brief Allocate a receive queue set.
8458 * @param sli4 SLI context.
8459 * @param num_rq_pairs to create
8460 * @param qs Pointers to the queue objects for both header and data.
8461 * Length of this arrays should be 2 * num_rq_pairs
8462 * @param base_cq_id. Assumes base_cq_id : (base_cq_id + num_rq_pairs) cqs as allotted.
8463 * @param n_entries number of entries in each RQ queue.
8464 * @param header_buffer_size
8465 * @param payload_buffer_size
8466 * @param ulp The ULP to bind
8468 * @return Returns 0 on success, or -1 on failure.
8471 sli_fc_rq_set_alloc(sli4_t *sli4, uint32_t num_rq_pairs,
8472 sli4_queue_t *qs[], uint32_t base_cq_id,
8473 uint32_t n_entries, uint32_t header_buffer_size,
8474 uint32_t payload_buffer_size, uint16_t ulp)
8476 uint32_t i, p, offset = 0;
8477 uint32_t payload_size, total_page_count = 0;
8480 sli4_res_common_create_queue_set_t *rsp = NULL;
8481 sli4_req_fcoe_rq_create_v2_t *req = NULL;
8483 for (i = 0; i < (num_rq_pairs * 2); i++) {
8484 if (__sli_queue_init(sli4, qs[i], SLI_QTYPE_RQ, SLI4_FCOE_RQE_SIZE,
8485 n_entries, SLI_PAGE_SIZE)) {
8490 total_page_count = sli_page_count(qs[0]->dma.size, SLI_PAGE_SIZE) * num_rq_pairs * 2;
8492 /* Payload length must accommodate both request and response */
8493 payload_size = max((sizeof(sli4_req_fcoe_rq_create_v1_t) + (8 * total_page_count)),
8494 sizeof(sli4_res_common_create_queue_set_t));
8496 if (ocs_dma_alloc(sli4->os, &dma, payload_size, SLI_PAGE_SIZE)) {
8497 ocs_log_err(sli4->os, "DMA allocation failed\n");
8500 ocs_memset(dma.virt, 0, payload_size);
8502 if (sli_cmd_sli_config(sli4, sli4->bmbx.virt, SLI4_BMBX_SIZE,
8503 payload_size, &dma) == -1) {
8506 req = (sli4_req_fcoe_rq_create_v2_t *)((uint8_t *)dma.virt);
8508 /* Fill Header fields */
8509 req->hdr.opcode = SLI4_OPC_FCOE_RQ_CREATE;
8510 req->hdr.subsystem = SLI4_SUBSYSTEM_FCFCOE;
8511 req->hdr.version = 2;
8512 req->hdr.request_length = sizeof(sli4_req_fcoe_rq_create_v2_t) - sizeof(sli4_req_hdr_t)
8513 + (8 * total_page_count);
8515 /* Fill Payload fields */
8517 req->num_pages = sli_page_count(qs[0]->dma.size, SLI_PAGE_SIZE);
8518 req->rqe_count = qs[0]->dma.size / SLI4_FCOE_RQE_SIZE;
8519 req->rqe_size = SLI4_FCOE_RQE_SIZE_8;
8520 req->page_size = SLI4_FCOE_RQ_PAGE_SIZE_4096;
8521 req->rq_count = num_rq_pairs * 2;
8522 req->base_cq_id = base_cq_id;
8523 req->hdr_buffer_size = header_buffer_size;
8524 req->payload_buffer_size = payload_buffer_size;
8526 for (i = 0; i < (num_rq_pairs * 2); i++) {
8527 for (p = 0, addr = qs[i]->dma.phys; p < req->num_pages; p++, addr += SLI_PAGE_SIZE) {
8528 req->page_physical_address[offset].low = ocs_addr32_lo(addr);
8529 req->page_physical_address[offset].high = ocs_addr32_hi(addr);
8534 if (sli_bmbx_command(sli4)){
8535 ocs_log_crit(sli4->os, "bootstrap mailbox write faild RQSet\n");
8540 rsp = (void *)((uint8_t *)dma.virt);
8541 if (rsp->hdr.status) {
8542 ocs_log_err(sli4->os, "bad create RQSet status=%#x addl=%#x\n",
8543 rsp->hdr.status, rsp->hdr.additional_status);
8546 for (i = 0; i < (num_rq_pairs * 2); i++) {
8547 qs[i]->id = i + rsp->q_id;
8548 if ((qs[i]->id & 1) == 0) {
8549 qs[i]->u.flag.is_hdr = TRUE;
8551 qs[i]->u.flag.is_hdr = FALSE;
8553 qs[i]->doorbell_offset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].off;
8554 qs[i]->doorbell_rset = regmap[SLI4_REG_FCOE_RQ_DOORBELL][sli4->if_type].rset;
8558 ocs_dma_free(sli4->os, &dma);
8563 for (i = 0; i < (num_rq_pairs * 2); i++) {
8564 if (qs[i]->dma.size) {
8565 ocs_dma_free(sli4->os, &qs[i]->dma);
8570 ocs_dma_free(sli4->os, &dma);
8578 * @brief Get the RPI resource requirements.
8580 * @param sli4 SLI context.
8581 * @param n_rpi Number of RPIs desired.
8583 * @return Returns the number of bytes needed. This value may be zero.
8586 sli_fc_get_rpi_requirements(sli4_t *sli4, uint32_t n_rpi)
8590 /* Check if header templates needed */
8591 if (sli4->config.hdr_template_req) {
8592 /* round up to a page */
8593 bytes = SLI_ROUND_PAGE(n_rpi * SLI4_FCOE_HDR_TEMPLATE_SIZE);
8601 * @brief Return a text string corresponding to a CQE status value
8603 * @param status Status value
8605 * @return Returns corresponding string, otherwise "unknown"
8608 sli_fc_get_status_string(uint32_t status)
8614 {SLI4_FC_WCQE_STATUS_SUCCESS, "SUCCESS"},
8615 {SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE, "FCP_RSP_FAILURE"},
8616 {SLI4_FC_WCQE_STATUS_REMOTE_STOP, "REMOTE_STOP"},
8617 {SLI4_FC_WCQE_STATUS_LOCAL_REJECT, "LOCAL_REJECT"},
8618 {SLI4_FC_WCQE_STATUS_NPORT_RJT, "NPORT_RJT"},
8619 {SLI4_FC_WCQE_STATUS_FABRIC_RJT, "FABRIC_RJT"},
8620 {SLI4_FC_WCQE_STATUS_NPORT_BSY, "NPORT_BSY"},
8621 {SLI4_FC_WCQE_STATUS_FABRIC_BSY, "FABRIC_BSY"},
8622 {SLI4_FC_WCQE_STATUS_LS_RJT, "LS_RJT"},
8623 {SLI4_FC_WCQE_STATUS_CMD_REJECT, "CMD_REJECT"},
8624 {SLI4_FC_WCQE_STATUS_FCP_TGT_LENCHECK, "FCP_TGT_LENCHECK"},
8625 {SLI4_FC_WCQE_STATUS_RQ_BUF_LEN_EXCEEDED, "BUF_LEN_EXCEEDED"},
8626 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_BUF_NEEDED, "RQ_INSUFF_BUF_NEEDED"},
8627 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_FRM_DISC, "RQ_INSUFF_FRM_DESC"},
8628 {SLI4_FC_WCQE_STATUS_RQ_DMA_FAILURE, "RQ_DMA_FAILURE"},
8629 {SLI4_FC_WCQE_STATUS_FCP_RSP_TRUNCATE, "FCP_RSP_TRUNCATE"},
8630 {SLI4_FC_WCQE_STATUS_DI_ERROR, "DI_ERROR"},
8631 {SLI4_FC_WCQE_STATUS_BA_RJT, "BA_RJT"},
8632 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_XRI_NEEDED, "RQ_INSUFF_XRI_NEEDED"},
8633 {SLI4_FC_WCQE_STATUS_RQ_INSUFF_XRI_DISC, "INSUFF_XRI_DISC"},
8634 {SLI4_FC_WCQE_STATUS_RX_ERROR_DETECT, "RX_ERROR_DETECT"},
8635 {SLI4_FC_WCQE_STATUS_RX_ABORT_REQUEST, "RX_ABORT_REQUEST"},
8639 for (i = 0; i < ARRAY_SIZE(lookup); i++) {
8640 if (status == lookup[i].code) {
8641 return lookup[i].label;