Staging: Add ServerEngines benet 10Gb ethernet driver
[linux-2.6.git] / drivers / staging / benet / benet.h
blob865022c3ff5b3c665c5feb3c045bba3c7e61088b
1 /*
2 * Copyright (C) 2005 - 2008 ServerEngines
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@serverengines.com
13 * ServerEngines
14 * 209 N. Fair Oaks Ave
15 * Sunnyvale, CA 94085
17 #ifndef _BENET_H_
18 #define _BENET_H_
20 #include <linux/pci.h>
21 #include <linux/netdevice.h>
22 #include <linux/inet_lro.h>
23 #include "hwlib.h"
25 #define _SA_MODULE_NAME "net-driver"
27 #define VLAN_VALID_BIT 0x8000
28 #define BE_NUM_VLAN_SUPPORTED 32
29 #define BE_PORT_LINK_DOWN 0000
30 #define BE_PORT_LINK_UP 0001
31 #define BE_MAX_TX_FRAG_COUNT (30)
33 /* Flag bits for send operation */
34 #define IPCS (1 << 0) /* Enable IP checksum offload */
35 #define UDPCS (1 << 1) /* Enable UDP checksum offload */
36 #define TCPCS (1 << 2) /* Enable TCP checksum offload */
37 #define LSO (1 << 3) /* Enable Large Segment offload */
38 #define ETHVLAN (1 << 4) /* Enable VLAN insert */
39 #define ETHEVENT (1 << 5) /* Generate event on completion */
40 #define ETHCOMPLETE (1 << 6) /* Generate completion when done */
41 #define IPSEC (1 << 7) /* Enable IPSEC */
42 #define FORWARD (1 << 8) /* Send the packet in forwarding path */
43 #define FIN (1 << 9) /* Issue FIN segment */
45 #define BE_MAX_MTU 8974
47 #define BE_MAX_LRO_DESCRIPTORS 8
48 #define BE_LRO_MAX_PKTS 64
49 #define BE_MAX_FRAGS_PER_FRAME 6
51 extern const char be_drvr_ver[];
52 extern char be_fw_ver[];
53 extern char be_driver_name[];
55 extern struct ethtool_ops be_ethtool_ops;
57 #define BE_DEV_STATE_NONE 0
58 #define BE_DEV_STATE_INIT 1
59 #define BE_DEV_STATE_OPEN 2
60 #define BE_DEV_STATE_SUSPEND 3
62 /* This structure is used to describe physical fragments to use
63 * for DMAing data from NIC.
65 struct be_recv_buffer {
66 struct list_head rxb_list; /* for maintaining a linked list */
67 void *rxb_va; /* buffer virtual address */
68 u32 rxb_pa_lo; /* low part of physical address */
69 u32 rxb_pa_hi; /* high part of physical address */
70 u32 rxb_len; /* length of recv buffer */
71 void *rxb_ctxt; /* context for OSM driver to use */
75 * fragment list to describe scattered data.
77 struct be_tx_frag_list {
78 u32 txb_len; /* Size of this fragment */
79 u32 txb_pa_lo; /* Lower 32 bits of 64 bit physical addr */
80 u32 txb_pa_hi; /* Higher 32 bits of 64 bit physical addr */
83 struct be_rx_page_info {
84 struct page *page;
85 dma_addr_t bus;
86 u16 page_offset;
90 * This structure is the main tracking structure for a NIC interface.
92 struct be_net_object {
93 /* MCC Ring - used to send fwcmds to embedded ARM processor */
94 struct MCC_WRB_AMAP *mcc_q; /* VA of the start of the ring */
95 u32 mcc_q_len; /* # of WRB entries in this ring */
96 u32 mcc_q_size;
97 u32 mcc_q_hd; /* MCC ring head */
98 u8 mcc_q_created; /* flag to help cleanup */
99 struct be_mcc_object mcc_q_obj; /* BECLIB's MCC ring Object */
100 dma_addr_t mcc_q_bus; /* DMA'ble bus address */
102 /* MCC Completion Ring - FW responses to fwcmds sent from MCC ring */
103 struct MCC_CQ_ENTRY_AMAP *mcc_cq; /* VA of the start of the ring */
104 u32 mcc_cq_len; /* # of compl. entries in this ring */
105 u32 mcc_cq_size;
106 u32 mcc_cq_tl; /* compl. ring tail */
107 u8 mcc_cq_created; /* flag to help cleanup */
108 struct be_cq_object mcc_cq_obj; /* BECLIB's MCC compl. ring object */
109 u32 mcc_cq_id; /* MCC ring ID */
110 dma_addr_t mcc_cq_bus; /* DMA'ble bus address */
112 struct ring_desc mb_rd; /* RD for MCC_MAIL_BOX */
113 void *mb_ptr; /* mailbox ptr to be freed */
114 dma_addr_t mb_bus; /* DMA'ble bus address */
115 u32 mb_size;
117 /* BEClib uses an array of context objects to track outstanding
118 * requests to the MCC. We need allocate the same number of
119 * conext entries as the number of entries in the MCC WRB ring
121 u32 mcc_wrb_ctxt_size;
122 void *mcc_wrb_ctxt; /* pointer to the context area */
123 u32 mcc_wrb_ctxtLen; /* Number of entries in the context */
125 * NIC send request ring - used for xmitting raw ether frames.
127 struct ETH_WRB_AMAP *tx_q; /* VA of the start of the ring */
128 u32 tx_q_len; /* # if entries in the send ring */
129 u32 tx_q_size;
130 u32 tx_q_hd; /* Head index. Next req. goes here */
131 u32 tx_q_tl; /* Tail indx. oldest outstanding req. */
132 u8 tx_q_created; /* flag to help cleanup */
133 struct be_ethsq_object tx_q_obj;/* BECLIB's send Q handle */
134 dma_addr_t tx_q_bus; /* DMA'ble bus address */
135 u32 tx_q_id; /* send queue ring ID */
136 u32 tx_q_port; /* 0 no binding, 1 port A, 2 port B */
137 atomic_t tx_q_used; /* # of WRBs used */
138 /* ptr to an array in which we store context info for each send req. */
139 void **tx_ctxt;
141 * NIC Send compl. ring - completion status for all NIC frames xmitted.
143 struct ETH_TX_COMPL_AMAP *tx_cq;/* VA of start of the ring */
144 u32 txcq_len; /* # of entries in the ring */
145 u32 tx_cq_size;
147 * index into compl ring where the host expects next completion entry
149 u32 tx_cq_tl;
150 u32 tx_cq_id; /* completion queue id */
151 u8 tx_cq_created; /* flag to help cleanup */
152 struct be_cq_object tx_cq_obj;
153 dma_addr_t tx_cq_bus; /* DMA'ble bus address */
155 * Event Queue - all completion entries post events here.
157 struct EQ_ENTRY_AMAP *event_q; /* VA of start of event queue */
158 u32 event_q_len; /* # of entries */
159 u32 event_q_size;
160 u32 event_q_tl; /* Tail of the event queue */
161 u32 event_q_id; /* Event queue ID */
162 u8 event_q_created; /* flag to help cleanup */
163 struct be_eq_object event_q_obj; /* Queue handle */
164 dma_addr_t event_q_bus; /* DMA'ble bus address */
166 * NIC receive queue - Data buffers to be used for receiving unicast,
167 * broadcast and multi-cast frames are posted here.
169 struct ETH_RX_D_AMAP *rx_q; /* VA of start of the queue */
170 u32 rx_q_len; /* # of entries */
171 u32 rx_q_size;
172 u32 rx_q_hd; /* Head of the queue */
173 atomic_t rx_q_posted; /* number of posted buffers */
174 u32 rx_q_id; /* queue ID */
175 u8 rx_q_created; /* flag to help cleanup */
176 struct be_ethrq_object rx_q_obj; /* NIC RX queue handle */
177 dma_addr_t rx_q_bus; /* DMA'ble bus address */
179 * Pointer to an array of opaque context object for use by OSM driver
181 void **rx_ctxt;
183 * NIC unicast RX completion queue - all unicast ether frame completion
184 * statuses from BE come here.
186 struct ETH_RX_COMPL_AMAP *rx_cq; /* VA of start of the queue */
187 u32 rx_cq_len; /* # of entries */
188 u32 rx_cq_size;
189 u32 rx_cq_tl; /* Tail of the queue */
190 u32 rx_cq_id; /* queue ID */
191 u8 rx_cq_created; /* flag to help cleanup */
192 struct be_cq_object rx_cq_obj; /* queue handle */
193 dma_addr_t rx_cq_bus; /* DMA'ble bus address */
194 struct be_function_object fn_obj; /* function object */
195 bool fn_obj_created;
196 u32 rx_buf_size; /* Size of the RX buffers */
198 struct net_device *netdev;
199 struct be_recv_buffer eth_rx_bufs[256]; /* to pass Rx buffer
200 addresses */
201 struct be_adapter *adapter; /* Pointer to OSM adapter */
202 u32 devno; /* OSM, network dev no. */
203 u32 use_port; /* Current active port */
204 struct be_rx_page_info *rx_page_info; /* Array of Rx buf pages */
205 u32 rx_pg_info_hd; /* Head of queue */
206 int rxbuf_post_fail; /* RxBuff posting fail count */
207 bool rx_pg_shared; /* Is an allocsted page shared as two frags ? */
208 struct vlan_group *vlan_grp;
209 u32 num_vlans; /* Number of vlans in BE's filter */
210 u16 vlan_tag[BE_NUM_VLAN_SUPPORTED]; /* vlans currently configured */
211 struct napi_struct napi;
212 struct net_lro_mgr lro_mgr;
213 struct net_lro_desc lro_desc[BE_MAX_LRO_DESCRIPTORS];
216 #define NET_FH(np) (&(np)->fn_obj)
219 * BE driver statistics.
221 struct be_drvr_stat {
222 u32 bes_tx_reqs; /* number of TX requests initiated */
223 u32 bes_tx_fails; /* number of TX requests that failed */
224 u32 bes_fwd_reqs; /* number of send reqs through forwarding i/f */
225 u32 bes_tx_wrbs; /* number of tx WRBs used */
227 u32 bes_ints; /* number of interrupts */
228 u32 bes_polls; /* number of times NAPI called poll function */
229 u32 bes_events; /* total evet entries processed */
230 u32 bes_tx_events; /* number of tx completion events */
231 u32 bes_rx_events; /* number of ucast rx completion events */
232 u32 bes_tx_compl; /* number of tx completion entries processed */
233 u32 bes_rx_compl; /* number of rx completion entries
234 processed */
235 u32 bes_ethrx_post_fail; /* number of ethrx buffer alloc
236 failures */
238 * number of non ether type II frames dropped where
239 * frame len > length field of Mac Hdr
241 u32 bes_802_3_dropped_frames;
243 * number of non ether type II frames malformed where
244 * in frame len < length field of Mac Hdr
246 u32 bes_802_3_malformed_frames;
247 u32 bes_ips; /* interrupts / sec */
248 u32 bes_prev_ints; /* bes_ints at last IPS calculation */
249 u16 bes_eth_tx_rate; /* ETH TX rate - Mb/sec */
250 u16 bes_eth_rx_rate; /* ETH RX rate - Mb/sec */
251 u32 bes_rx_coal; /* Num pkts coalasced */
252 u32 bes_rx_flush; /* Num times coalasced */
253 u32 bes_link_change_physical; /*Num of times physical link changed */
254 u32 bes_link_change_virtual; /*Num of times virtual link changed */
255 u32 bes_rx_misc_pkts; /* Misc pkts received */
258 /* Maximum interrupt delay (in microseconds) allowed */
259 #define MAX_EQD 120
262 * timer to prevent system shutdown hang for ever if h/w stops responding
264 struct be_timer_ctxt {
265 atomic_t get_stat_flag;
266 struct timer_list get_stats_timer;
267 unsigned long get_stat_sem_addr;
270 /* This structure is the main BladeEngine driver context. */
271 struct be_adapter {
272 struct net_device *netdevp;
273 struct be_drvr_stat be_stat;
274 struct net_device_stats benet_stats;
276 /* PCI BAR mapped addresses */
277 u8 __iomem *csr_va; /* CSR */
278 u8 __iomem *db_va; /* Door Bell */
279 u8 __iomem *pci_va; /* PCI Config */
281 struct tasklet_struct sts_handler;
282 struct timer_list cq_timer;
283 spinlock_t int_lock;
285 struct FWCMD_ETH_GET_STATISTICS *eth_statsp;
287 * This will enable the use of ethtool to enable or disable
288 * Checksum on Rx pkts to be obeyed or disobeyed.
289 * If this is true = 1, then whatever is the checksum on the
290 * Received pkt as per BE, it will be given to the stack.
291 * Else the stack will re calculate it.
293 bool rx_csum;
295 * This will enable the use of ethtool to enable or disable
296 * Coalese on Rx pkts to be obeyed or disobeyed.
297 * If this is grater than 0 and less than 16 then coalascing
298 * is enabled else it is disabled
300 u32 max_rx_coal;
301 struct pci_dev *pdev; /* Pointer to OS's PCI dvice */
303 spinlock_t txq_lock;
305 u32 isr; /* copy of Intr status reg. */
307 u32 port0_link_sts; /* Port 0 link status */
308 u32 port1_link_sts; /* port 1 list status */
309 struct BE_LINK_STATUS *be_link_sts;
311 /* pointer to the first netobject of this adapter */
312 struct be_net_object *net_obj;
314 /* Flags to indicate what to clean up */
315 bool tasklet_started;
316 bool isr_registered;
318 * adaptive interrupt coalescing (AIC) related
320 bool enable_aic; /* 1 if AIC is enabled */
321 u16 min_eqd; /* minimum EQ delay in usec */
322 u16 max_eqd; /* minimum EQ delay in usec */
323 u16 cur_eqd; /* current EQ delay in usec */
325 * book keeping for interrupt / sec and TX/RX rate calculation
327 ulong ips_jiffies; /* jiffies at last IPS calc */
328 u32 eth_tx_bytes;
329 ulong eth_tx_jiffies;
330 u32 eth_rx_bytes;
331 ulong eth_rx_jiffies;
333 struct semaphore get_eth_stat_sem;
335 /* timer ctxt to prevent shutdown hanging due to un-responsive BE */
336 struct be_timer_ctxt timer_ctxt;
338 #define BE_MAX_MSIX_VECTORS 32
339 #define BE_MAX_REQ_MSIX_VECTORS 1 /* only one EQ in Linux driver */
340 struct msix_entry msix_entries[BE_MAX_MSIX_VECTORS];
341 bool msix_enabled;
342 bool dma_64bit_cap; /* the Device DAC capable or not */
343 u8 dev_state; /* The current state of the device */
344 u8 dev_pm_state; /* The State of device before going to suspend */
348 * Every second we look at the ints/sec and adjust eq_delay
349 * between adapter->min_eqd and adapter->max_eqd to keep the ints/sec between
350 * IPS_HI_WM and IPS_LO_WM.
352 #define IPS_HI_WM 18000
353 #define IPS_LO_WM 8000
356 static inline void index_adv(u32 *index, u32 val, u32 limit)
358 BUG_ON(limit & (limit-1));
359 *index = (*index + val) & (limit - 1);
362 static inline void index_inc(u32 *index, u32 limit)
364 BUG_ON(limit & (limit-1));
365 *index = (*index + 1) & (limit - 1);
368 static inline void be_adv_eq_tl(struct be_net_object *pnob)
370 index_inc(&pnob->event_q_tl, pnob->event_q_len);
373 static inline void be_adv_txq_hd(struct be_net_object *pnob)
375 index_inc(&pnob->tx_q_hd, pnob->tx_q_len);
378 static inline void be_adv_txq_tl(struct be_net_object *pnob)
380 index_inc(&pnob->tx_q_tl, pnob->tx_q_len);
383 static inline void be_adv_txcq_tl(struct be_net_object *pnob)
385 index_inc(&pnob->tx_cq_tl, pnob->txcq_len);
388 static inline void be_adv_rxq_hd(struct be_net_object *pnob)
390 index_inc(&pnob->rx_q_hd, pnob->rx_q_len);
393 static inline void be_adv_rxcq_tl(struct be_net_object *pnob)
395 index_inc(&pnob->rx_cq_tl, pnob->rx_cq_len);
398 static inline u32 tx_compl_lastwrb_idx_get(struct be_net_object *pnob)
400 return (pnob->tx_q_tl + *(u32 *)&pnob->tx_ctxt[pnob->tx_q_tl] - 1)
401 & (pnob->tx_q_len - 1);
404 int benet_init(struct net_device *);
405 int be_ethtool_ioctl(struct net_device *, struct ifreq *);
406 struct net_device_stats *benet_get_stats(struct net_device *);
407 void be_process_intr(unsigned long context);
408 irqreturn_t be_int(int irq, void *dev);
409 void be_post_eth_rx_buffs(struct be_net_object *);
410 void be_get_stat_cb(void *, int, struct MCC_WRB_AMAP *);
411 void be_get_stats_timer_handler(unsigned long);
412 void be_wait_nic_tx_cmplx_cmpl(struct be_net_object *);
413 void be_print_link_info(struct BE_LINK_STATUS *);
414 void be_update_link_status(struct be_adapter *);
415 void be_init_procfs(struct be_adapter *);
416 void be_cleanup_procfs(struct be_adapter *);
417 int be_poll(struct napi_struct *, int);
418 struct ETH_RX_COMPL_AMAP *be_get_rx_cmpl(struct be_net_object *);
419 void be_notify_cmpl(struct be_net_object *, int, int, int);
420 void be_enable_intr(struct be_net_object *);
421 void be_enable_eq_intr(struct be_net_object *);
422 void be_disable_intr(struct be_net_object *);
423 void be_disable_eq_intr(struct be_net_object *);
424 int be_set_uc_mac_adr(struct be_net_object *, u8, u8, u8,
425 u8 *, mcc_wrb_cqe_callback, void *);
426 int be_get_flow_ctl(struct be_function_object *pFnObj, bool *, bool *);
427 void process_one_tx_compl(struct be_net_object *pnob, u32 end_idx);
429 #endif /* _BENET_H_ */