]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/ldpaa_eth/ldpaa_eth.c
Fix GCC format-security errors and convert sprintfs.
[u-boot] / drivers / net / ldpaa_eth / ldpaa_eth.c
index 3d4c0f52dfd7eb892c18c4ddcae4361fe25601d3..3857122bd05c1f057b3d5aec911b5f5de9cacd02 100644 (file)
@@ -24,6 +24,84 @@ static int init_phy(struct eth_device *dev)
        return 0;
 }
 
+#ifdef DEBUG
+static void ldpaa_eth_get_dpni_counter(void)
+{
+       int err = 0;
+       u64 value;
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_ING_FRAME,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_ING_FRAME failed\n");
+               return;
+       }
+       printf("DPNI_CNT_ING_FRAME=%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_ING_BYTE,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_ING_BYTE failed\n");
+               return;
+       }
+       printf("DPNI_CNT_ING_BYTE=%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_ING_FRAME_DROP ,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DROP failed\n");
+               return;
+       }
+       printf("DPNI_CNT_ING_FRAME_DROP =%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_ING_FRAME_DISCARD,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DISCARD failed\n");
+               return;
+       }
+       printf("DPNI_CNT_ING_FRAME_DISCARD=%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_EGR_FRAME,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_EGR_FRAME failed\n");
+               return;
+       }
+       printf("DPNI_CNT_EGR_FRAME=%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_EGR_BYTE ,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_EGR_BYTE failed\n");
+               return;
+       }
+       printf("DPNI_CNT_EGR_BYTE =%lld\n", value);
+
+       err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
+                    dflt_dpni->dpni_handle,
+                    DPNI_CNT_EGR_FRAME_DISCARD ,
+                    &value);
+       if (err < 0) {
+               printf("dpni_get_counter: DPNI_CNT_EGR_FRAME_DISCARD failed\n");
+               return;
+       }
+       printf("DPNI_CNT_EGR_FRAME_DISCARD =%lld\n", value);
+}
+#endif
+
 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
                         const struct dpaa_fd *fd)
 {
@@ -222,6 +300,9 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
        struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
        struct dpni_queue_attr rx_queue_attr;
        struct dpmac_link_state dpmac_link_state = { 0 };
+#ifdef DEBUG
+       struct dpni_link_state link_state;
+#endif
        int err;
 
        if (net_dev->state == ETH_STATE_ACTIVE)
@@ -295,6 +376,20 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
                printf("dpmac_set_link_state() failed\n");
                return err;
        }
+
+#ifdef DEBUG
+       err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                 dflt_dpni->dpni_handle, &link_state);
+       if (err < 0) {
+               printf("dpni_get_link_state() failed\n");
+               return err;
+       }
+
+       printf("link status: %d - ", link_state.up);
+       link_state.up == 0 ? printf("down\n") :
+       link_state.up == 1 ? printf("up\n") : printf("error state\n");
+#endif
+
        /* TODO: support multiple Rx flows */
        err = dpni_get_rx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
                               dflt_dpni->dpni_handle, 0, 0, &rx_queue_attr);
@@ -339,6 +434,10 @@ static void ldpaa_eth_stop(struct eth_device *net_dev)
            (net_dev->state == ETH_STATE_INIT))
                return;
 
+#ifdef DEBUG
+       ldpaa_eth_get_dpni_counter();
+#endif
+
        err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
                              dflt_dprc_handle, &dpmac_endpoint);
        if (err < 0)
@@ -401,7 +500,7 @@ static int ldpaa_bp_add_7(uint16_t bpid)
        struct qbman_release_desc rd;
 
        for (i = 0; i < 7; i++) {
-               addr = memalign(L1_CACHE_BYTES, LDPAA_ETH_RX_BUFFER_SIZE);
+               addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
                if (!addr) {
                        printf("addr allocation failed\n");
                        goto err_alloc;
@@ -523,12 +622,17 @@ static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
                .max_rate = 0
        };
 
+#ifdef DEBUG
+       struct dprc_endpoint dbg_endpoint;
+       int state = 0;
+#endif
+
        memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
-       sprintf(dpmac_endpoint.type, "dpmac");
+       strcpy(dpmac_endpoint.type, "dpmac");
        dpmac_endpoint.id = priv->dpmac_id;
 
        memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
-       sprintf(dpni_endpoint.type, "dpni");
+       strcpy(dpni_endpoint.type, "dpni");
        dpni_endpoint.id = dflt_dpni->dpni_id;
 
        err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
@@ -536,6 +640,25 @@ static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
                             &dpmac_endpoint,
                             &dpni_endpoint,
                             &dprc_connection_cfg);
+       if (err)
+               printf("dprc_connect() failed\n");
+
+#ifdef DEBUG
+       err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                   dflt_dprc_handle, &dpni_endpoint,
+                                   &dbg_endpoint, &state);
+       printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
+       printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
+       printf("%s, DPMAC State= %d\n", __func__, state);
+
+       memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
+       err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
+                                   dflt_dprc_handle, &dpmac_endpoint,
+                                   &dbg_endpoint, &state);
+       printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
+       printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
+       printf("%s, DPNI State= %d\n", __func__, state);
+#endif
        return err;
 }
 
@@ -562,10 +685,13 @@ static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
        /* Configure our buffers' layout */
        dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
                                   DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
-                                  DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
+                                  DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
+                                  DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
        dflt_dpni->buf_layout.pass_parser_result = true;
        dflt_dpni->buf_layout.pass_frame_status = true;
        dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
+       /* HW erratum mandates data alignment in multiples of 256 */
+       dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
        /* ...rx, ... */
        err = dpni_set_rx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
                                        dflt_dpni->dpni_handle,
@@ -576,7 +702,9 @@ static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
        }
 
        /* ... tx, ... */
-       dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PARSER_RESULT;
+       /* remove Rx-only options */
+       dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
+                                     DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
        err = dpni_set_tx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
                                        dflt_dpni->dpni_handle,
                                        &dflt_dpni->buf_layout);