2
2
*
3
3
* Copyright 2023 NXP
4
4
*
5
- * Inspiration from eth_mcux.c, which is :
5
+ * Inspiration from eth_mcux.c, which was :
6
6
* Copyright (c) 2016-2017 ARM Ltd
7
7
* Copyright (c) 2016 Linaro Ltd
8
8
* Copyright (c) 2018 Intel Corporation
19
19
#include <zephyr/logging/log.h>
20
20
LOG_MODULE_REGISTER (LOG_MODULE_NAME );
21
21
22
- /*
23
- ************
24
- * Includes *
25
- ************
26
- */
27
-
28
22
#include <zephyr/device.h>
29
23
#include <zephyr/sys/util.h>
30
24
#include <zephyr/kernel.h>
31
25
#include <zephyr/sys/__assert.h>
26
+
32
27
#include <zephyr/net/net_pkt.h>
33
28
#include <zephyr/net/net_if.h>
34
29
#include <zephyr/net/ethernet.h>
30
+ #include <zephyr/net/phy.h>
31
+ #include <zephyr/net/mii.h>
35
32
#include <ethernet/eth_stats.h>
33
+
36
34
#include <zephyr/drivers/pinctrl.h>
37
35
#include <zephyr/drivers/clock_control.h>
38
- #include <zephyr/drivers/ethernet/eth_nxp_enet.h>
39
- #include <zephyr/dt-bindings/ethernet/nxp_enet.h>
40
- #include <zephyr/net/phy.h>
41
- #include <zephyr/net/mii.h>
36
+
37
+ #ifdef CONFIG_PTP_CLOCK
42
38
#include <zephyr/drivers/ptp_clock.h>
43
- #if defined(CONFIG_NET_DSA )
44
- #include <zephyr/net/dsa.h>
45
39
#endif
46
40
47
- #include "fsl_enet.h"
41
+ #ifdef CONFIG_NET_DSA
42
+ #include <zephyr/net/dsa.h>
43
+ #endif
48
44
49
- /*
50
- ***********
51
- * Defines *
52
- ***********
53
- */
45
+ #include <zephyr/drivers/ethernet/eth_nxp_enet.h>
46
+ #include <zephyr/dt-bindings/ethernet/nxp_enet.h>
47
+ #include <fsl_enet.h>
54
48
55
49
#define RING_ID 0
56
50
57
- /*
58
- *********************
59
- * Driver Structures *
60
- *********************
61
- */
62
-
63
51
struct nxp_enet_mac_config {
64
52
ENET_Type * base ;
65
53
const struct device * clock_dev ;
@@ -92,31 +80,10 @@ struct nxp_enet_mac_data {
92
80
struct k_sem ptp_ts_sem ;
93
81
struct k_mutex * ptp_mutex ; /* created in PTP driver */
94
82
#endif
95
- /* TODO: FIXME. This Ethernet frame sized buffer is used for
96
- * interfacing with MCUX. How it works is that hardware uses
97
- * DMA scatter buffers to receive a frame, and then public
98
- * MCUX call gathers them into this buffer (there's no other
99
- * public interface). All this happens only for this driver
100
- * to scatter this buffer again into Zephyr fragment buffers.
101
- * This is not efficient, but proper resolution of this issue
102
- * depends on introduction of zero-copy networking support
103
- * in Zephyr, and adding needed interface to MCUX (or
104
- * bypassing it and writing a more complex driver working
105
- * directly with hardware).
106
- *
107
- * Note that we do not copy FCS into this buffer thus the
108
- * size is 1514 bytes.
109
- */
110
- uint8_t * tx_frame_buf ; /* Max MTU + ethernet header */
111
- uint8_t * rx_frame_buf ; /* Max MTU + ethernet header */
83
+ uint8_t * tx_frame_buf ;
84
+ uint8_t * rx_frame_buf ;
112
85
};
113
86
114
- /*
115
- ********************
116
- * Helper Functions *
117
- ********************
118
- */
119
-
120
87
static inline struct net_if * get_iface (struct nxp_enet_mac_data * data )
121
88
{
122
89
return data -> iface ;
@@ -187,12 +154,6 @@ static const struct device *eth_nxp_enet_get_ptp_clock(const struct device *dev)
187
154
}
188
155
#endif /* CONFIG_PTP_CLOCK */
189
156
190
- /*
191
- *********************************
192
- * Ethernet driver API Functions *
193
- *********************************
194
- */
195
-
196
157
static int eth_nxp_enet_tx (const struct device * dev , struct net_pkt * pkt )
197
158
{
198
159
const struct nxp_enet_mac_config * config = dev -> config ;
@@ -207,7 +168,6 @@ static int eth_nxp_enet_tx(const struct device *dev, struct net_pkt *pkt)
207
168
/* Enter critical section for TX frame buffer access */
208
169
k_mutex_lock (& data -> tx_frame_buf_mutex , K_FOREVER );
209
170
210
- /* Read network packet from upper layer into frame buffer */
211
171
ret = net_pkt_read (pkt , data -> tx_frame_buf , total_len );
212
172
if (ret ) {
213
173
k_sem_give (& data -> tx_buf_sem );
@@ -321,12 +281,6 @@ static int eth_nxp_enet_set_config(const struct device *dev,
321
281
return - ENOTSUP ;
322
282
}
323
283
324
- /*
325
- *****************************
326
- * Ethernet RX Functionality *
327
- *****************************
328
- */
329
-
330
284
static int eth_nxp_enet_rx (const struct device * dev )
331
285
{
332
286
const struct nxp_enet_mac_config * config = dev -> config ;
@@ -447,12 +401,6 @@ static void eth_nxp_enet_rx_thread(void *arg1, void *unused1, void *unused2)
447
401
}
448
402
}
449
403
450
- /*
451
- ****************************
452
- * PHY management functions *
453
- ****************************
454
- */
455
-
456
404
static int nxp_enet_phy_reset_and_configure (const struct device * phy )
457
405
{
458
406
int ret ;
@@ -511,12 +459,6 @@ static int nxp_enet_phy_init(const struct device *dev)
511
459
return ret ;
512
460
}
513
461
514
- /*
515
- ****************************
516
- * Callbacks and interrupts *
517
- ****************************
518
- */
519
-
520
462
void nxp_enet_driver_cb (const struct device * dev , enum nxp_enet_driver dev_type ,
521
463
enum nxp_enet_callback_reason event , void * data )
522
464
{
@@ -599,12 +541,6 @@ static void eth_nxp_enet_isr(const struct device *dev)
599
541
irq_unlock (irq_lock_key );
600
542
}
601
543
602
- /*
603
- ******************
604
- * Initialization *
605
- ******************
606
- */
607
-
608
544
static int eth_nxp_enet_init (const struct device * dev )
609
545
{
610
546
struct nxp_enet_mac_data * data = dev -> data ;
@@ -618,7 +554,6 @@ static int eth_nxp_enet_init(const struct device *dev)
618
554
return err ;
619
555
}
620
556
621
- /* Initialize kernel objects */
622
557
k_mutex_init (& data -> rx_frame_buf_mutex );
623
558
k_mutex_init (& data -> tx_frame_buf_mutex );
624
559
k_sem_init (& data -> rx_thread_sem , 0 , CONFIG_ETH_NXP_ENET_RX_BUFFERS );
@@ -640,14 +575,12 @@ static int eth_nxp_enet_init(const struct device *dev)
640
575
0 , K_NO_WAIT );
641
576
k_thread_name_set (& data -> rx_thread , "eth_nxp_enet_rx" );
642
577
643
- /* Get ENET IP module clock rate */
644
578
err = clock_control_get_rate (config -> clock_dev , config -> clock_subsys ,
645
579
& enet_module_clock_rate );
646
580
if (err ) {
647
581
return err ;
648
582
}
649
583
650
- /* Use HAL to set up MAC configuration */
651
584
ENET_GetDefaultConfig (& enet_config );
652
585
653
586
if (IS_ENABLED (CONFIG_NET_PROMISCUOUS_MODE )) {
@@ -930,9 +863,6 @@ static const struct ethernet_api api_funcs = {
930
863
931
864
DT_INST_FOREACH_STATUS_OKAY (NXP_ENET_MAC_INIT )
932
865
933
- /*
934
- * ENET module-level management
935
- */
936
866
#undef DT_DRV_COMPAT
937
867
#define DT_DRV_COMPAT nxp_enet
938
868
0 commit comments