1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef __T3_ADAPTER_H__
36#define __T3_ADAPTER_H__
37
38#include <linux/pci.h>
39#include <linux/spinlock.h>
40#include <linux/interrupt.h>
41#include <linux/timer.h>
42#include <linux/cache.h>
43#include <linux/mutex.h>
44#include <linux/bitops.h>
45#include "t3cdev.h"
46#include <asm/io.h>
47
48struct vlan_group;
49struct adapter;
50struct sge_qset;
51struct port_info;
52
53enum mac_idx_types {
54 LAN_MAC_IDX = 0,
55 SAN_MAC_IDX,
56
57 MAX_MAC_IDX
58};
59
60struct iscsi_config {
61 __u8 mac_addr[ETH_ALEN];
62 __u32 flags;
63 int (*send)(struct port_info *pi, struct sk_buff **skb);
64 int (*recv)(struct port_info *pi, struct sk_buff *skb);
65};
66
67struct port_info {
68 struct adapter *adapter;
69 struct vlan_group *vlan_grp;
70 struct sge_qset *qs;
71 u8 port_id;
72 u8 nqsets;
73 u8 first_qset;
74 struct cphy phy;
75 struct cmac mac;
76 struct link_config link_config;
77 struct net_device_stats netstats;
78 int activity;
79 __be32 iscsi_ipv4addr;
80 struct iscsi_config iscsic;
81
82 int link_fault;
83};
84
85enum {
86 FULL_INIT_DONE = (1 << 0),
87 USING_MSI = (1 << 1),
88 USING_MSIX = (1 << 2),
89 QUEUES_BOUND = (1 << 3),
90 TP_PARITY_INIT = (1 << 4),
91 NAPI_INIT = (1 << 5),
92};
93
94struct fl_pg_chunk {
95 struct page *page;
96 void *va;
97 unsigned int offset;
98 unsigned long *p_cnt;
99 dma_addr_t mapping;
100};
101
102struct rx_desc;
103struct rx_sw_desc;
104
105struct sge_fl {
106 unsigned int buf_size;
107 unsigned int credits;
108 unsigned int pend_cred;
109 unsigned int size;
110 unsigned int cidx;
111 unsigned int pidx;
112 unsigned int gen;
113 struct fl_pg_chunk pg_chunk;
114 unsigned int use_pages;
115 unsigned int order;
116 unsigned int alloc_size;
117 struct rx_desc *desc;
118 struct rx_sw_desc *sdesc;
119 dma_addr_t phys_addr;
120 unsigned int cntxt_id;
121 unsigned long empty;
122 unsigned long alloc_failed;
123};
124
125
126
127
128
129# define RX_BUNDLE_SIZE 8
130
131struct rsp_desc;
132
133struct sge_rspq {
134 unsigned int credits;
135 unsigned int size;
136 unsigned int cidx;
137 unsigned int gen;
138 unsigned int polling;
139 unsigned int holdoff_tmr;
140 unsigned int next_holdoff;
141 unsigned int rx_recycle_buf;
142
143 struct rsp_desc *desc;
144 dma_addr_t phys_addr;
145 unsigned int cntxt_id;
146 spinlock_t lock;
147 struct sk_buff_head rx_queue;
148 struct sk_buff *pg_skb;
149
150 unsigned long offload_pkts;
151 unsigned long offload_bundles;
152 unsigned long eth_pkts;
153 unsigned long pure_rsps;
154 unsigned long imm_data;
155 unsigned long rx_drops;
156 unsigned long async_notif;
157 unsigned long empty;
158 unsigned long nomem;
159 unsigned long unhandled_irqs;
160 unsigned long starved;
161 unsigned long restarted;
162};
163
164struct tx_desc;
165struct tx_sw_desc;
166
167struct sge_txq {
168 unsigned long flags;
169 unsigned int in_use;
170 unsigned int size;
171 unsigned int processed;
172 unsigned int cleaned;
173 unsigned int stop_thres;
174 unsigned int cidx;
175 unsigned int pidx;
176 unsigned int gen;
177 unsigned int unacked;
178 struct tx_desc *desc;
179 struct tx_sw_desc *sdesc;
180 spinlock_t lock;
181 unsigned int token;
182 dma_addr_t phys_addr;
183 struct sk_buff_head sendq;
184 struct tasklet_struct qresume_tsk;
185 unsigned int cntxt_id;
186 unsigned long stops;
187 unsigned long restarts;
188};
189
190enum {
191 SGE_PSTAT_TSO,
192 SGE_PSTAT_RX_CSUM_GOOD,
193 SGE_PSTAT_TX_CSUM,
194 SGE_PSTAT_VLANEX,
195 SGE_PSTAT_VLANINS,
196
197 SGE_PSTAT_MAX
198};
199
200struct napi_gro_fraginfo;
201
202struct sge_qset {
203 struct adapter *adap;
204 struct napi_struct napi;
205 struct sge_rspq rspq;
206 struct sge_fl fl[SGE_RXQ_PER_SET];
207 struct sge_txq txq[SGE_TXQ_PER_SET];
208 int nomem;
209 void *lro_va;
210 struct net_device *netdev;
211 struct netdev_queue *tx_q;
212 unsigned long txq_stopped;
213 struct timer_list tx_reclaim_timer;
214 struct timer_list rx_reclaim_timer;
215 unsigned long port_stats[SGE_PSTAT_MAX];
216} ____cacheline_aligned;
217
218struct sge {
219 struct sge_qset qs[SGE_QSETS];
220 spinlock_t reg_lock;
221};
222
223struct adapter {
224 struct t3cdev tdev;
225 struct list_head adapter_list;
226 void __iomem *regs;
227 struct pci_dev *pdev;
228 unsigned long registered_device_map;
229 unsigned long open_device_map;
230 unsigned long flags;
231
232 const char *name;
233 int msg_enable;
234 unsigned int mmio_len;
235
236 struct adapter_params params;
237 unsigned int slow_intr_mask;
238 unsigned long irq_stats[IRQ_NUM_STATS];
239
240 int msix_nvectors;
241 struct {
242 unsigned short vec;
243 char desc[22];
244 } msix_info[SGE_QSETS + 1];
245
246
247 struct sge sge;
248 struct mc7 pmrx;
249 struct mc7 pmtx;
250 struct mc7 cm;
251 struct mc5 mc5;
252
253 struct net_device *port[MAX_NPORTS];
254 unsigned int check_task_cnt;
255 struct delayed_work adap_check_task;
256 struct work_struct ext_intr_handler_task;
257 struct work_struct fatal_error_handler_task;
258 struct work_struct link_fault_handler_task;
259
260 struct work_struct db_full_task;
261 struct work_struct db_empty_task;
262 struct work_struct db_drop_task;
263
264 struct dentry *debugfs_root;
265
266 struct mutex mdio_lock;
267 spinlock_t stats_lock;
268 spinlock_t work_lock;
269
270 struct sk_buff *nofail_skb;
271};
272
273static inline u32 t3_read_reg(struct adapter *adapter, u32 reg_addr)
274{
275 u32 val = readl(adapter->regs + reg_addr);
276
277 CH_DBG(adapter, MMIO, "read register 0x%x value 0x%x\n", reg_addr, val);
278 return val;
279}
280
281static inline void t3_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
282{
283 CH_DBG(adapter, MMIO, "setting register 0x%x to 0x%x\n", reg_addr, val);
284 writel(val, adapter->regs + reg_addr);
285}
286
287static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
288{
289 return netdev_priv(adap->port[idx]);
290}
291
292static inline int phy2portid(struct cphy *phy)
293{
294 struct adapter *adap = phy->adapter;
295 struct port_info *port0 = adap2pinfo(adap, 0);
296
297 return &port0->phy == phy ? 0 : 1;
298}
299
300#define OFFLOAD_DEVMAP_BIT 15
301
302#define tdev2adap(d) container_of(d, struct adapter, tdev)
303
304static inline int offload_running(struct adapter *adapter)
305{
306 return test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
307}
308
309int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb);
310
311void t3_os_ext_intr_handler(struct adapter *adapter);
312void t3_os_link_changed(struct adapter *adapter, int port_id, int link_status,
313 int speed, int duplex, int fc);
314void t3_os_phymod_changed(struct adapter *adap, int port_id);
315void t3_os_link_fault(struct adapter *adapter, int port_id, int state);
316void t3_os_link_fault_handler(struct adapter *adapter, int port_id);
317
318void t3_sge_start(struct adapter *adap);
319void t3_sge_stop(struct adapter *adap);
320void t3_start_sge_timers(struct adapter *adap);
321void t3_stop_sge_timers(struct adapter *adap);
322void t3_free_sge_resources(struct adapter *adap);
323void t3_sge_err_intr_handler(struct adapter *adapter);
324irq_handler_t t3_intr_handler(struct adapter *adap, int polling);
325netdev_tx_t t3_eth_xmit(struct sk_buff *skb, struct net_device *dev);
326int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
327void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
328int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
329 int irq_vec_idx, const struct qset_params *p,
330 int ntxq, struct net_device *dev,
331 struct netdev_queue *netdevq);
332extern struct workqueue_struct *cxgb3_wq;
333
334int t3_get_edc_fw(struct cphy *phy, int edc_idx, int size);
335
336#endif
337