2 * linux/drivers/net/ehea/ehea.h
4 * eHEA ethernet device driver for IBM eServer System p
6 * (C) Copyright IBM Corp. 2006
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
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)
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.
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.
32 #include <linux/module.h>
33 #include <linux/ethtool.h>
34 #include <linux/vmalloc.h>
35 #include <linux/if_vlan.h>
36 #include <linux/inet_lro.h>
38 #include <asm/ibmebus.h>
39 #include <asm/abs_addr.h>
42 #define DRV_NAME "ehea"
43 #define DRV_VERSION "EHEA_0090"
45 /* eHEA capability flags */
46 #define DLPAR_PORT_ADD_REM 1
47 #define DLPAR_MEM_ADD 2
48 #define DLPAR_MEM_REM 4
49 #define EHEA_CAPABILITIES (DLPAR_PORT_ADD_REM | DLPAR_MEM_ADD)
51 #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
52 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
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
60 #define EHEA_SMALL_QUEUES
61 #define EHEA_NUM_TX_QP 1
62 #define EHEA_LRO_MAX_AGGR 64
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
71 #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
78 #define EHEA_MAX_ENTRIES_EQ 20
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 */
89 #define MAX_LRO_DESCRIPTORS 8
91 /* Send completion signaling */
93 /* Protection Domain Identifier */
94 #define EHEA_PD_ID 0xaabcdeff
96 #define EHEA_RQ2_THRESHOLD 1
97 #define EHEA_RQ3_THRESHOLD 9 /* use RQ3 threshold of 1522 bytes */
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
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
115 #define EHEA_CACHE_LINE 128
118 #define EHEA_MR_ACC_CTRL 0x00800000
120 #define EHEA_BUSMAP_START 0x8000000000000000ULL
122 #define EHEA_WATCH_DOG_TIMEOUT 10*HZ
124 /* utility functions */
126 #define ehea_info(fmt, args...) \
127 printk(KERN_INFO DRV_NAME ": " fmt "\n", ## args)
129 #define ehea_error(fmt, args...) \
130 printk(KERN_ERR DRV_NAME ": Error in %s: " fmt "\n", __func__, ## args)
133 #define ehea_debug(fmt, args...) \
134 printk(KERN_DEBUG DRV_NAME ": " fmt, ## args)
136 #define ehea_debug(fmt, args...) do {} while (0)
139 void ehea_dump(void *adr, int len, char *msg);
141 #define EHEA_BMASK(pos, length) (((pos) << 16) + (length))
143 #define EHEA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1))
145 #define EHEA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff)
147 #define EHEA_BMASK_MASK(mask) \
148 (0xffffffffffffffffULL >> ((64 - (mask)) & 0xffff))
150 #define EHEA_BMASK_SET(mask, value) \
151 ((EHEA_BMASK_MASK(mask) & ((u64)(value))) << EHEA_BMASK_SHIFTPOS(mask))
153 #define EHEA_BMASK_GET(mask, value) \
154 (EHEA_BMASK_MASK(mask) & (((u64)(value)) >> EHEA_BMASK_SHIFTPOS(mask)))
160 u8 entries[PAGE_SIZE];
164 * Generic queue in linux kernel virtual memory
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 */
172 u32 toggle_state; /* toggle flag - per page */
173 u32 reserved; /* 64 bit alignment */
177 * For pSeries this is a 64bit memory address where
178 * I/O memory is mapped into CPU address space
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 */
196 unsigned int entries; /* total number of entries */
197 unsigned int valid_sections; /* number of valid sections */
208 * Queue attributes passed to ehea_create_qp()
210 struct ehea_qp_init_attr {
211 /* input parameter */
212 u32 qp_token; /* queue token */
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;
225 u8 swqe_imm_data_len; /* immediate data length for swqes */
233 /* output parameter */
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;
254 * Event Queue attributes, passed as paramter
256 struct ehea_eq_attr {
259 u8 eqe_gen; /* generate eqe flag */
263 u32 ist1; /* Interrupt service token */
274 struct ehea_adapter *adapter;
275 struct hw_queue hw_queue;
279 struct ehea_eq_attr attr;
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;
293 struct ehea_qp_init_attr init_attr;
297 * Completion Queue attributes
299 struct ehea_cq_attr {
300 /* input parameter */
305 /* output parameter */
314 struct ehea_adapter *adapter;
316 struct hw_queue hw_queue;
318 struct ehea_cq_attr attr;
325 struct ehea_adapter *adapter;
332 * Port state information
335 int poll_receive_errors;
342 #define EHEA_IRQ_NAME_SIZE 20
347 struct 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 */
357 struct ehea_port_res {
358 struct napi_struct napi;
359 struct port_stats p_stats;
360 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];
367 struct ehea_cq *send_cq;
368 struct ehea_cq *recv_cq;
370 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;
375 spinlock_t netif_queue;
384 struct net_lro_mgr lro_mgr;
385 struct net_lro_desc lro_desc[MAX_LRO_DESCRIPTORS];
389 #define EHEA_MAX_PORTS 16
391 #define EHEA_NUM_PORTRES_FW_HANDLES 6 /* QP handle, SendCQ handle,
392 RecvCQ handle, EQ handle,
393 SendMR handle, RecvMR handle */
394 #define EHEA_NUM_PORT_FW_HANDLES 1 /* EQ handle */
395 #define EHEA_NUM_ADAPTER_FW_HANDLES 2 /* MR handle, NEQ handle */
397 struct ehea_adapter {
399 struct of_device *ofdev;
400 struct ehea_port *port[EHEA_MAX_PORTS];
401 struct ehea_eq *neq; /* notification event queue */
402 struct tasklet_struct neq_tasklet;
404 u32 pd; /* protection domain */
405 u64 max_mc_mac; /* max number of multicast mac addresses */
407 struct list_head list;
411 struct ehea_mc_list {
412 struct list_head list;
417 struct ehea_fw_handle_entry {
418 u64 adh; /* Adapter Handle */
419 u64 fwh; /* Firmware Handle */
422 struct ehea_fw_handle_array {
423 struct ehea_fw_handle_entry *arr;
428 struct ehea_bcmc_reg_entry {
429 u64 adh; /* Adapter Handle */
430 u32 port_id; /* Logical Port Id */
431 u8 reg_type; /* Registration Type */
435 struct ehea_bcmc_reg_array {
436 struct ehea_bcmc_reg_entry *arr;
441 #define EHEA_PORT_UP 1
442 #define EHEA_PORT_DOWN 0
443 #define EHEA_PHY_LINK_UP 1
444 #define EHEA_PHY_LINK_DOWN 0
445 #define EHEA_MAX_PORT_RES 16
447 struct ehea_adapter *adapter; /* adapter that owns this port */
448 struct net_device *netdev;
449 struct net_device_stats stats;
450 struct ehea_port_res port_res[EHEA_MAX_PORT_RES];
451 struct of_device ofdev; /* Open Firmware Device */
452 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */
453 struct vlan_group *vgrp;
454 struct ehea_eq *qp_eq;
455 struct work_struct reset_task;
456 struct mutex port_lock;
457 char int_aff_name[EHEA_IRQ_NAME_SIZE];
458 int allmulti; /* Indicates IFF_ALLMULTI state */
459 int promisc; /* Indicates IFF_PROMISC state */
477 struct port_res_cfg {
486 enum ehea_flag_bits {
490 void ehea_set_ethtool_ops(struct net_device *netdev);
491 int ehea_sense_port_attr(struct ehea_port *port);
492 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed);
494 extern u64 ehea_driver_flags;
495 extern struct work_struct ehea_rereg_mr_task;
497 #endif /* __EHEA_H__ */