blob: c0cbd949e33619d3d354af60efa6db0b4dc6a275 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea.h
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
12 *
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
29#ifndef __EHEA_H__
30#define __EHEA_H__
31
32#include <linux/module.h>
33#include <linux/ethtool.h>
34#include <linux/vmalloc.h>
35#include <linux/if_vlan.h>
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070036#include <linux/inet_lro.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020037
38#include <asm/ibmebus.h>
39#include <asm/abs_addr.h>
40#include <asm/io.h>
41
42#define DRV_NAME "ehea"
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020043#define DRV_VERSION "EHEA_0074"
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +020044
Thomas Klein44c82152007-07-11 16:32:00 +020045/* eHEA capability flags */
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +020046#define DLPAR_PORT_ADD_REM 1
Thomas Klein44c82152007-07-11 16:32:00 +020047#define DLPAR_MEM_ADD 2
48#define DLPAR_MEM_REM 4
49#define EHEA_CAPABILITIES (DLPAR_PORT_ADD_REM)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020050
51#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
52 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
53
54#define EHEA_MAX_ENTRIES_RQ1 32767
55#define EHEA_MAX_ENTRIES_RQ2 16383
56#define EHEA_MAX_ENTRIES_RQ3 16383
57#define EHEA_MAX_ENTRIES_SQ 32767
58#define EHEA_MIN_ENTRIES_QP 127
59
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +020060#define EHEA_SMALL_QUEUES
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020061#define EHEA_NUM_TX_QP 1
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070062#define EHEA_LRO_MAX_AGGR 64
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020063
64#ifdef EHEA_SMALL_QUEUES
65#define EHEA_MAX_CQE_COUNT 1023
66#define EHEA_DEF_ENTRIES_SQ 1023
67#define EHEA_DEF_ENTRIES_RQ1 4095
68#define EHEA_DEF_ENTRIES_RQ2 1023
69#define EHEA_DEF_ENTRIES_RQ3 1023
70#else
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +020071#define EHEA_MAX_CQE_COUNT 4080
72#define EHEA_DEF_ENTRIES_SQ 4080
73#define EHEA_DEF_ENTRIES_RQ1 8160
74#define EHEA_DEF_ENTRIES_RQ2 2040
75#define EHEA_DEF_ENTRIES_RQ3 2040
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076#endif
77
78#define EHEA_MAX_ENTRIES_EQ 20
79
80#define EHEA_SG_SQ 2
81#define EHEA_SG_RQ1 1
82#define EHEA_SG_RQ2 0
83#define EHEA_SG_RQ3 0
84
85#define EHEA_MAX_PACKET_SIZE 9022 /* for jumbo frames */
86#define EHEA_RQ2_PKT_SIZE 1522
87#define EHEA_L_PKT_SIZE 256 /* low latency */
88
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070089#define MAX_LRO_DESCRIPTORS 8
90
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020091/* Send completion signaling */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
93/* Protection Domain Identifier */
94#define EHEA_PD_ID 0xaabcdeff
95
96#define EHEA_RQ2_THRESHOLD 1
97#define EHEA_RQ3_THRESHOLD 9 /* use RQ3 threshold of 1522 bytes */
98
99#define EHEA_SPEED_10G 10000
100#define EHEA_SPEED_1G 1000
101#define EHEA_SPEED_100M 100
102#define EHEA_SPEED_10M 10
103#define EHEA_SPEED_AUTONEG 0
104
105/* Broadcast/Multicast registration types */
106#define EHEA_BCMC_SCOPE_ALL 0x08
107#define EHEA_BCMC_SCOPE_SINGLE 0x00
108#define EHEA_BCMC_MULTICAST 0x04
109#define EHEA_BCMC_BROADCAST 0x00
110#define EHEA_BCMC_UNTAGGED 0x02
111#define EHEA_BCMC_TAGGED 0x00
112#define EHEA_BCMC_VLANID_ALL 0x01
113#define EHEA_BCMC_VLANID_SINGLE 0x00
114
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200115#define EHEA_CACHE_LINE 128
116
117/* Memory Regions */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200118#define EHEA_MR_ACC_CTRL 0x00800000
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200119
Thomas Klein44c82152007-07-11 16:32:00 +0200120#define EHEA_BUSMAP_START 0x8000000000000000ULL
121
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200122#define EHEA_WATCH_DOG_TIMEOUT 10*HZ
123
124/* utility functions */
125
126#define ehea_info(fmt, args...) \
127 printk(KERN_INFO DRV_NAME ": " fmt "\n", ## args)
128
129#define ehea_error(fmt, args...) \
130 printk(KERN_ERR DRV_NAME ": Error in %s: " fmt "\n", __func__, ## args)
131
132#ifdef DEBUG
133#define ehea_debug(fmt, args...) \
134 printk(KERN_DEBUG DRV_NAME ": " fmt, ## args)
135#else
136#define ehea_debug(fmt, args...) do {} while (0)
137#endif
138
139void ehea_dump(void *adr, int len, char *msg);
140
141#define EHEA_BMASK(pos, length) (((pos) << 16) + (length))
142
143#define EHEA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1))
144
145#define EHEA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff)
146
147#define EHEA_BMASK_MASK(mask) \
148 (0xffffffffffffffffULL >> ((64 - (mask)) & 0xffff))
149
150#define EHEA_BMASK_SET(mask, value) \
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200151 ((EHEA_BMASK_MASK(mask) & ((u64)(value))) << EHEA_BMASK_SHIFTPOS(mask))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200152
153#define EHEA_BMASK_GET(mask, value) \
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200154 (EHEA_BMASK_MASK(mask) & (((u64)(value)) >> EHEA_BMASK_SHIFTPOS(mask)))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200155
156/*
157 * Generic ehea page
158 */
159struct ehea_page {
160 u8 entries[PAGE_SIZE];
161};
162
163/*
164 * Generic queue in linux kernel virtual memory
165 */
166struct hw_queue {
167 u64 current_q_offset; /* current queue entry */
168 struct ehea_page **queue_pages; /* array of pages belonging to queue */
169 u32 qe_size; /* queue entry size */
170 u32 queue_length; /* queue length allocated in bytes */
171 u32 pagesize;
172 u32 toggle_state; /* toggle flag - per page */
173 u32 reserved; /* 64 bit alignment */
174};
175
176/*
177 * For pSeries this is a 64bit memory address where
178 * I/O memory is mapped into CPU address space
179 */
180struct h_epa {
181 void __iomem *addr;
182};
183
184struct h_epa_user {
185 u64 addr;
186};
187
188struct h_epas {
189 struct h_epa kernel; /* kernel space accessible resource,
190 set to 0 if unused */
191 struct h_epa_user user; /* user space accessible resource
192 set to 0 if unused */
193};
194
Thomas Klein44c82152007-07-11 16:32:00 +0200195struct ehea_busmap {
196 unsigned int entries; /* total number of entries */
197 unsigned int valid_sections; /* number of valid sections */
198 u64 *vaddr;
199};
200
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200201struct ehea_qp;
202struct ehea_cq;
203struct ehea_eq;
204struct ehea_port;
205struct ehea_av;
206
207/*
208 * Queue attributes passed to ehea_create_qp()
209 */
210struct ehea_qp_init_attr {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200211 /* input parameter */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200212 u32 qp_token; /* queue token */
213 u8 low_lat_rq1;
214 u8 signalingtype; /* cqe generation flag */
215 u8 rq_count; /* num of receive queues */
216 u8 eqe_gen; /* eqe generation flag */
217 u16 max_nr_send_wqes; /* max number of send wqes */
218 u16 max_nr_rwqes_rq1; /* max number of receive wqes */
219 u16 max_nr_rwqes_rq2;
220 u16 max_nr_rwqes_rq3;
221 u8 wqe_size_enc_sq;
222 u8 wqe_size_enc_rq1;
223 u8 wqe_size_enc_rq2;
224 u8 wqe_size_enc_rq3;
225 u8 swqe_imm_data_len; /* immediate data length for swqes */
226 u16 port_nr;
227 u16 rq2_threshold;
228 u16 rq3_threshold;
229 u64 send_cq_handle;
230 u64 recv_cq_handle;
231 u64 aff_eq_handle;
232
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200233 /* output parameter */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200234 u32 qp_nr;
235 u16 act_nr_send_wqes;
236 u16 act_nr_rwqes_rq1;
237 u16 act_nr_rwqes_rq2;
238 u16 act_nr_rwqes_rq3;
239 u8 act_wqe_size_enc_sq;
240 u8 act_wqe_size_enc_rq1;
241 u8 act_wqe_size_enc_rq2;
242 u8 act_wqe_size_enc_rq3;
243 u32 nr_sq_pages;
244 u32 nr_rq1_pages;
245 u32 nr_rq2_pages;
246 u32 nr_rq3_pages;
247 u32 liobn_sq;
248 u32 liobn_rq1;
249 u32 liobn_rq2;
250 u32 liobn_rq3;
251};
252
253/*
254 * Event Queue attributes, passed as paramter
255 */
256struct ehea_eq_attr {
257 u32 type;
258 u32 max_nr_of_eqes;
259 u8 eqe_gen; /* generate eqe flag */
260 u64 eq_handle;
261 u32 act_nr_of_eqes;
262 u32 nr_pages;
263 u32 ist1; /* Interrupt service token */
264 u32 ist2;
265 u32 ist3;
266 u32 ist4;
267};
268
269
270/*
271 * Event Queue
272 */
273struct ehea_eq {
274 struct ehea_adapter *adapter;
275 struct hw_queue hw_queue;
276 u64 fw_handle;
277 struct h_epas epas;
278 spinlock_t spinlock;
279 struct ehea_eq_attr attr;
280};
281
282/*
283 * HEA Queues
284 */
285struct ehea_qp {
286 struct ehea_adapter *adapter;
287 u64 fw_handle; /* QP handle for firmware calls */
288 struct hw_queue hw_squeue;
289 struct hw_queue hw_rqueue1;
290 struct hw_queue hw_rqueue2;
291 struct hw_queue hw_rqueue3;
292 struct h_epas epas;
293 struct ehea_qp_init_attr init_attr;
294};
295
296/*
297 * Completion Queue attributes
298 */
299struct ehea_cq_attr {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200300 /* input parameter */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200301 u32 max_nr_of_cqes;
302 u32 cq_token;
303 u64 eq_handle;
304
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200305 /* output parameter */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200306 u32 act_nr_of_cqes;
307 u32 nr_pages;
308};
309
310/*
311 * Completion Queue
312 */
313struct ehea_cq {
314 struct ehea_adapter *adapter;
315 u64 fw_handle;
316 struct hw_queue hw_queue;
317 struct h_epas epas;
318 struct ehea_cq_attr attr;
319};
320
321/*
322 * Memory Region
323 */
324struct ehea_mr {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100325 struct ehea_adapter *adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200326 u64 handle;
327 u64 vaddr;
328 u32 lkey;
329};
330
331/*
332 * Port state information
333 */
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100334struct port_stats {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200335 int poll_receive_errors;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 int queue_stopped;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100337 int err_tcp_cksum;
338 int err_ip_cksum;
339 int err_frame_crc;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200340};
341
342#define EHEA_IRQ_NAME_SIZE 20
343
344/*
345 * Queue SKB Array
346 */
347struct ehea_q_skb_arr {
348 struct sk_buff **arr; /* skb array for queue */
349 int len; /* array length */
350 int index; /* array index */
351 int os_skbs; /* rq2/rq3 only: outstanding skbs */
352};
353
354/*
355 * Port resources
356 */
357struct ehea_port_res {
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700358 struct napi_struct napi;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100359 struct port_stats p_stats;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200360 struct ehea_mr send_mr; /* send memory region */
361 struct ehea_mr recv_mr; /* receive memory region */
362 spinlock_t xmit_lock;
363 struct ehea_port *port;
364 char int_recv_name[EHEA_IRQ_NAME_SIZE];
365 char int_send_name[EHEA_IRQ_NAME_SIZE];
366 struct ehea_qp *qp;
367 struct ehea_cq *send_cq;
368 struct ehea_cq *recv_cq;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100369 struct ehea_eq *eq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370 struct ehea_q_skb_arr rq1_skba;
371 struct ehea_q_skb_arr rq2_skba;
372 struct ehea_q_skb_arr rq3_skba;
373 struct ehea_q_skb_arr sq_skba;
374 spinlock_t netif_queue;
375 int queue_stopped;
376 int swqe_refill_th;
377 atomic_t swqe_avail;
378 int swqe_ll_count;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379 u32 swqe_id_counter;
380 u64 tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200381 u64 rx_packets;
382 u32 poll_counter;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700383 struct net_lro_mgr lro_mgr;
384 struct net_lro_desc lro_desc[MAX_LRO_DESCRIPTORS];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200385};
386
387
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100388#define EHEA_MAX_PORTS 16
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389struct ehea_adapter {
390 u64 handle;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100391 struct ibmebus_dev *ebus_dev;
392 struct ehea_port *port[EHEA_MAX_PORTS];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200393 struct ehea_eq *neq; /* notification event queue */
394 struct workqueue_struct *ehea_wq;
395 struct tasklet_struct neq_tasklet;
396 struct ehea_mr mr;
397 u32 pd; /* protection domain */
398 u64 max_mc_mac; /* max number of multicast mac addresses */
Thomas Klein44c82152007-07-11 16:32:00 +0200399 int active_ports;
400 struct list_head list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401};
402
403
404struct ehea_mc_list {
405 struct list_head list;
406 u64 macaddr;
407};
408
409#define EHEA_PORT_UP 1
410#define EHEA_PORT_DOWN 0
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200411#define EHEA_PHY_LINK_UP 1
412#define EHEA_PHY_LINK_DOWN 0
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413#define EHEA_MAX_PORT_RES 16
414struct ehea_port {
415 struct ehea_adapter *adapter; /* adapter that owns this port */
416 struct net_device *netdev;
417 struct net_device_stats stats;
418 struct ehea_port_res port_res[EHEA_MAX_PORT_RES];
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100419 struct of_device ofdev; /* Open Firmware Device */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */
421 struct vlan_group *vgrp;
422 struct ehea_eq *qp_eq;
423 struct work_struct reset_task;
424 struct semaphore port_lock;
425 char int_aff_name[EHEA_IRQ_NAME_SIZE];
426 int allmulti; /* Indicates IFF_ALLMULTI state */
427 int promisc; /* Indicates IFF_PROMISC state */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100428 int num_tx_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429 int num_add_tx_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100430 int num_mcs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431 int resets;
432 u64 mac_addr;
433 u32 logical_port_id;
434 u32 port_speed;
435 u32 msg_enable;
436 u32 sig_comp_iv;
437 u32 state;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700438 u32 lro_max_aggr;
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200439 u8 phy_link;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440 u8 full_duplex;
441 u8 autoneg;
442 u8 num_def_qps;
443};
444
445struct port_res_cfg {
446 int max_entries_rcq;
447 int max_entries_scq;
448 int max_entries_sq;
449 int max_entries_rq1;
450 int max_entries_rq2;
451 int max_entries_rq3;
452};
453
Thomas Klein44c82152007-07-11 16:32:00 +0200454enum ehea_flag_bits {
455 __EHEA_STOP_XFER
456};
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457
458void ehea_set_ethtool_ops(struct net_device *netdev);
459int ehea_sense_port_attr(struct ehea_port *port);
460int ehea_set_portspeed(struct ehea_port *port, u32 port_speed);
461
462#endif /* __EHEA_H__ */