1/*
2 * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 *    conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 *    of conditions and the following disclaimer in the documentation and/or other materials
13 *    provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 *    to endorse or promote products derived from this software without specific prior written
17 *    permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/* Ethernet driver structure */
33
34#ifndef _ETH_DRV_H_
35#define	_ETH_DRV_H_
36
37#define	USBPKG_NET_LWIP
38#ifdef USBPKG_NET_LWIP
39#include <los_mac.h>
40#endif
41
42#include "los_typedef.h"
43
44#ifdef __cplusplus
45#if __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48#endif /* __cplusplus */
49
50struct eth_drv_sg {
51	UINTPTR buf;
52	UINT32 len;
53};
54
55#define	CYGNUM_IO_ETH_DRIVERS_SG_LIST_SIZE 32
56#define	MAX_ETH_DRV_SG CYGNUM_IO_ETH_DRIVERS_SG_LIST_SIZE
57#define	MAX_ETH_MSG 1540
58
59extern const struct los_eth_funs eth_drv_funs_usb;
60
61struct eth_drv_sc{
62	struct eth_hwr_funs *funs;
63	void				*driver_private;
64	const char			*dev_name;
65	unsigned int		state;
66};
67
68typedef void (*eth_start)(struct los_eth_driver *sc, unsigned char *enaddr, int flags);
69typedef void (*eth_stop)(struct los_eth_driver *sc);
70typedef int (*eth_control)(struct los_eth_driver *sc, unsigned long key, void *data, int data_length);
71typedef int (*eth_can_send)(struct los_eth_driver *sc);
72typedef void (*eth_send)(struct los_eth_driver *sc, struct eth_drv_sg *sg_list,
73					    int sg_len, int total_len, UINTPTR key);
74typedef void (*eth_recv)(struct los_eth_driver *sc, struct eth_drv_sg *sg_list, int sg_len);
75typedef void (*eth_deliver)(struct los_eth_driver *sc);
76typedef void (*eth_poll)(struct los_eth_driver *sc);
77typedef int (*eth_int_vector)(struct los_eth_driver *sc);
78
79struct eth_hwr_funs {
80	/* Initialize hardware (including startup) */
81	eth_start start;
82	/* Shut down hardware */
83	eth_stop stop;
84	/* Device control (ioctl pass-thru) */
85	eth_control control;
86	/* Query - can a packet be sent? */
87	eth_can_send can_send;
88	/* Send a packet of data */
89	eth_send send;
90	/* Receive [unload] a packet of data */
91	eth_recv recv;
92	/*
93	 * Deliver data to/from device from/to stack memory space
94	 * (moves lots of memcpy()s out of DSRs into thread)
95	 */
96	eth_deliver deliver;
97	/* Poll for interrupts/device service */
98	eth_poll poll;
99	/* Get interrupt information from hardware driver */
100	eth_int_vector int_vector;
101	/* Logical driver interface */
102	const struct los_eth_funs *eth_drv, *eth_drv_old;
103};
104
105/* Control 'key's */
106#define	ETH_DRV_SET_MAC_ADDRESS 0x0100
107
108#ifdef __cplusplus
109#if __cplusplus
110}
111#endif /* __cplusplus */
112#endif /* __cplusplus */
113
114#endif /* _ETH_DRV_H_ */
115