]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/drivers/bus/fslmc/mc/fsl_mc_cmd.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / drivers / bus / fslmc / mc / fsl_mc_cmd.h
CommitLineData
9f95a23c 1/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
11fdf7f2
TL
2 *
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
9f95a23c 4 * Copyright 2016-2017 NXP
11fdf7f2 5 *
11fdf7f2
TL
6 */
7#ifndef __FSL_MC_CMD_H
8#define __FSL_MC_CMD_H
9
9f95a23c
TL
10#include <rte_byteorder.h>
11#include <stdint.h>
11fdf7f2 12
9f95a23c 13#define MC_CMD_NUM_OF_PARAMS 7
11fdf7f2 14
9f95a23c
TL
15#define phys_addr_t uint64_t
16
17#define u64 uint64_t
18#define u32 uint32_t
19#define u16 uint16_t
20#define u8 uint8_t
21
22#define cpu_to_le64 rte_cpu_to_le_64
23#define cpu_to_le32 rte_cpu_to_le_32
24#define cpu_to_le16 rte_cpu_to_le_16
25
26#define le64_to_cpu rte_le_to_cpu_64
27#define le32_to_cpu rte_le_to_cpu_32
28#define le16_to_cpu rte_le_to_cpu_16
29
30#define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
31#define GENMASK(h, l) \
32 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
33
34struct mc_cmd_header {
35 union {
36 struct {
37 uint8_t src_id;
38 uint8_t flags_hw;
39 uint8_t status;
40 uint8_t flags_sw;
41 uint16_t token;
42 uint16_t cmd_id;
43 };
44 uint32_t word[2];
45 };
46};
11fdf7f2
TL
47
48struct mc_command {
49 uint64_t header;
50 uint64_t params[MC_CMD_NUM_OF_PARAMS];
51};
52
9f95a23c
TL
53struct mc_rsp_create {
54 uint32_t object_id;
11fdf7f2
TL
55};
56
9f95a23c
TL
57enum mc_cmd_status {
58 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
59 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
60 MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
61 MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
62 MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
63 MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
64 MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
65 MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
66 MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
67 MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
68 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
69 MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
70};
11fdf7f2 71
9f95a23c
TL
72/*
73 * MC command flags
11fdf7f2 74 */
11fdf7f2 75
9f95a23c
TL
76/* High priority flag */
77#define MC_CMD_FLAG_PRI 0x80
78/* Command completion flag */
79#define MC_CMD_FLAG_INTR_DIS 0x01
80
11fdf7f2
TL
81#define MC_CMD_HDR_FLAGS_MASK 0xFF00FF00
82
9f95a23c 83int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
11fdf7f2 84
9f95a23c
TL
85static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
86 uint32_t cmd_flags,
87 uint16_t token)
88{
89 uint64_t header = 0;
90 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
11fdf7f2 91
9f95a23c
TL
92 hdr->cmd_id = cpu_to_le16(cmd_id);
93 hdr->token = cpu_to_le16(token);
94 hdr->status = MC_CMD_STATUS_READY;
95 hdr->word[0] |= cpu_to_le32(cmd_flags & MC_CMD_HDR_FLAGS_MASK);
11fdf7f2 96
9f95a23c
TL
97 return header;
98}
11fdf7f2 99
9f95a23c
TL
100static inline uint16_t mc_cmd_hdr_read_token(struct mc_command *cmd)
101{
102 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
103 uint16_t token = le16_to_cpu(hdr->token);
11fdf7f2 104
9f95a23c
TL
105 return token;
106}
11fdf7f2 107
9f95a23c
TL
108static inline uint32_t mc_cmd_read_object_id(struct mc_command *cmd)
109{
110 struct mc_rsp_create *rsp_params;
11fdf7f2 111
9f95a23c
TL
112 rsp_params = (struct mc_rsp_create *)cmd->params;
113 return le32_to_cpu(rsp_params->object_id);
114}
11fdf7f2 115
9f95a23c 116static inline enum mc_cmd_status mc_cmd_read_status(struct mc_command *cmd)
11fdf7f2 117{
9f95a23c
TL
118 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
119 uint8_t status = hdr->status;
11fdf7f2 120
9f95a23c 121 return (enum mc_cmd_status)status;
11fdf7f2
TL
122}
123
124/**
125 * mc_write_command - writes a command to a Management Complex (MC) portal
126 *
127 * @portal: pointer to an MC portal
128 * @cmd: pointer to a filled command
129 */
130static inline void mc_write_command(struct mc_command __iomem *portal,
131 struct mc_command *cmd)
132{
9f95a23c 133 struct mc_cmd_header *cmd_header = (struct mc_cmd_header *)&cmd->header;
11fdf7f2 134 char *header = (char *)&portal->header;
9f95a23c 135 int i;
11fdf7f2
TL
136
137 /* copy command parameters into the portal */
138 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
139 iowrite64(cmd->params[i], &portal->params[i]);
140
141 /* submit the command by writing the header */
9f95a23c
TL
142 iowrite32(le32_to_cpu(cmd_header->word[1]), (((uint32_t *)header) + 1));
143 iowrite32(le32_to_cpu(cmd_header->word[0]), (uint32_t *)header);
11fdf7f2
TL
144}
145
146/**
147 * mc_read_response - reads the response for the last MC command from a
148 * Management Complex (MC) portal
149 *
150 * @portal: pointer to an MC portal
151 * @resp: pointer to command response buffer
152 *
153 * Returns MC_CMD_STATUS_OK on Success; Error code otherwise.
154 */
155static inline enum mc_cmd_status mc_read_response(
156 struct mc_command __iomem *portal,
157 struct mc_command *resp)
158{
159 int i;
160 enum mc_cmd_status status;
161
162 /* Copy command response header from MC portal: */
163 resp->header = ioread64(&portal->header);
9f95a23c 164 status = mc_cmd_read_status(resp);
11fdf7f2
TL
165 if (status != MC_CMD_STATUS_OK)
166 return status;
167
168 /* Copy command response data from MC portal: */
169 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
170 resp->params[i] = ioread64(&portal->params[i]);
171
172 return status;
173}
174
175#endif /* __FSL_MC_CMD_H */