1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License as published by the 6 * Free Software Foundation; either version 2 of the License, or (at your 7 * option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Description: Hieth ETH operation header file 18 */ 19 20 21 #ifndef __HIETH_H__ 22 #define __HIETH_H__ 23 24 #include <config.h> 25 #include <common.h> 26 #include <command.h> 27 28 #include <linux/list.h> 29 #include <asm/io.h> 30 31 #include <malloc.h> /* malloc, free, realloc */ 32 33 #include <net.h> 34 #include <miiphy.h> 35 #include <asm/arch/platform.h> 36 37 #define OSDRV_MODULE_VERSION_STRING "Hisilicon ETH net controler" 38 39 #ifndef bit 40 #define bit(nr) (1UL << (nr)) 41 #endif 42 #define mdelay(n) udelay((n)*1000) 43 /* *********************************************************** 44 * 45 * Global varibles and defintions 46 * 47 * *********************************************************** 48 */ 49 50 /* configuerable values */ 51 52 #ifdef HIETH_RX_QUEUE_MULTI_DESC 53 #define HIETH_HW_DESC_DEPTH 72 54 #endif 55 56 #define ETH_MDIO_FRQDIV 2 57 58 /* mdiobus device name, such as platform device name */ 59 #define HIETH_MDIOBUS_NAME "hieth_mdiobus" 60 61 /* eth device name, such as platform device name */ 62 #define HIETH_SFV300_NAME "hieth_sfv300" 63 #define MAX_PHY_NAME_LEN 16 64 #define HIETH_MAX_QUEUE_DEPTH 64 65 #ifdef HIETH_RX_QUEUE_MULTI_DESC 66 #define HIETH_HW_RXQ_DEPTH 52 /* uboot */ 67 #else 68 #define HIETH_HW_RXQ_DEPTH 1 /* uboot */ 69 #endif 70 #define HIETH_HW_TXQ_DEPTH 1 /* uboot */ 71 72 #define HIETH_MAX_FRAME_SIZE PKTSIZE_ALIGN /* 1536 */ 73 74 #define HIETH_TRACE_ETH 2 75 #define HIETH_TRACE_MDIO 4 76 #define HIETH_TRACE_DRV 7 77 #define HIETH_TRACE_LEVEL 8 78 79 /* Error number */ 80 #define HIETH_E_QUEUE (-1) 81 #define HIETH_E_BUSY (-2) 82 #define HIETH_E_FULL (-3) 83 #define HIETH_E_EMPTY (-4) 84 85 struct hieth_frame_desc { 86 unsigned long frm_addr; /* required by the controler */ 87 unsigned int frm_len : 11; /* required by the controler */ 88 }; 89 90 #define hieth_trace_fd(level, fd) hieth_trace(level, \ 91 #fd "<%p>={ .frm_addr=%08lx, .frm_len=%d}", \ 92 &(fd), (fd).frm_addr, (fd).frm_len) 93 94 /* port */ 95 #define UP_PORT 0 96 #define DOWN_PORT 1 97 #define MAX_PORT 2 98 99 enum if_mode { 100 INTERFACE_MODE_MII, 101 INTERFACE_MODE_RMII 102 }; 103 104 struct hieth_netdev_local { 105 unsigned long iobase_phys; /* physical io addr */ 106 int port : 1; /* 0 => up port, 1 => down port */ 107 108 #ifdef HIETH_RX_QUEUE_MULTI_DESC 109 int desc_hw_offset; /* the offset where we feed hw */ 110 int desc_rec_offset; /* the offset where we receve the package */ 111 struct hieth_frame_desc *hieth_desc_head; 112 #endif 113 114 u32 link_stat; 115 char *mii_name; 116 unsigned char phy_addr; 117 enum if_mode phy_intf; 118 119 /* mdio_bus freq-div, 1 for 1/100, 0 for 1/50 */ 120 u32 mdio_frqdiv; 121 }; 122 123 /* *********************************************************** 124 * 125 * Only for internal used! 126 * 127 * *********************************************************** 128 */ 129 130 /* read/write IO */ 131 132 #define _readl(c) ({ u32 __v = le32_to_cpu(__raw_readl(c)); __v; }) 133 #define _writel(v, c) __raw_writel(cpu_to_le32(v), c) 134 135 #define mk_bits(shift, nbits) ((((shift) & 0x1F) << 16) | ((nbits) & 0x1F)) 136 137 u32 hieth_readl(struct hieth_netdev_local *ld, u32 ofs); 138 void hieth_writel(struct hieth_netdev_local *ld, u32 v, u32 ofs); 139 u32 hieth_readl_bits(struct hieth_netdev_local *ld, u32 ofs, u32 bits_desc); 140 void hieth_writel_bits(struct hieth_netdev_local *ld, u32 v, u32 ofs, u32 bits_desc); 141 142 void hieth_trace(int level, const char *fmt, ...); 143 void hieth_error(const char *fmt, ...); 144 void hieth_assert(bool cond); 145 146 #define local_lock_init(ld) 147 #define local_lock_exit(ld) 148 #define local_lock(ld) 149 #define local_unlock(ld) 150 151 #define ud_reg_name(name) ((ld->port == UP_PORT) ? U_##name : D_##name) 152 #define ud_bit_name(name) ((ld->port == UP_PORT) ? name##_U : name##_D) 153 154 #endif 155