ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0215-dpaa2-eth-Add-support-for-new-link-state-APIs.patch
1 From 0153f87972bfa3ef33bf369b8e91142f7c2b284a Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Wed, 17 Oct 2018 20:14:24 +0300
4 Subject: [PATCH] dpaa2-eth: Add support for new link state APIs
5
6 Add v2 of dpni_get_link_state() and dpni_set_link_cfg() commands.
7 The new version allows setting & getting advertised and supported
8 link options.
9
10 Signed-off-by: Valentin Catalin Neacsu <valentin-catalin.neacsu@nxp.com>
11 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
12 ---
13  drivers/net/ethernet/freescale/dpaa2/dpni-cmd.h | 33 ++++++++++++
14  drivers/net/ethernet/freescale/dpaa2/dpni.c     | 70 +++++++++++++++++++++++++
15  drivers/net/ethernet/freescale/dpaa2/dpni.h     | 27 ++++++++++
16  3 files changed, 130 insertions(+)
17
18 --- a/drivers/net/ethernet/freescale/dpaa2/dpni-cmd.h
19 +++ b/drivers/net/ethernet/freescale/dpaa2/dpni-cmd.h
20 @@ -44,9 +44,11 @@
21  #define DPNI_CMDID_GET_QDID                            DPNI_CMD(0x210)
22  #define DPNI_CMDID_GET_TX_DATA_OFFSET                  DPNI_CMD(0x212)
23  #define DPNI_CMDID_GET_LINK_STATE                      DPNI_CMD(0x215)
24 +#define DPNI_CMDID_GET_LINK_STATE_V2                   DPNI_CMD_V2(0x215)
25  #define DPNI_CMDID_SET_MAX_FRAME_LENGTH                        DPNI_CMD(0x216)
26  #define DPNI_CMDID_GET_MAX_FRAME_LENGTH                        DPNI_CMD(0x217)
27  #define DPNI_CMDID_SET_LINK_CFG                                DPNI_CMD(0x21A)
28 +#define DPNI_CMDID_SET_LINK_CFG_V2                     DPNI_CMD_V2(0x21A)
29  #define DPNI_CMDID_SET_TX_SHAPING                      DPNI_CMD_V2(0x21B)
30  
31  #define DPNI_CMDID_SET_MCAST_PROMISC                   DPNI_CMD(0x220)
32 @@ -304,8 +306,22 @@ struct dpni_cmd_link_cfg {
33         __le64 options;
34  };
35  
36 +struct dpni_cmd_set_link_cfg_v2 {
37 +       /* cmd word 0 */
38 +       __le64 pad0;
39 +       /* cmd word 1 */
40 +       __le32 rate;
41 +       __le32 pad1;
42 +       /* cmd word 2 */
43 +       __le64 options;
44 +       /* cmd word 3 */
45 +       __le64 advertising;
46 +};
47 +
48  #define DPNI_LINK_STATE_SHIFT          0
49  #define DPNI_LINK_STATE_SIZE           1
50 +#define DPNI_STATE_VALID_SHIFT         1
51 +#define DPNI_STATE_VALID_SIZE          1
52  
53  struct dpni_rsp_get_link_state {
54         /* response word 0 */
55 @@ -320,6 +336,23 @@ struct dpni_rsp_get_link_state {
56         __le64 options;
57  };
58  
59 +struct dpni_rsp_get_link_state_v2 {
60 +       /* response word 0 */
61 +       __le32 pad0;
62 +       /* from LSB: up:1, valid:1 */
63 +       u8 flags;
64 +       u8 pad1[3];
65 +       /* response word 1 */
66 +       __le32 rate;
67 +       __le32 pad2;
68 +       /* response word 2 */
69 +       __le64 options;
70 +       /* cmd word 3 */
71 +       __le64 supported;
72 +       /* cmd word 4 */
73 +       __le64 advertising;
74 +};
75 +
76  #define DPNI_COUPLED_SHIFT     0
77  #define DPNI_COUPLED_SIZE      1
78  
79 --- a/drivers/net/ethernet/freescale/dpaa2/dpni.c
80 +++ b/drivers/net/ethernet/freescale/dpaa2/dpni.c
81 @@ -853,6 +853,36 @@ int dpni_set_link_cfg(struct fsl_mc_io *
82  }
83  
84  /**
85 + * dpni_set_link_cfg_v2() - set the link configuration.
86 + * @mc_io:      Pointer to MC portal's I/O object
87 + * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
88 + * @token:      Token of DPNI object
89 + * @cfg:        Link configuration
90 + *
91 + * Return:      '0' on Success; Error code otherwise.
92 + */
93 +int dpni_set_link_cfg_v2(struct fsl_mc_io *mc_io,
94 +                        u32 cmd_flags,
95 +                        u16 token,
96 +                        const struct dpni_link_cfg *cfg)
97 +{
98 +       struct fsl_mc_command cmd = { 0 };
99 +       struct dpni_cmd_set_link_cfg_v2 *cmd_params;
100 +
101 +       /* prepare command */
102 +       cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG_V2,
103 +                                         cmd_flags,
104 +                                         token);
105 +       cmd_params = (struct dpni_cmd_set_link_cfg_v2 *)cmd.params;
106 +       cmd_params->rate = cpu_to_le32(cfg->rate);
107 +       cmd_params->options = cpu_to_le64(cfg->options);
108 +       cmd_params->advertising = cpu_to_le64(cfg->advertising);
109 +
110 +       /* send command to mc*/
111 +       return mc_send_command(mc_io, &cmd);
112 +}
113 +
114 +/**
115   * dpni_get_link_cfg() - return the link configuration
116   * @mc_io:     Pointer to MC portal's I/O object
117   * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
118 @@ -924,6 +954,46 @@ int dpni_get_link_state(struct fsl_mc_io
119  
120         return 0;
121  }
122 +
123 +/**
124 + * dpni_get_link_state_v2() - Return the link state (either up or down)
125 + * @mc_io:      Pointer to MC portal's I/O object
126 + * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
127 + * @token:      Token of DPNI object
128 + * @state:      Returned link state;
129 + *
130 + * Return:      '0' on Success; Error code otherwise.
131 + */
132 +int dpni_get_link_state_v2(struct fsl_mc_io *mc_io,
133 +                          u32 cmd_flags,
134 +                          u16 token,
135 +                          struct dpni_link_state *state)
136 +{
137 +       struct fsl_mc_command cmd = { 0 };
138 +       struct dpni_rsp_get_link_state_v2 *rsp_params;
139 +       int err;
140 +
141 +       /* prepare command */
142 +       cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE_V2,
143 +                                         cmd_flags,
144 +                                         token);
145 +
146 +       /* send command to mc*/
147 +       err = mc_send_command(mc_io, &cmd);
148 +       if (err)
149 +               return err;
150 +
151 +       /* retrieve response parameters */
152 +       rsp_params = (struct dpni_rsp_get_link_state_v2 *)cmd.params;
153 +       state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
154 +       state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
155 +       state->rate = le32_to_cpu(rsp_params->rate);
156 +       state->options = le64_to_cpu(rsp_params->options);
157 +       state->supported = le64_to_cpu(rsp_params->supported);
158 +       state->advertising = le64_to_cpu(rsp_params->advertising);
159 +
160 +       return 0;
161 +}
162  
163  /**
164   * dpni_set_tx_shaping() - Set the transmit shaping
165 --- a/drivers/net/ethernet/freescale/dpaa2/dpni.h
166 +++ b/drivers/net/ethernet/freescale/dpaa2/dpni.h
167 @@ -522,6 +522,19 @@ int dpni_reset_statistics(struct fsl_mc_
168   * Enable priority flow control pause frames
169   */
170  #define DPNI_LINK_OPT_PFC_PAUSE                0x0000000000000010ULL
171 +/**
172 + * Advertised link speeds
173 + */
174 +#define DPNI_ADVERTISED_10BASET_FULL           0x0000000000000001ULL
175 +#define DPNI_ADVERTISED_100BASET_FULL          0x0000000000000002ULL
176 +#define DPNI_ADVERTISED_1000BASET_FULL         0x0000000000000004ULL
177 +#define DPNI_ADVERTISED_10000BASET_FULL        0x0000000000000010ULL
178 +#define DPNI_ADVERTISED_2500BASEX_FULL         0x0000000000000020ULL
179 +
180 +/**
181 + * Advertise auto-negotiation enabled
182 + */
183 +#define DPNI_ADVERTISED_AUTONEG                0x0000000000000008ULL
184  
185  /**
186   * struct - Structure representing DPNI link configuration
187 @@ -531,6 +544,7 @@ int dpni_reset_statistics(struct fsl_mc_
188  struct dpni_link_cfg {
189         u32 rate;
190         u64 options;
191 +       u64 advertising;
192  };
193  
194  int dpni_set_link_cfg(struct fsl_mc_io                 *mc_io,
195 @@ -538,6 +552,11 @@ int dpni_set_link_cfg(struct fsl_mc_io
196                       u16                               token,
197                       const struct dpni_link_cfg        *cfg);
198  
199 +int dpni_set_link_cfg_v2(struct fsl_mc_io              *mc_io,
200 +                        u32                            cmd_flags,
201 +                        u16                            token,
202 +                        const struct dpni_link_cfg     *cfg);
203 +
204  int dpni_get_link_cfg(struct fsl_mc_io                 *mc_io,
205                       u32                               cmd_flags,
206                       u16                               token,
207 @@ -552,7 +571,10 @@ int dpni_get_link_cfg(struct fsl_mc_io
208  struct dpni_link_state {
209         u32     rate;
210         u64     options;
211 +       u64     supported;
212 +       u64     advertising;
213         int     up;
214 +       int     state_valid;
215  };
216  
217  int dpni_get_link_state(struct fsl_mc_io       *mc_io,
218 @@ -560,6 +582,11 @@ int dpni_get_link_state(struct fsl_mc_io
219                         u16                     token,
220                         struct dpni_link_state  *state);
221  
222 +int dpni_get_link_state_v2(struct fsl_mc_io    *mc_io,
223 +                          u32                  cmd_flags,
224 +                          u16                  token,
225 +                          struct dpni_link_state       *state);
226 +
227  /**
228   * struct dpni_tx_shaping - Structure representing DPNI tx shaping configuration
229   * @rate_limit: rate in Mbps