2626 * - itf_data_alt if != 0 -> data xmit/recv are allowed (see spec)
2727 * - ep_in IN endpoints take data from the device intended to go in to the host (the device transmits)
2828 * - ep_out OUT endpoints send data out of the host to the device (the device receives)
29+ *
30+ * Linux host NCM driver
31+ * ---------------------
32+ * - https://github.com/torvalds/linux/blob/master/drivers/net/usb/cdc_ncm.c
33+ * - https://github.com/torvalds/linux/blob/master/include/linux/usb/cdc_ncm.h
34+ * - https://github.com/torvalds/linux/blob/master/include/uapi/linux/usb/cdc.h
2935 */
3036
3137#define DT_DRV_COMPAT zephyr_cdc_ncm_ethernet
4349#include <zephyr/logging/log.h>
4450LOG_MODULE_REGISTER (cdc_ncm , CONFIG_USBD_CDC_NCM_LOG_LEVEL );
4551
46- #include "usbd_cdc_ncm_local .h"
52+ #include "usbd_cdc_ncm_private .h"
4753
4854#define CDC_NCM_EP_MPS_INT 64
4955#define CDC_NCM_INTERVAL_DEFAULT 50000UL
@@ -63,11 +69,11 @@ enum {
6369
6470/*
6571 * Transfers through two endpoints proceed in a synchronous manner,
66- * with maximum block of CONFIG_CDC_NCM_XMT_NTB_MAX_SIZE .
72+ * with maximum block of CFG_CDC_NCM_XMT_NTB_MAX_SIZE .
6773 */
6874NET_BUF_POOL_FIXED_DEFINE (cdc_ncm_ep_pool ,
6975 DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) * 2 ,
70- CONFIG_CDC_NCM_XMT_NTB_MAX_SIZE ,
76+ MAX ( CFG_CDC_NCM_XMT_NTB_MAX_SIZE , CFG_CDC_NCM_RCV_NTB_MAX_SIZE ) ,
7177 sizeof (struct udc_buf_info ), NULL );
7278
7379
@@ -77,16 +83,16 @@ NET_BUF_POOL_FIXED_DEFINE(cdc_ncm_ep_pool,
7783static struct ntb_parameters_t ntb_parameters = {
7884 .wLength = sys_cpu_to_le16 (sizeof (struct ntb_parameters_t )),
7985 .bmNtbFormatsSupported = sys_cpu_to_le16 (0x01 ), // 16-bit NTB supported
80- .dwNtbInMaxSize = sys_cpu_to_le32 (CONFIG_CDC_NCM_XMT_NTB_MAX_SIZE ),
86+ .dwNtbInMaxSize = sys_cpu_to_le32 (CFG_CDC_NCM_XMT_NTB_MAX_SIZE ),
8187 .wNdbInDivisor = sys_cpu_to_le16 (4 ),
8288 .wNdbInPayloadRemainder = sys_cpu_to_le16 (0 ),
83- .wNdbInAlignment = sys_cpu_to_le16 (CONFIG_CDC_NCM_ALIGNMENT ),
89+ .wNdbInAlignment = sys_cpu_to_le16 (CFG_CDC_NCM_ALIGNMENT ),
8490 .wReserved = sys_cpu_to_le16 (0 ),
85- .dwNtbOutMaxSize = sys_cpu_to_le32 (CONFIG_CDC_NCM_RCV_NTB_MAX_SIZE ),
91+ .dwNtbOutMaxSize = sys_cpu_to_le32 (CFG_CDC_NCM_RCV_NTB_MAX_SIZE ),
8692 .wNdbOutDivisor = sys_cpu_to_le16 (4 ),
8793 .wNdbOutPayloadRemainder = sys_cpu_to_le16 (0 ),
88- .wNdbOutAlignment = sys_cpu_to_le16 (CONFIG_CDC_NCM_ALIGNMENT ),
89- .wNtbOutMaxDatagrams = sys_cpu_to_le16 (CONFIG_CDC_NCM_RCV_MAX_DATAGRAMS_PER_NTB )
94+ .wNdbOutAlignment = sys_cpu_to_le16 (CFG_CDC_NCM_ALIGNMENT ),
95+ .wNtbOutMaxDatagrams = sys_cpu_to_le16 (CFG_CDC_NCM_RCV_MAX_DATAGRAMS_PER_NTB )
9096};
9197
9298static struct ncm_notify_network_connection_t ncm_notify_connected = {
@@ -337,9 +343,9 @@ static bool _cdc_ncm_frame_ok(struct cdc_ncm_eth_data *data, struct net_buf *con
337343 LOG_ERR (" ill block length: %d > %d" , sys_le16_to_cpu (nth16 -> wBlockLength ), len );
338344 return false;
339345 }
340- if (sys_le16_to_cpu (nth16 -> wBlockLength ) > CONFIG_CDC_NCM_RCV_NTB_MAX_SIZE )
346+ if (sys_le16_to_cpu (nth16 -> wBlockLength ) > CFG_CDC_NCM_RCV_NTB_MAX_SIZE )
341347 {
342- LOG_ERR (" ill block length2: %d > %d" , sys_le16_to_cpu (nth16 -> wBlockLength ), CONFIG_CDC_NCM_RCV_NTB_MAX_SIZE );
348+ LOG_ERR (" ill block length2: %d > %d" , sys_le16_to_cpu (nth16 -> wBlockLength ), CFG_CDC_NCM_RCV_NTB_MAX_SIZE );
343349 return false;
344350 }
345351 if (sys_le16_to_cpu (nth16 -> wNdpIndex ) < sizeof (nth16 ) || sys_le16_to_cpu (nth16 -> wNdpIndex ) > len - (sizeof (struct ndp16_t ) + 2 * sizeof (struct ndp16_datagram_t )))
@@ -379,7 +385,7 @@ static bool _cdc_ncm_frame_ok(struct cdc_ncm_eth_data *data, struct net_buf *con
379385 int ndx = 0 ;
380386 uint16_t max_ndx = (uint16_t )((sys_le16_to_cpu (ndp16 -> wLength ) - sizeof (struct ndp16_t )) / sizeof (struct ndp16_datagram_t ));
381387
382- if (max_ndx > CONFIG_CDC_NCM_RCV_MAX_DATAGRAMS_PER_NTB + 1 )
388+ if (max_ndx > CFG_CDC_NCM_RCV_MAX_DATAGRAMS_PER_NTB + 1 )
383389 {
384390 // number of datagrams in NTB > 1
385391 LOG_ERR ("<<xyx %d (%d)" , max_ndx - 1 , sys_le16_to_cpu (ntb -> nth .wBlockLength ));
@@ -901,7 +907,7 @@ static int cdc_ncm_send(const struct device *dev, struct net_pkt *const pkt)
901907 ntb -> nth .wNdpIndex = sys_cpu_to_le16 (sizeof (struct nth16_t ));
902908
903909 ntb -> ndp .dwSignature = sys_cpu_to_le32 (NDP16_SIGNATURE_NCM0 );
904- ntb -> ndp .wLength = sys_cpu_to_le16 (sizeof (struct ndp16_t ) + (CONFIG_CDC_NCM_XMT_MAX_DATAGRAMS_PER_NTB + 1 )* sizeof (struct ndp16_datagram_t ));
910+ ntb -> ndp .wLength = sys_cpu_to_le16 (sizeof (struct ndp16_t ) + (CFG_CDC_NCM_XMT_MAX_DATAGRAMS_PER_NTB + 1 )* sizeof (struct ndp16_datagram_t ));
905911 ntb -> ndp .wNextNdpIndex = 0 ;
906912
907913 ntb -> ndp_datagram [0 ].wDatagramIndex = sys_cpu_to_le16 (sys_le16_to_cpu (ntb -> nth .wHeaderLength ) + sys_le16_to_cpu (ntb -> ndp .wLength ));
0 commit comments