1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
5 #include <linux/fsl/mc.h>
10 * dpmac_open() - Open a control session for the specified object.
11 * @mc_io: Pointer to MC portal's I/O object
12 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
13 * @dpmac_id: DPMAC unique ID
14 * @token: Returned token; use in subsequent API calls
16 * This function can be used to open a control session for an
17 * already created object; an object may have been declared in
18 * the DPL or by calling the dpmac_create function.
19 * This function returns a unique authentication token,
20 * associated with the specific object ID and the specific MC
21 * portal; this token must be used in all subsequent commands for
22 * this specific object
24 * Return: '0' on Success; Error code otherwise.
26 int dpmac_open(struct fsl_mc_io
*mc_io
,
31 struct dpmac_cmd_open
*cmd_params
;
32 struct fsl_mc_command cmd
= { 0 };
36 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_OPEN
,
39 cmd_params
= (struct dpmac_cmd_open
*)cmd
.params
;
40 cmd_params
->dpmac_id
= cpu_to_le32(dpmac_id
);
42 /* send command to mc*/
43 err
= mc_send_command(mc_io
, &cmd
);
47 /* retrieve response parameters */
48 *token
= mc_cmd_hdr_read_token(&cmd
);
54 * dpmac_close() - Close the control session of the object
55 * @mc_io: Pointer to MC portal's I/O object
56 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
57 * @token: Token of DPMAC object
59 * After this function is called, no further operations are
60 * allowed on the object without opening a new control session.
62 * Return: '0' on Success; Error code otherwise.
64 int dpmac_close(struct fsl_mc_io
*mc_io
,
68 struct fsl_mc_command cmd
= { 0 };
71 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_CLOSE
, cmd_flags
,
74 /* send command to mc*/
75 return mc_send_command(mc_io
, &cmd
);
79 * dpmac_get_attributes - Retrieve DPMAC attributes.
81 * @mc_io: Pointer to MC portal's I/O object
82 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
83 * @token: Token of DPMAC object
84 * @attr: Returned object's attributes
86 * Return: '0' on Success; Error code otherwise.
88 int dpmac_get_attributes(struct fsl_mc_io
*mc_io
,
91 struct dpmac_attr
*attr
)
93 struct dpmac_rsp_get_attributes
*rsp_params
;
94 struct fsl_mc_command cmd
= { 0 };
98 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR
,
102 /* send command to mc*/
103 err
= mc_send_command(mc_io
, &cmd
);
107 /* retrieve response parameters */
108 rsp_params
= (struct dpmac_rsp_get_attributes
*)cmd
.params
;
109 attr
->eth_if
= rsp_params
->eth_if
;
110 attr
->link_type
= rsp_params
->link_type
;
111 attr
->id
= le16_to_cpu(rsp_params
->id
);
112 attr
->max_rate
= le32_to_cpu(rsp_params
->max_rate
);
118 * dpmac_set_link_state() - Set the Ethernet link status
119 * @mc_io: Pointer to opaque I/O object
120 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
121 * @token: Token of DPMAC object
122 * @link_state: Link state configuration
124 * Return: '0' on Success; Error code otherwise.
126 int dpmac_set_link_state(struct fsl_mc_io
*mc_io
,
129 struct dpmac_link_state
*link_state
)
131 struct dpmac_cmd_set_link_state
*cmd_params
;
132 struct fsl_mc_command cmd
= { 0 };
134 /* prepare command */
135 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE
,
138 cmd_params
= (struct dpmac_cmd_set_link_state
*)cmd
.params
;
139 cmd_params
->options
= cpu_to_le64(link_state
->options
);
140 cmd_params
->rate
= cpu_to_le32(link_state
->rate
);
141 dpmac_set_field(cmd_params
->state
, STATE
, link_state
->up
);
142 dpmac_set_field(cmd_params
->state
, STATE_VALID
,
143 link_state
->state_valid
);
144 cmd_params
->supported
= cpu_to_le64(link_state
->supported
);
145 cmd_params
->advertising
= cpu_to_le64(link_state
->advertising
);
147 /* send command to mc*/
148 return mc_send_command(mc_io
, &cmd
);
152 * dpmac_get_counter() - Read a specific DPMAC counter
153 * @mc_io: Pointer to opaque I/O object
154 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
155 * @token: Token of DPMAC object
156 * @id: The requested counter ID
157 * @value: Returned counter value
159 * Return: The requested counter; '0' otherwise.
161 int dpmac_get_counter(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
162 enum dpmac_counter_id id
, u64
*value
)
164 struct dpmac_cmd_get_counter
*dpmac_cmd
;
165 struct dpmac_rsp_get_counter
*dpmac_rsp
;
166 struct fsl_mc_command cmd
= { 0 };
169 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER
,
172 dpmac_cmd
= (struct dpmac_cmd_get_counter
*)cmd
.params
;
175 err
= mc_send_command(mc_io
, &cmd
);
179 dpmac_rsp
= (struct dpmac_rsp_get_counter
*)cmd
.params
;
180 *value
= le64_to_cpu(dpmac_rsp
->counter
);