blob: 5e1c28654e16146918a70e2efbbd3da4619a939f [file] [log] [blame]
Masakazu Mokuno02c18892007-07-05 20:11:16 +09001/*
2 * PS3 Platfom gelic network driver.
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2006, 2007 Sony Corporation.
6 *
7 * This file is based on: spider_net.h
8 *
9 * (C) Copyright IBM Corp. 2005
10 *
11 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
12 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28#ifndef _GELIC_NET_H
29#define _GELIC_NET_H
30
31#define GELIC_NET_DRV_NAME "Gelic Network Driver"
32#define GELIC_NET_DRV_VERSION "1.0"
33
34#define GELIC_NET_ETHTOOL /* use ethtool */
35
36/* ioctl */
37#define GELIC_NET_GET_MODE (SIOCDEVPRIVATE + 0)
38#define GELIC_NET_SET_MODE (SIOCDEVPRIVATE + 1)
39
40/* descriptors */
41#define GELIC_NET_RX_DESCRIPTORS 128 /* num of descriptors */
42#define GELIC_NET_TX_DESCRIPTORS 128 /* num of descriptors */
43
44#define GELIC_NET_MAX_MTU 2308
45#define GELIC_NET_MIN_MTU 64
46#define GELIC_NET_RXBUF_ALIGN 128
47#define GELIC_NET_RX_CSUM_DEFAULT 1 /* hw chksum */
48#define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ
49#define GELIC_NET_NAPI_WEIGHT (GELIC_NET_RX_DESCRIPTORS)
50#define GELIC_NET_BROADCAST_ADDR 0xffffffffffffL
51#define GELIC_NET_VLAN_POS (VLAN_ETH_ALEN * 2)
52#define GELIC_NET_VLAN_MAX 4
53#define GELIC_NET_MC_COUNT_MAX 32 /* multicast address list */
54
55enum gelic_net_int0_status {
56 GELIC_NET_GDTDCEINT = 24,
57 GELIC_NET_GRFANMINT = 28,
58};
59
60/* GHIINT1STS bits */
61enum gelic_net_int1_status {
62 GELIC_NET_GDADCEINT = 14,
63};
64
65/* interrupt mask */
66#define GELIC_NET_TXINT (1L << (GELIC_NET_GDTDCEINT + 32))
67
68#define GELIC_NET_RXINT0 (1L << (GELIC_NET_GRFANMINT + 32))
69#define GELIC_NET_RXINT1 (1L << GELIC_NET_GDADCEINT)
70#define GELIC_NET_RXINT (GELIC_NET_RXINT0 | GELIC_NET_RXINT1)
71
72 /* RX descriptor data_status bits */
73#define GELIC_NET_RXDMADU 0x80000000 /* destination MAC addr unknown */
74#define GELIC_NET_RXLSTFBF 0x40000000 /* last frame buffer */
75#define GELIC_NET_RXIPCHK 0x20000000 /* IP checksum performed */
76#define GELIC_NET_RXTCPCHK 0x10000000 /* TCP/UDP checksup performed */
77#define GELIC_NET_RXIPSPKT 0x08000000 /* IPsec packet */
78#define GELIC_NET_RXIPSAHPRT 0x04000000 /* IPsec AH protocol performed */
79#define GELIC_NET_RXIPSESPPRT 0x02000000 /* IPsec ESP protocol performed */
80#define GELIC_NET_RXSESPAH 0x01000000 /*
81 * IPsec ESP protocol auth
82 * performed
83 */
84
85#define GELIC_NET_RXWTPKT 0x00C00000 /*
86 * wakeup trigger packet
87 * 01: Magic Packet (TM)
88 * 10: ARP packet
89 * 11: Multicast MAC addr
90 */
91#define GELIC_NET_RXVLNPKT 0x00200000 /* VLAN packet */
92/* bit 20..16 reserved */
93#define GELIC_NET_RXRECNUM 0x0000ff00 /* reception receipt number */
94/* bit 7..0 reserved */
95
96#define GELIC_NET_TXDESC_TAIL 0
97#define GELIC_NET_DATA_STATUS_CHK_MASK (GELIC_NET_RXIPCHK | GELIC_NET_RXTCPCHK)
98
99/* RX descriptor data_error bits */
100/* bit 31 reserved */
101#define GELIC_NET_RXALNERR 0x40000000 /* alignement error 10/100M */
102#define GELIC_NET_RXOVERERR 0x20000000 /* oversize error */
103#define GELIC_NET_RXRNTERR 0x10000000 /* Runt error */
104#define GELIC_NET_RXIPCHKERR 0x08000000 /* IP checksum error */
105#define GELIC_NET_RXTCPCHKERR 0x04000000 /* TCP/UDP checksum error */
106#define GELIC_NET_RXUMCHSP 0x02000000 /* unmatched sp on sp */
107#define GELIC_NET_RXUMCHSPI 0x01000000 /* unmatched SPI on SAD */
108#define GELIC_NET_RXUMCHSAD 0x00800000 /* unmatched SAD */
109#define GELIC_NET_RXIPSAHERR 0x00400000 /* auth error on AH protocol
110 * processing */
111#define GELIC_NET_RXIPSESPAHERR 0x00200000 /* auth error on ESP protocol
112 * processing */
113#define GELIC_NET_RXDRPPKT 0x00100000 /* drop packet */
114#define GELIC_NET_RXIPFMTERR 0x00080000 /* IP packet format error */
115/* bit 18 reserved */
116#define GELIC_NET_RXDATAERR 0x00020000 /* IP packet format error */
117#define GELIC_NET_RXCALERR 0x00010000 /* cariier extension length
118 * error */
119#define GELIC_NET_RXCREXERR 0x00008000 /* carrier extention error */
120#define GELIC_NET_RXMLTCST 0x00004000 /* multicast address frame */
121/* bit 13..0 reserved */
122#define GELIC_NET_DATA_ERROR_CHK_MASK \
123 (GELIC_NET_RXIPCHKERR | GELIC_NET_RXTCPCHKERR)
124
125
126/* tx descriptor command and status */
127#define GELIC_NET_DMAC_CMDSTAT_NOCS 0xa0080000 /* middle of frame */
128#define GELIC_NET_DMAC_CMDSTAT_TCPCS 0xa00a0000
129#define GELIC_NET_DMAC_CMDSTAT_UDPCS 0xa00b0000
130#define GELIC_NET_DMAC_CMDSTAT_END_FRAME 0x00040000 /* end of frame */
131
132#define GELIC_NET_DMAC_CMDSTAT_RXDCEIS 0x00000002 /* descriptor chain end
133 * interrupt status */
134
135#define GELIC_NET_DMAC_CMDSTAT_CHAIN_END 0x00000002 /* RXDCEIS:DMA stopped */
136#define GELIC_NET_DMAC_CMDSTAT_NOT_IN_USE 0xb0000000
137#define GELIC_NET_DESCR_IND_PROC_SHIFT 28
138#define GELIC_NET_DESCR_IND_PROC_MASKO 0x0fffffff
139
140
141enum gelic_net_descr_status {
142 GELIC_NET_DESCR_COMPLETE = 0x00, /* used in rx and tx */
143 GELIC_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */
144 GELIC_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */
145 GELIC_NET_DESCR_FRAME_END = 0x04, /* used in rx */
146 GELIC_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */
147 GELIC_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */
148 GELIC_NET_DESCR_NOT_IN_USE /* any other value */
149};
150/* for lv1_net_control */
151#define GELIC_NET_GET_MAC_ADDRESS 0x0000000000000001
152#define GELIC_NET_GET_ETH_PORT_STATUS 0x0000000000000002
153#define GELIC_NET_SET_NEGOTIATION_MODE 0x0000000000000003
154#define GELIC_NET_GET_VLAN_ID 0x0000000000000004
155
156#define GELIC_NET_LINK_UP 0x0000000000000001
157#define GELIC_NET_FULL_DUPLEX 0x0000000000000002
158#define GELIC_NET_AUTO_NEG 0x0000000000000004
159#define GELIC_NET_SPEED_10 0x0000000000000010
160#define GELIC_NET_SPEED_100 0x0000000000000020
161#define GELIC_NET_SPEED_1000 0x0000000000000040
162
163#define GELIC_NET_VLAN_ALL 0x0000000000000001
164#define GELIC_NET_VLAN_WIRED 0x0000000000000002
165#define GELIC_NET_VLAN_WIRELESS 0x0000000000000003
166#define GELIC_NET_VLAN_PSP 0x0000000000000004
167#define GELIC_NET_VLAN_PORT0 0x0000000000000010
168#define GELIC_NET_VLAN_PORT1 0x0000000000000011
169#define GELIC_NET_VLAN_PORT2 0x0000000000000012
170#define GELIC_NET_VLAN_DAEMON_CLIENT_BSS 0x0000000000000013
171#define GELIC_NET_VLAN_LIBERO_CLIENT_BSS 0x0000000000000014
172#define GELIC_NET_VLAN_NO_ENTRY -6
173
174#define GELIC_NET_PORT 2 /* for port status */
175
176/* size of hardware part of gelic descriptor */
177#define GELIC_NET_DESCR_SIZE (32)
178struct gelic_net_descr {
179 /* as defined by the hardware */
180 u32 buf_addr;
181 u32 buf_size;
182 u32 next_descr_addr;
183 u32 dmac_cmd_status;
184 u32 result_size;
185 u32 valid_size; /* all zeroes for tx */
186 u32 data_status;
187 u32 data_error; /* all zeroes for tx */
188
189 /* used in the driver */
190 struct sk_buff *skb;
191 dma_addr_t bus_addr;
192 struct gelic_net_descr *next;
193 struct gelic_net_descr *prev;
194 struct vlan_ethhdr vlan;
195} __attribute__((aligned(32)));
196
197struct gelic_net_descr_chain {
198 /* we walk from tail to head */
199 struct gelic_net_descr *head;
200 struct gelic_net_descr *tail;
201};
202
203struct gelic_net_card {
204 struct net_device *netdev;
205 /*
206 * hypervisor requires irq_status should be
207 * 8 bytes aligned, but u64 member is
208 * always disposed in that manner
209 */
210 u64 irq_status;
211 u64 ghiintmask;
212
213 struct ps3_system_bus_device *dev;
214 u32 vlan_id[GELIC_NET_VLAN_MAX];
215 int vlan_index;
216
217 struct gelic_net_descr_chain tx_chain;
218 struct gelic_net_descr_chain rx_chain;
219 /* gurad dmac descriptor chain*/
220 spinlock_t chain_lock;
221
222 struct net_device_stats netdev_stats;
223 int rx_csum;
224 /* guard tx_dma_progress */
225 spinlock_t tx_dma_lock;
226 int tx_dma_progress;
227
228 struct work_struct tx_timeout_task;
229 atomic_t tx_timeout_task_counter;
230 wait_queue_head_t waitq;
231
232 struct gelic_net_descr *tx_top, *rx_top;
233 struct gelic_net_descr descr[0];
234};
235
236
237extern unsigned long p_to_lp(long pa);
238
239#endif /* _GELIC_NET_H */