| 1 |
/* |
|---|
| 2 |
* ar8216.h: AR8216 switch driver |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> |
|---|
| 5 |
* |
|---|
| 6 |
* This program is free software; you can redistribute it and/or |
|---|
| 7 |
* modify it under the terms of the GNU General Public License |
|---|
| 8 |
* as published by the Free Software Foundation; either version 2 |
|---|
| 9 |
* of the License, or (at your option) any later version. |
|---|
| 10 |
* |
|---|
| 11 |
* This program is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
* GNU General Public License for more details. |
|---|
| 15 |
*/ |
|---|
| 16 |
|
|---|
| 17 |
#ifndef __AR8216_H |
|---|
| 18 |
#define __AR8216_H |
|---|
| 19 |
|
|---|
| 20 |
#define BITS(_s, _n) (((1UL << (_n)) - 1) << _s) |
|---|
| 21 |
#define BIT(nr) (1UL << (nr)) |
|---|
| 22 |
|
|---|
| 23 |
#define AR8216_PORT_CPU 0 |
|---|
| 24 |
#define AR8216_NUM_PORTS 6 |
|---|
| 25 |
#define AR8216_NUM_VLANS 16 |
|---|
| 26 |
|
|---|
| 27 |
#define AR8216_REG_CTRL 0x0000 |
|---|
| 28 |
#define AR8216_CTRL_RESET BIT(31) |
|---|
| 29 |
|
|---|
| 30 |
#define AR8216_REG_GLOBAL_CTRL 0x0030 |
|---|
| 31 |
#define AR8216_GCTRL_MTU BITS(0, 10) |
|---|
| 32 |
|
|---|
| 33 |
#define AR8216_REG_VTU 0x0040 |
|---|
| 34 |
#define AR8216_VTU_OP BITS(0, 3) |
|---|
| 35 |
#define AR8216_VTU_OP_NOOP 0x0 |
|---|
| 36 |
#define AR8216_VTU_OP_FLUSH 0x1 |
|---|
| 37 |
#define AR8216_VTU_OP_LOAD 0x2 |
|---|
| 38 |
#define AR8216_VTU_OP_PURGE 0x3 |
|---|
| 39 |
#define AR8216_VTU_OP_REMOVE_PORT 0x4 |
|---|
| 40 |
#define AR8216_VTU_ACTIVE BIT(3) |
|---|
| 41 |
#define AR8216_VTU_FULL BIT(4) |
|---|
| 42 |
#define AR8216_VTU_PORT BITS(8, 4) |
|---|
| 43 |
#define AR8216_VTU_PORT_S 8 |
|---|
| 44 |
#define AR8216_VTU_VID BITS(16, 12) |
|---|
| 45 |
#define AR8216_VTU_VID_S 16 |
|---|
| 46 |
#define AR8216_VTU_PRIO BITS(28, 3) |
|---|
| 47 |
#define AR8216_VTU_PRIO_S 28 |
|---|
| 48 |
#define AR8216_VTU_PRIO_EN BIT(31) |
|---|
| 49 |
|
|---|
| 50 |
#define AR8216_REG_VTU_DATA 0x0044 |
|---|
| 51 |
#define AR8216_VTUDATA_MEMBER BITS(0, 10) |
|---|
| 52 |
#define AR8216_VTUDATA_VALID BIT(11) |
|---|
| 53 |
|
|---|
| 54 |
#define AR8216_REG_ATU 0x0050 |
|---|
| 55 |
#define AR8216_ATU_OP BITS(0, 3) |
|---|
| 56 |
#define AR8216_ATU_OP_NOOP 0x0 |
|---|
| 57 |
#define AR8216_ATU_OP_FLUSH 0x1 |
|---|
| 58 |
#define AR8216_ATU_OP_LOAD 0x2 |
|---|
| 59 |
#define AR8216_ATU_OP_PURGE 0x3 |
|---|
| 60 |
#define AR8216_ATU_OP_FLUSH_LOCKED 0x4 |
|---|
| 61 |
#define AR8216_ATU_OP_FLUSH_UNICAST 0x5 |
|---|
| 62 |
#define AR8216_ATU_OP_GET_NEXT 0x6 |
|---|
| 63 |
#define AR8216_ATU_ACTIVE BIT(3) |
|---|
| 64 |
#define AR8216_ATU_PORT_NUM BITS(8, 4) |
|---|
| 65 |
#define AR8216_ATU_FULL_VIO BIT(12) |
|---|
| 66 |
#define AR8216_ATU_ADDR4 BIT(16, 8) |
|---|
| 67 |
#define AR8216_ATU_ADDR5 BIT(24, 8) |
|---|
| 68 |
|
|---|
| 69 |
#define AR8216_REG_ATU_DATA 0x0054 |
|---|
| 70 |
#define AR8216_ATU_ADDR3 BIT(0, 8) |
|---|
| 71 |
#define AR8216_ATU_ADDR2 BIT(8, 8) |
|---|
| 72 |
#define AR8216_ATU_ADDR1 BIT(16, 8) |
|---|
| 73 |
#define AR8216_ATU_ADDR0 BIT(24, 8) |
|---|
| 74 |
|
|---|
| 75 |
#define AR8216_PORT_OFFSET(_i) (0x0100 * (i + 1)) |
|---|
| 76 |
#define AR8216_REG_PORT_STATUS(_i) (AR8216_PORT_OFFSET(_i) + 0x0000) |
|---|
| 77 |
#define AR8216_PORT_STATUS_SPEED BIT(0) |
|---|
| 78 |
#define AR8216_PORT_STATUS_SPEED_ERR BIT(1) |
|---|
| 79 |
#define AR8216_PORT_STATUS_TXMAC BIT(2) |
|---|
| 80 |
#define AR8216_PORT_STATUS_RXMAC BIT(3) |
|---|
| 81 |
#define AR8216_PORT_STATUS_TXFLOW BIT(4) |
|---|
| 82 |
#define AR8216_PORT_STATUS_RXFLOW BIT(5) |
|---|
| 83 |
#define AR8216_PORT_STATUS_DUPLEX BIT(6) |
|---|
| 84 |
#define AR8216_PORT_STATUS_LINK_UP BIT(8) |
|---|
| 85 |
#define AR8216_PORT_STATUS_LINK_AUTO BIT(9) |
|---|
| 86 |
#define AR8216_PORT_STATUS_LINK_PAUSE BIT(10) |
|---|
| 87 |
|
|---|
| 88 |
#define AR8216_REG_PORT_CTRL(_i) (AR8216_PORT_OFFSET(_i) + 0x0004) |
|---|
| 89 |
|
|---|
| 90 |
/* port forwarding state */ |
|---|
| 91 |
#define AR8216_PORT_CTRL_STATE BITS(0, 3) |
|---|
| 92 |
#define AR8216_PORT_CTRL_STATE_S 0 |
|---|
| 93 |
|
|---|
| 94 |
#define AR8216_PORT_CTRL_LEARN_LOCK BIT(7) |
|---|
| 95 |
|
|---|
| 96 |
/* egress 802.1q mode */ |
|---|
| 97 |
#define AR8216_PORT_CTRL_VLAN_MODE BITS(8, 2) |
|---|
| 98 |
#define AR8216_PORT_CTRL_VLAN_MODE_S 8 |
|---|
| 99 |
|
|---|
| 100 |
#define AR8216_PORT_CTRL_IGMP_SNOOP BIT(10) |
|---|
| 101 |
#define AR8216_PORT_CTRL_HEADER BIT(11) |
|---|
| 102 |
#define AR8216_PORT_CTRL_MAC_LOOP BIT(12) |
|---|
| 103 |
#define AR8216_PORT_CTRL_SINGLE_VLAN BIT(13) |
|---|
| 104 |
#define AR8216_PORT_CTRL_LEARN BIT(14) |
|---|
| 105 |
#define AR8216_PORT_CTRL_MIRROR_TX BIT(16) |
|---|
| 106 |
#define AR8216_PORT_CTRL_MIRROR_RX BIT(17) |
|---|
| 107 |
|
|---|
| 108 |
#define AR8216_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET(_i) + 0x0008) |
|---|
| 109 |
|
|---|
| 110 |
#define AR8216_PORT_VLAN_DEFAULT_ID BITS(0, 12) |
|---|
| 111 |
#define AR8216_PORT_VLAN_DEFAULT_ID_S 0 |
|---|
| 112 |
|
|---|
| 113 |
#define AR8216_PORT_VLAN_DEST_PORTS BITS(16, 9) |
|---|
| 114 |
#define AR8216_PORT_VLAN_DEST_PORTS_S 16 |
|---|
| 115 |
|
|---|
| 116 |
/* bit0 added to the priority field of egress frames */ |
|---|
| 117 |
#define AR8216_PORT_VLAN_TX_PRIO BIT(27) |
|---|
| 118 |
|
|---|
| 119 |
/* port default priority */ |
|---|
| 120 |
#define AR8216_PORT_VLAN_PRIORITY BITS(28, 2) |
|---|
| 121 |
#define AR8216_PORT_VLAN_PRIORITY_S 28 |
|---|
| 122 |
|
|---|
| 123 |
/* ingress 802.1q mode */ |
|---|
| 124 |
#define AR8216_PORT_VLAN_MODE BITS(30, 2) |
|---|
| 125 |
#define AR8216_PORT_VLAN_MODE_S 30 |
|---|
| 126 |
|
|---|
| 127 |
#define AR8216_REG_PORT_RATE(_i) (AR8216_PORT_OFFSET(_i) + 0x000c) |
|---|
| 128 |
#define AR8216_REG_PORT_PRIO(_i) (AR8216_PORT_OFFSET(_i) + 0x0010) |
|---|
| 129 |
|
|---|
| 130 |
/* ingress 802.1q mode */ |
|---|
| 131 |
enum { |
|---|
| 132 |
AR8216_IN_PORT_ONLY = 0, |
|---|
| 133 |
AR8216_IN_PORT_FALLBACK = 1, |
|---|
| 134 |
AR8216_IN_VLAN_ONLY = 2, |
|---|
| 135 |
AR8216_IN_SECURE = 3 |
|---|
| 136 |
}; |
|---|
| 137 |
|
|---|
| 138 |
/* egress 802.1q mode */ |
|---|
| 139 |
enum { |
|---|
| 140 |
AR8216_OUT_KEEP = 0, |
|---|
| 141 |
AR8216_OUT_STRIP_VLAN = 1, |
|---|
| 142 |
AR8216_OUT_ADD_VLAN = 2 |
|---|
| 143 |
}; |
|---|
| 144 |
|
|---|
| 145 |
/* port forwarding state */ |
|---|
| 146 |
enum { |
|---|
| 147 |
AR8216_PORT_STATE_DISABLED = 0, |
|---|
| 148 |
AR8216_PORT_STATE_BLOCK = 1, |
|---|
| 149 |
AR8216_PORT_STATE_LISTEN = 2, |
|---|
| 150 |
AR8216_PORT_STATE_LEARN = 3, |
|---|
| 151 |
AR8216_PORT_STATE_FORWARD = 4 |
|---|
| 152 |
}; |
|---|
| 153 |
|
|---|
| 154 |
#endif |
|---|