2 * This file is part of the Chelsio T3 Ethernet driver for Linux.
4 * Copyright (C) 2003-2006 Chelsio Communications. All rights reserved.
6 * This program is distributed in the hope that it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
9 * release for licensing terms and conditions.
12 /* This file should not be included directly. Include common.h instead. */
14 #ifndef __T3_ADAPTER_H__
15 #define __T3_ADAPTER_H__
17 #include <linux/pci.h>
18 #include <linux/spinlock.h>
19 #include <linux/interrupt.h>
20 #include <linux/timer.h>
21 #include <linux/cache.h>
22 #include <linux/mutex.h>
24 #include <asm/semaphore.h>
25 #include <asm/bitops.h>
28 typedef irqreturn_t(*intr_handler_t) (int, void *);
33 struct vlan_group *vlan_grp;
34 const struct port_type_info *port_type;
41 struct link_config link_config;
42 struct net_device_stats netstats;
46 enum { /* adapter flags */
47 FULL_INIT_DONE = (1 << 0),
49 USING_MSIX = (1 << 2),
50 QUEUES_BOUND = (1 << 3),
56 struct sge_fl { /* SGE per free-buffer list state */
57 unsigned int buf_size; /* size of each Rx buffer */
58 unsigned int credits; /* # of available Rx buffers */
59 unsigned int size; /* capacity of free list */
60 unsigned int cidx; /* consumer index */
61 unsigned int pidx; /* producer index */
62 unsigned int gen; /* free list generation */
63 struct rx_desc *desc; /* address of HW Rx descriptor ring */
64 struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
65 dma_addr_t phys_addr; /* physical address of HW ring start */
66 unsigned int cntxt_id; /* SGE context id for the free list */
67 unsigned long empty; /* # of times queue ran out of buffers */
71 * Bundle size for grouping offload RX packets for delivery to the stack.
72 * Don't make this too big as we do prefetch on each packet in a bundle.
74 # define RX_BUNDLE_SIZE 8
78 struct sge_rspq { /* state for an SGE response queue */
79 unsigned int credits; /* # of pending response credits */
80 unsigned int size; /* capacity of response queue */
81 unsigned int cidx; /* consumer index */
82 unsigned int gen; /* current generation bit */
83 unsigned int polling; /* is the queue serviced through NAPI? */
84 unsigned int holdoff_tmr; /* interrupt holdoff timer in 100ns */
85 unsigned int next_holdoff; /* holdoff time for next interrupt */
86 struct rsp_desc *desc; /* address of HW response ring */
87 dma_addr_t phys_addr; /* physical address of the ring */
88 unsigned int cntxt_id; /* SGE context id for the response q */
89 spinlock_t lock; /* guards response processing */
90 struct sk_buff *rx_head; /* offload packet receive queue head */
91 struct sk_buff *rx_tail; /* offload packet receive queue tail */
93 unsigned long offload_pkts;
94 unsigned long offload_bundles;
95 unsigned long eth_pkts; /* # of ethernet packets */
96 unsigned long pure_rsps; /* # of pure (non-data) responses */
97 unsigned long imm_data; /* responses with immediate data */
98 unsigned long rx_drops; /* # of packets dropped due to no mem */
99 unsigned long async_notif; /* # of asynchronous notification events */
100 unsigned long empty; /* # of times queue ran out of credits */
101 unsigned long nomem; /* # of responses deferred due to no mem */
102 unsigned long unhandled_irqs; /* # of spurious intrs */
108 struct sge_txq { /* state for an SGE Tx queue */
109 unsigned long flags; /* HW DMA fetch status */
110 unsigned int in_use; /* # of in-use Tx descriptors */
111 unsigned int size; /* # of descriptors */
112 unsigned int processed; /* total # of descs HW has processed */
113 unsigned int cleaned; /* total # of descs SW has reclaimed */
114 unsigned int stop_thres; /* SW TX queue suspend threshold */
115 unsigned int cidx; /* consumer index */
116 unsigned int pidx; /* producer index */
117 unsigned int gen; /* current value of generation bit */
118 unsigned int unacked; /* Tx descriptors used since last COMPL */
119 struct tx_desc *desc; /* address of HW Tx descriptor ring */
120 struct tx_sw_desc *sdesc; /* address of SW Tx descriptor ring */
121 spinlock_t lock; /* guards enqueueing of new packets */
122 unsigned int token; /* WR token */
123 dma_addr_t phys_addr; /* physical address of the ring */
124 struct sk_buff_head sendq; /* List of backpressured offload packets */
125 struct tasklet_struct qresume_tsk; /* restarts the queue */
126 unsigned int cntxt_id; /* SGE context id for the Tx q */
127 unsigned long stops; /* # of times q has been stopped */
128 unsigned long restarts; /* # of queue restarts */
131 enum { /* per port SGE statistics */
132 SGE_PSTAT_TSO, /* # of TSO requests */
133 SGE_PSTAT_RX_CSUM_GOOD, /* # of successful RX csum offloads */
134 SGE_PSTAT_TX_CSUM, /* # of TX checksum offloads */
135 SGE_PSTAT_VLANEX, /* # of VLAN tag extractions */
136 SGE_PSTAT_VLANINS, /* # of VLAN tag insertions */
138 SGE_PSTAT_MAX /* must be last */
141 struct sge_qset { /* an SGE queue set */
142 struct sge_rspq rspq;
143 struct sge_fl fl[SGE_RXQ_PER_SET];
144 struct sge_txq txq[SGE_TXQ_PER_SET];
145 struct net_device *netdev; /* associated net device */
146 unsigned long txq_stopped; /* which Tx queues are stopped */
147 struct timer_list tx_reclaim_timer; /* reclaims TX buffers */
148 unsigned long port_stats[SGE_PSTAT_MAX];
149 } ____cacheline_aligned;
152 struct sge_qset qs[SGE_QSETS];
153 spinlock_t reg_lock; /* guards non-atomic SGE registers (eg context) */
158 struct list_head adapter_list;
160 struct pci_dev *pdev;
161 unsigned long registered_device_map;
162 unsigned long open_device_map;
167 unsigned int mmio_len;
169 struct adapter_params params;
170 unsigned int slow_intr_mask;
171 unsigned long irq_stats[IRQ_NUM_STATS];
176 } msix_info[SGE_QSETS + 1];
185 struct net_device *port[MAX_NPORTS];
186 unsigned int check_task_cnt;
187 struct delayed_work adap_check_task;
188 struct work_struct ext_intr_handler_task;
191 * Dummy netdevices are needed when using multiple receive queues with
192 * NAPI as each netdevice can service only one queue.
194 struct net_device *dummy_netdev[SGE_QSETS - 1];
196 struct dentry *debugfs_root;
198 struct mutex mdio_lock;
199 spinlock_t stats_lock;
200 spinlock_t work_lock;
203 static inline u32 t3_read_reg(struct adapter *adapter, u32 reg_addr)
205 u32 val = readl(adapter->regs + reg_addr);
207 CH_DBG(adapter, MMIO, "read register 0x%x value 0x%x\n", reg_addr, val);
211 static inline void t3_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
213 CH_DBG(adapter, MMIO, "setting register 0x%x to 0x%x\n", reg_addr, val);
214 writel(val, adapter->regs + reg_addr);
217 static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
219 return netdev_priv(adap->port[idx]);
223 * We use the spare atalk_ptr to map a net device to its SGE queue set.
224 * This is a macro so it can be used as l-value.
226 #define dev2qset(netdev) ((netdev)->atalk_ptr)
228 #define OFFLOAD_DEVMAP_BIT 15
230 #define tdev2adap(d) container_of(d, struct adapter, tdev)
232 static inline int offload_running(struct adapter *adapter)
234 return test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
237 int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb);
239 void t3_os_ext_intr_handler(struct adapter *adapter);
240 void t3_os_link_changed(struct adapter *adapter, int port_id, int link_status,
241 int speed, int duplex, int fc);
243 void t3_sge_start(struct adapter *adap);
244 void t3_sge_stop(struct adapter *adap);
245 void t3_free_sge_resources(struct adapter *adap);
246 void t3_sge_err_intr_handler(struct adapter *adapter);
247 intr_handler_t t3_intr_handler(struct adapter *adap, int polling);
248 int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev);
249 int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
250 void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
251 int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
252 int irq_vec_idx, const struct qset_params *p,
253 int ntxq, struct net_device *netdev);
254 int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
255 unsigned char *data);
256 irqreturn_t t3_sge_intr_msix(int irq, void *cookie);
258 #endif /* __T3_ADAPTER_H__ */