adapter.h 10.9 KB
Newer Older
1
/*
D
Divy Le Ray 已提交
2
 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3
 *
D
Divy Le Ray 已提交
4 5 6 7 8
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
9
 *
D
Divy Le Ray 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
31 32 33 34 35 36 37 38 39 40 41 42
 */

/* This file should not be included directly.  Include common.h instead. */

#ifndef __T3_ADAPTER_H__
#define __T3_ADAPTER_H__

#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/cache.h>
D
Divy Le Ray 已提交
43
#include <linux/mutex.h>
J
Jiri Slaby 已提交
44
#include <linux/bitops.h>
45 46 47
#include "t3cdev.h"
#include <asm/io.h>

D
Divy Le Ray 已提交
48
struct adapter;
49
struct sge_qset;
50
struct port_info;
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65
enum mac_idx_types {
	LAN_MAC_IDX	= 0,
	SAN_MAC_IDX,

	MAX_MAC_IDX
};

struct iscsi_config {
	__u8	mac_addr[ETH_ALEN];
	__u32	flags;
	int (*send)(struct port_info *pi, struct sk_buff **skb);
	int (*recv)(struct port_info *pi, struct sk_buff *skb);
};

66
struct port_info {
D
Divy Le Ray 已提交
67
	struct adapter *adapter;
68
	struct sge_qset *qs;
69 70 71 72 73 74 75 76
	u8 port_id;
	u8 nqsets;
	u8 first_qset;
	struct cphy phy;
	struct cmac mac;
	struct link_config link_config;
	struct net_device_stats netstats;
	int activity;
K
Karen Xie 已提交
77
	__be32 iscsi_ipv4addr;
78
	struct iscsi_config iscsic;
D
Divy Le Ray 已提交
79 80

	int link_fault; /* link fault was detected */
81 82 83 84 85 86
};

enum {				/* adapter flags */
	FULL_INIT_DONE = (1 << 0),
	USING_MSI = (1 << 1),
	USING_MSIX = (1 << 2),
87
	QUEUES_BOUND = (1 << 3),
88
	TP_PARITY_INIT = (1 << 4),
89
	NAPI_INIT = (1 << 5),
90 91
};

D
Divy Le Ray 已提交
92 93 94 95
struct fl_pg_chunk {
	struct page *page;
	void *va;
	unsigned int offset;
D
Divy Le Ray 已提交
96 97
	unsigned long *p_cnt;
	dma_addr_t mapping;
D
Divy Le Ray 已提交
98 99
};

100 101 102
struct rx_desc;
struct rx_sw_desc;

D
Divy Le Ray 已提交
103 104 105
struct sge_fl {                     /* SGE per free-buffer list state */
	unsigned int buf_size;      /* size of each Rx buffer */
	unsigned int credits;       /* # of available Rx buffers */
106
	unsigned int pend_cred;     /* new buffers since last FL DB ring */
D
Divy Le Ray 已提交
107 108 109 110 111 112
	unsigned int size;          /* capacity of free list */
	unsigned int cidx;          /* consumer index */
	unsigned int pidx;          /* producer index */
	unsigned int gen;           /* free list generation */
	struct fl_pg_chunk pg_chunk;/* page chunk cache */
	unsigned int use_pages;     /* whether FL uses pages or sk_buffs */
113
	unsigned int order;	    /* order of page allocations */
114
	unsigned int alloc_size;    /* size of allocated buffer */
D
Divy Le Ray 已提交
115 116 117 118 119
	struct rx_desc *desc;       /* address of HW Rx descriptor ring */
	struct rx_sw_desc *sdesc;   /* address of SW Rx descriptor ring */
	dma_addr_t   phys_addr;     /* physical address of HW ring start */
	unsigned int cntxt_id;      /* SGE context id for the free list */
	unsigned long empty;        /* # of times queue ran out of buffers */
120
	unsigned long alloc_failed; /* # of times buffer allocation failed */
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
};

/*
 * Bundle size for grouping offload RX packets for delivery to the stack.
 * Don't make this too big as we do prefetch on each packet in a bundle.
 */
# define RX_BUNDLE_SIZE 8

struct rsp_desc;

struct sge_rspq {		/* state for an SGE response queue */
	unsigned int credits;	/* # of pending response credits */
	unsigned int size;	/* capacity of response queue */
	unsigned int cidx;	/* consumer index */
	unsigned int gen;	/* current generation bit */
	unsigned int polling;	/* is the queue serviced through NAPI? */
	unsigned int holdoff_tmr;	/* interrupt holdoff timer in 100ns */
	unsigned int next_holdoff;	/* holdoff time for next interrupt */
139 140
	unsigned int rx_recycle_buf; /* whether recycling occurred
					within current sop-eop */
141 142 143 144
	struct rsp_desc *desc;	/* address of HW response ring */
	dma_addr_t phys_addr;	/* physical address of the ring */
	unsigned int cntxt_id;	/* SGE context id for the response q */
	spinlock_t lock;	/* guards response processing */
145
	struct sk_buff_head rx_queue; /* offload packet receive queue */
146
	struct sk_buff *pg_skb; /* used to build frag list in napi handler */
147 148 149 150 151 152 153 154 155 156 157

	unsigned long offload_pkts;
	unsigned long offload_bundles;
	unsigned long eth_pkts;	/* # of ethernet packets */
	unsigned long pure_rsps;	/* # of pure (non-data) responses */
	unsigned long imm_data;	/* responses with immediate data */
	unsigned long rx_drops;	/* # of packets dropped due to no mem */
	unsigned long async_notif; /* # of asynchronous notification events */
	unsigned long empty;	/* # of times queue ran out of credits */
	unsigned long nomem;	/* # of responses deferred due to no mem */
	unsigned long unhandled_irqs;	/* # of spurious intrs */
158 159
	unsigned long starved;
	unsigned long restarted;
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
};

struct tx_desc;
struct tx_sw_desc;

struct sge_txq {		/* state for an SGE Tx queue */
	unsigned long flags;	/* HW DMA fetch status */
	unsigned int in_use;	/* # of in-use Tx descriptors */
	unsigned int size;	/* # of descriptors */
	unsigned int processed;	/* total # of descs HW has processed */
	unsigned int cleaned;	/* total # of descs SW has reclaimed */
	unsigned int stop_thres;	/* SW TX queue suspend threshold */
	unsigned int cidx;	/* consumer index */
	unsigned int pidx;	/* producer index */
	unsigned int gen;	/* current value of generation bit */
	unsigned int unacked;	/* Tx descriptors used since last COMPL */
	struct tx_desc *desc;	/* address of HW Tx descriptor ring */
	struct tx_sw_desc *sdesc;	/* address of SW Tx descriptor ring */
	spinlock_t lock;	/* guards enqueueing of new packets */
	unsigned int token;	/* WR token */
	dma_addr_t phys_addr;	/* physical address of the ring */
	struct sk_buff_head sendq;	/* List of backpressured offload packets */
	struct tasklet_struct qresume_tsk;	/* restarts the queue */
	unsigned int cntxt_id;	/* SGE context id for the Tx q */
	unsigned long stops;	/* # of times q has been stopped */
	unsigned long restarts;	/* # of queue restarts */
};

enum {				/* per port SGE statistics */
	SGE_PSTAT_TSO,		/* # of TSO requests */
	SGE_PSTAT_RX_CSUM_GOOD,	/* # of successful RX csum offloads */
	SGE_PSTAT_TX_CSUM,	/* # of TX checksum offloads */
	SGE_PSTAT_VLANEX,	/* # of VLAN tag extractions */
	SGE_PSTAT_VLANINS,	/* # of VLAN tag insertions */

	SGE_PSTAT_MAX		/* must be last */
};

H
Herbert Xu 已提交
198
struct napi_gro_fraginfo;
D
Divy Le Ray 已提交
199

200
struct sge_qset {		/* an SGE queue set */
201 202
	struct adapter *adap;
	struct napi_struct napi;
203 204 205
	struct sge_rspq rspq;
	struct sge_fl fl[SGE_RXQ_PER_SET];
	struct sge_txq txq[SGE_TXQ_PER_SET];
206
	int nomem;
D
Divy Le Ray 已提交
207
	void *lro_va;
208
	struct net_device *netdev;
209
	struct netdev_queue *tx_q;	/* associated netdev TX queue */
210 211
	unsigned long txq_stopped;	/* which Tx queues are stopped */
	struct timer_list tx_reclaim_timer;	/* reclaims TX buffers */
212
	struct timer_list rx_reclaim_timer;	/* reclaims RX buffers */
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
	unsigned long port_stats[SGE_PSTAT_MAX];
} ____cacheline_aligned;

struct sge {
	struct sge_qset qs[SGE_QSETS];
	spinlock_t reg_lock;	/* guards non-atomic SGE registers (eg context) */
};

struct adapter {
	struct t3cdev tdev;
	struct list_head adapter_list;
	void __iomem *regs;
	struct pci_dev *pdev;
	unsigned long registered_device_map;
	unsigned long open_device_map;
	unsigned long flags;

	const char *name;
	int msg_enable;
	unsigned int mmio_len;

	struct adapter_params params;
	unsigned int slow_intr_mask;
	unsigned long irq_stats[IRQ_NUM_STATS];

238
	int msix_nvectors;
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
	struct {
		unsigned short vec;
		char desc[22];
	} msix_info[SGE_QSETS + 1];

	/* T3 modules */
	struct sge sge;
	struct mc7 pmrx;
	struct mc7 pmtx;
	struct mc7 cm;
	struct mc5 mc5;

	struct net_device *port[MAX_NPORTS];
	unsigned int check_task_cnt;
	struct delayed_work adap_check_task;
	struct work_struct ext_intr_handler_task;
255
	struct work_struct fatal_error_handler_task;
D
Divy Le Ray 已提交
256
	struct work_struct link_fault_handler_task;
257

258 259 260 261
	struct work_struct db_full_task;
	struct work_struct db_empty_task;
	struct work_struct db_drop_task;

262 263 264 265 266
	struct dentry *debugfs_root;

	struct mutex mdio_lock;
	spinlock_t stats_lock;
	spinlock_t work_lock;
D
Divy Le Ray 已提交
267 268

	struct sk_buff *nofail_skb;
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
};

static inline u32 t3_read_reg(struct adapter *adapter, u32 reg_addr)
{
	u32 val = readl(adapter->regs + reg_addr);

	CH_DBG(adapter, MMIO, "read register 0x%x value 0x%x\n", reg_addr, val);
	return val;
}

static inline void t3_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
{
	CH_DBG(adapter, MMIO, "setting register 0x%x to 0x%x\n", reg_addr, val);
	writel(val, adapter->regs + reg_addr);
}

static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
{
	return netdev_priv(adap->port[idx]);
}

D
Divy Le Ray 已提交
290 291 292 293 294 295 296 297
static inline int phy2portid(struct cphy *phy)
{
	struct adapter *adap = phy->adapter;
	struct port_info *port0 = adap2pinfo(adap, 0);

	return &port0->phy == phy ? 0 : 1;
}

298 299 300 301 302 303 304 305 306 307 308 309 310 311
#define OFFLOAD_DEVMAP_BIT 15

#define tdev2adap(d) container_of(d, struct adapter, tdev)

static inline int offload_running(struct adapter *adapter)
{
	return test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
}

int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb);

void t3_os_ext_intr_handler(struct adapter *adapter);
void t3_os_link_changed(struct adapter *adapter, int port_id, int link_status,
			int speed, int duplex, int fc);
312
void t3_os_phymod_changed(struct adapter *adap, int port_id);
D
Divy Le Ray 已提交
313 314
void t3_os_link_fault(struct adapter *adapter, int port_id, int state);
void t3_os_link_fault_handler(struct adapter *adapter, int port_id);
315 316 317

void t3_sge_start(struct adapter *adap);
void t3_sge_stop(struct adapter *adap);
318
void t3_start_sge_timers(struct adapter *adap);
D
Divy Le Ray 已提交
319
void t3_stop_sge_timers(struct adapter *adap);
320 321
void t3_free_sge_resources(struct adapter *adap);
void t3_sge_err_intr_handler(struct adapter *adapter);
322
irq_handler_t t3_intr_handler(struct adapter *adap, int polling);
323
netdev_tx_t t3_eth_xmit(struct sk_buff *skb, struct net_device *dev);
324
int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
325 326 327
void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
		      int irq_vec_idx, const struct qset_params *p,
328 329
		      int ntxq, struct net_device *dev,
		      struct netdev_queue *netdevq);
330
extern struct workqueue_struct *cxgb3_wq;
331

332 333
int t3_get_edc_fw(struct cphy *phy, int edc_idx, int size);

334
#endif				/* __T3_ADAPTER_H__ */