/* config.h - Compile-time configuration for sbc_harness
 *
 * Copyright (C) 2024  Luke T. Shumaker <lukeshu@lukeshu.com>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#ifndef _CONFIG_H_
#define _CONFIG_H_

/* W5500 **********************************************************************/

/**
 * How many W5500 chips we have.
 */
#define CONFIG_W5500_NUM                1

/**
 * When allocating an arbitrary local port, what range should it be
 * allocated from?
 *
 * These are the default values of the Linux kernel's
 * net.ipv4.ip_local_port_range, so I figure they're probably good
 * values to use.
 */
#define CONFIG_W5500_LOCAL_PORT_MIN     32768
#define CONFIG_W5500_LOCAL_PORT_MAX     60999

#define CONFIG_W5500_DEBUG              1 /* bool */

#define CONFIG_W5500_LL_DEBUG           0 /* bool */

/* 9P *************************************************************************/

#define CONFIG_9P_PORT                564
/**
 * This max-msg-size is sized so that a Twrite message can return
 * 8KiB of data.
 *
 * This is the same as the default in Plan 9 4e's lib9p; it has the
 * comment that "24" is "ample room for Twrite/Rread header
 * (iounit)".  In fact, the Twrite header is only 23 bytes
 * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the
 * Rread header is even shorter at 11 bytes ("size[4] Rread[1]
 * tag[2] count[4]"), so "24" appears to be the size of the Twrite
 * header rounded up to a nice round number.
 *
 * In older versions of 9P ("9P1"), the max message size was
 * defined as part of the protocol specification rather than
 * negotiated.  In Plan 9 1e it was (8*1024)+128, and was bumped to
 * (8*1024)+160 in 2e and 3e.
 */
#define CONFIG_9P_MAX_MSG_SIZE        ((4*1024)+24)
/**
 * Maximum host-data-structure size.  A message may be larger in
 * unmarshaled-host-structures than marshaled-net-bytes due to (1)
 * struct padding, (2) nul-terminator byes for strings.
 */
#define CONFIG_9P_MAX_HOSTMSG_SIZE    CONFIG_9P_MAX_MSG_SIZE+16
#define CONFIG_9P_MAX_FIDS            16
#define CONFIG_9P_MAX_REQS            2
#define CONFIG_9P_MAX_ERR_SIZE        128 /* 128 is what Plan 9 4e uses */
#define CONFIG_9P_ENABLE_9P2000       1 /* bool */
#define CONFIG_9P_ENABLE_9P2000_u     1 /* bool */
#define CONFIG_9P_ENABLE_9P2000_e     0 /* bool */

/* DHCP ***********************************************************************/

#define CONFIG_DHCP_CAN_RECV_UNICAST_IP_WITHOUT_IP      0 /* bool */
#define CONFIG_DHCP_DEBUG                               1 /* bool */
#define CONFIG_DHCP_OPT_SIZE                            312 /* minimum of 312 */
#define CONFIG_DHCP_SELECTING_NS                        (5*NS_PER_S)

/* USB KEYBOARD ***************************************************************/

/**
 * Which USB port to use for the Root Hub.
 *
 * The RP2040 only has 1 port, so it's gotta be port #0.
 */
#define CONFIG_USB_COMMON_RHPORT               0

#define CONFIG_USB_COMMON_DEBUG                1 /* bool */

/* COROUTINE ******************************************************************/

#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE    (2*1024)
#define CONFIG_COROUTINE_NAME_LEN              16
#define CONFIG_COROUTINE_MEASURE_STACK         1 /* bool */
#define CONFIG_COROUTINE_PROTECT_STACK         1 /* bool */
#define CONFIG_COROUTINE_DEBUG                 0 /* bool */
#define CONFIG_COROUTINE_VALGRIND              0 /* bool */
#define CONFIG_COROUTINE_GDB                   1 /* bool */

#define _CONFIG_9P_NUM_SOCKS                   7
#define CONFIG_COROUTINE_NUM (                                               \
	1                                         /* usb_common         */ + \
        1                                         /* usb_keyboard       */ + \
	CONFIG_W5500_NUM                          /* irq handler        */ + \
        _CONFIG_9P_NUM_SOCKS                      /* 9P accept()+read() */ + \
        (CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS) /* 9P work+write()    */ )

#endif /* _CONFIG_H_ */