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 __CXGB4_H__
36#define __CXGB4_H__
37
38#include <linux/bitops.h>
39#include <linux/cache.h>
40#include <linux/interrupt.h>
41#include <linux/list.h>
42#include <linux/netdevice.h>
43#include <linux/pci.h>
44#include <linux/spinlock.h>
45#include <linux/timer.h>
46#include <asm/io.h>
47#include "cxgb4_uld.h"
48#include "t4_hw.h"
49
50#define FW_VERSION_MAJOR 1
51#define FW_VERSION_MINOR 1
52#define FW_VERSION_MICRO 0
53
54enum {
55 MAX_NPORTS = 4,
56 SERNUM_LEN = 24,
57 EC_LEN = 16,
58 ID_LEN = 16,
59};
60
61enum {
62 MEM_EDC0,
63 MEM_EDC1,
64 MEM_MC
65};
66
67enum dev_master {
68 MASTER_CANT,
69 MASTER_MAY,
70 MASTER_MUST
71};
72
73enum dev_state {
74 DEV_STATE_UNINIT,
75 DEV_STATE_INIT,
76 DEV_STATE_ERR
77};
78
79enum {
80 PAUSE_RX = 1 << 0,
81 PAUSE_TX = 1 << 1,
82 PAUSE_AUTONEG = 1 << 2
83};
84
85struct port_stats {
86 u64 tx_octets;
87 u64 tx_frames;
88 u64 tx_bcast_frames;
89 u64 tx_mcast_frames;
90 u64 tx_ucast_frames;
91 u64 tx_error_frames;
92
93 u64 tx_frames_64;
94 u64 tx_frames_65_127;
95 u64 tx_frames_128_255;
96 u64 tx_frames_256_511;
97 u64 tx_frames_512_1023;
98 u64 tx_frames_1024_1518;
99 u64 tx_frames_1519_max;
100
101 u64 tx_drop;
102 u64 tx_pause;
103 u64 tx_ppp0;
104 u64 tx_ppp1;
105 u64 tx_ppp2;
106 u64 tx_ppp3;
107 u64 tx_ppp4;
108 u64 tx_ppp5;
109 u64 tx_ppp6;
110 u64 tx_ppp7;
111
112 u64 rx_octets;
113 u64 rx_frames;
114 u64 rx_bcast_frames;
115 u64 rx_mcast_frames;
116 u64 rx_ucast_frames;
117 u64 rx_too_long;
118 u64 rx_jabber;
119 u64 rx_fcs_err;
120 u64 rx_len_err;
121 u64 rx_symbol_err;
122 u64 rx_runt;
123
124 u64 rx_frames_64;
125 u64 rx_frames_65_127;
126 u64 rx_frames_128_255;
127 u64 rx_frames_256_511;
128 u64 rx_frames_512_1023;
129 u64 rx_frames_1024_1518;
130 u64 rx_frames_1519_max;
131
132 u64 rx_pause;
133 u64 rx_ppp0;
134 u64 rx_ppp1;
135 u64 rx_ppp2;
136 u64 rx_ppp3;
137 u64 rx_ppp4;
138 u64 rx_ppp5;
139 u64 rx_ppp6;
140 u64 rx_ppp7;
141
142 u64 rx_ovflow0;
143 u64 rx_ovflow1;
144 u64 rx_ovflow2;
145 u64 rx_ovflow3;
146 u64 rx_trunc0;
147 u64 rx_trunc1;
148 u64 rx_trunc2;
149 u64 rx_trunc3;
150};
151
152struct lb_port_stats {
153 u64 octets;
154 u64 frames;
155 u64 bcast_frames;
156 u64 mcast_frames;
157 u64 ucast_frames;
158 u64 error_frames;
159
160 u64 frames_64;
161 u64 frames_65_127;
162 u64 frames_128_255;
163 u64 frames_256_511;
164 u64 frames_512_1023;
165 u64 frames_1024_1518;
166 u64 frames_1519_max;
167
168 u64 drop;
169
170 u64 ovflow0;
171 u64 ovflow1;
172 u64 ovflow2;
173 u64 ovflow3;
174 u64 trunc0;
175 u64 trunc1;
176 u64 trunc2;
177 u64 trunc3;
178};
179
180struct tp_tcp_stats {
181 u32 tcpOutRsts;
182 u64 tcpInSegs;
183 u64 tcpOutSegs;
184 u64 tcpRetransSegs;
185};
186
187struct tp_err_stats {
188 u32 macInErrs[4];
189 u32 hdrInErrs[4];
190 u32 tcpInErrs[4];
191 u32 tnlCongDrops[4];
192 u32 ofldChanDrops[4];
193 u32 tnlTxDrops[4];
194 u32 ofldVlanDrops[4];
195 u32 tcp6InErrs[4];
196 u32 ofldNoNeigh;
197 u32 ofldCongDefer;
198};
199
200struct tp_params {
201 unsigned int ntxchan;
202 unsigned int tre;
203};
204
205struct vpd_params {
206 unsigned int cclk;
207 u8 ec[EC_LEN + 1];
208 u8 sn[SERNUM_LEN + 1];
209 u8 id[ID_LEN + 1];
210};
211
212struct pci_params {
213 unsigned char speed;
214 unsigned char width;
215};
216
217struct adapter_params {
218 struct tp_params tp;
219 struct vpd_params vpd;
220 struct pci_params pci;
221
222 unsigned int sf_size;
223 unsigned int sf_nsec;
224 unsigned int sf_fw_start;
225
226 unsigned int fw_vers;
227 unsigned int tp_vers;
228 u8 api_vers[7];
229
230 unsigned short mtus[NMTUS];
231 unsigned short a_wnd[NCCTRL_WIN];
232 unsigned short b_wnd[NCCTRL_WIN];
233
234 unsigned char nports;
235 unsigned char portvec;
236 unsigned char rev;
237 unsigned char offload;
238
239 unsigned int ofldq_wr_cred;
240};
241
242struct trace_params {
243 u32 data[TRACE_LEN / 4];
244 u32 mask[TRACE_LEN / 4];
245 unsigned short snap_len;
246 unsigned short min_len;
247 unsigned char skip_ofst;
248 unsigned char skip_len;
249 unsigned char invert;
250 unsigned char port;
251};
252
253struct link_config {
254 unsigned short supported;
255 unsigned short advertising;
256 unsigned short requested_speed;
257 unsigned short speed;
258 unsigned char requested_fc;
259 unsigned char fc;
260 unsigned char autoneg;
261 unsigned char link_ok;
262};
263
264#define FW_LEN16(fw_struct) FW_CMD_LEN16(sizeof(fw_struct) / 16)
265
266enum {
267 MAX_ETH_QSETS = 32,
268 MAX_OFLD_QSETS = 16,
269 MAX_CTRL_QUEUES = NCHAN,
270 MAX_RDMA_QUEUES = NCHAN,
271};
272
273enum {
274 MAX_EGRQ = 128,
275 MAX_INGQ = 64
276};
277
278struct adapter;
279struct vlan_group;
280struct sge_rspq;
281
282struct port_info {
283 struct adapter *adapter;
284 u16 viid;
285 s16 xact_addr_filt;
286 u16 rss_size;
287 s8 mdio_addr;
288 u8 port_type;
289 u8 mod_type;
290 u8 port_id;
291 u8 tx_chan;
292 u8 lport;
293 u8 rx_offload;
294 u8 nqsets;
295 u8 first_qset;
296 u8 rss_mode;
297 struct link_config link_cfg;
298 u16 *rss;
299};
300
301
302enum {
303 RX_CSO = 1 << 0,
304};
305
306struct dentry;
307struct work_struct;
308
309enum {
310 FULL_INIT_DONE = (1 << 0),
311 USING_MSI = (1 << 1),
312 USING_MSIX = (1 << 2),
313 FW_OK = (1 << 4),
314};
315
316struct rx_sw_desc;
317
318struct sge_fl {
319 unsigned int avail;
320 unsigned int pend_cred;
321 unsigned int cidx;
322 unsigned int pidx;
323 unsigned long alloc_failed;
324 unsigned long large_alloc_failed;
325 unsigned long starving;
326
327 unsigned int cntxt_id;
328 unsigned int size;
329 struct rx_sw_desc *sdesc;
330 __be64 *desc;
331 dma_addr_t addr;
332};
333
334
335struct pkt_gl {
336 skb_frag_t frags[MAX_SKB_FRAGS];
337 void *va;
338 unsigned int nfrags;
339 unsigned int tot_len;
340};
341
342typedef int (*rspq_handler_t)(struct sge_rspq *q, const __be64 *rsp,
343 const struct pkt_gl *gl);
344
345struct sge_rspq {
346 struct napi_struct napi;
347 const __be64 *cur_desc;
348 unsigned int cidx;
349 u8 gen;
350 u8 intr_params;
351 u8 next_intr_params;
352 u8 pktcnt_idx;
353 u8 uld;
354 u8 idx;
355 int offset;
356 u16 cntxt_id;
357 u16 abs_id;
358 __be64 *desc;
359 dma_addr_t phys_addr;
360 unsigned int iqe_len;
361 unsigned int size;
362 struct adapter *adap;
363 struct net_device *netdev;
364 rspq_handler_t handler;
365};
366
367struct sge_eth_stats {
368 unsigned long pkts;
369 unsigned long lro_pkts;
370 unsigned long lro_merged;
371 unsigned long rx_cso;
372 unsigned long vlan_ex;
373 unsigned long rx_drops;
374};
375
376struct sge_eth_rxq {
377 struct sge_rspq rspq;
378 struct sge_fl fl;
379 struct sge_eth_stats stats;
380} ____cacheline_aligned_in_smp;
381
382struct sge_ofld_stats {
383 unsigned long pkts;
384 unsigned long imm;
385 unsigned long an;
386 unsigned long nomem;
387};
388
389struct sge_ofld_rxq {
390 struct sge_rspq rspq;
391 struct sge_fl fl;
392 struct sge_ofld_stats stats;
393} ____cacheline_aligned_in_smp;
394
395struct tx_desc {
396 __be64 flit[8];
397};
398
399struct tx_sw_desc;
400
401struct sge_txq {
402 unsigned int in_use;
403 unsigned int size;
404 unsigned int cidx;
405 unsigned int pidx;
406 unsigned long stops;
407 unsigned long restarts;
408 unsigned int cntxt_id;
409 struct tx_desc *desc;
410 struct tx_sw_desc *sdesc;
411 struct sge_qstat *stat;
412 dma_addr_t phys_addr;
413};
414
415struct sge_eth_txq {
416 struct sge_txq q;
417 struct netdev_queue *txq;
418 unsigned long tso;
419 unsigned long tx_cso;
420 unsigned long vlan_ins;
421 unsigned long mapping_err;
422} ____cacheline_aligned_in_smp;
423
424struct sge_ofld_txq {
425 struct sge_txq q;
426 struct adapter *adap;
427 struct sk_buff_head sendq;
428 struct tasklet_struct qresume_tsk;
429 u8 full;
430 unsigned long mapping_err;
431} ____cacheline_aligned_in_smp;
432
433struct sge_ctrl_txq {
434 struct sge_txq q;
435 struct adapter *adap;
436 struct sk_buff_head sendq;
437 struct tasklet_struct qresume_tsk;
438 u8 full;
439} ____cacheline_aligned_in_smp;
440
441struct sge {
442 struct sge_eth_txq ethtxq[MAX_ETH_QSETS];
443 struct sge_ofld_txq ofldtxq[MAX_OFLD_QSETS];
444 struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
445
446 struct sge_eth_rxq ethrxq[MAX_ETH_QSETS];
447 struct sge_ofld_rxq ofldrxq[MAX_OFLD_QSETS];
448 struct sge_ofld_rxq rdmarxq[MAX_RDMA_QUEUES];
449 struct sge_rspq fw_evtq ____cacheline_aligned_in_smp;
450
451 struct sge_rspq intrq ____cacheline_aligned_in_smp;
452 spinlock_t intrq_lock;
453
454 u16 max_ethqsets;
455 u16 ethqsets;
456 u16 ethtxq_rover;
457 u16 ofldqsets;
458 u16 rdmaqs;
459 u16 ofld_rxq[MAX_OFLD_QSETS];
460 u16 rdma_rxq[NCHAN];
461 u16 timer_val[SGE_NTIMERS];
462 u8 counter_val[SGE_NCOUNTERS];
463 unsigned int starve_thres;
464 u8 idma_state[2];
465 unsigned int egr_start;
466 unsigned int ingr_start;
467 void *egr_map[MAX_EGRQ];
468 struct sge_rspq *ingr_map[MAX_INGQ];
469 DECLARE_BITMAP(starving_fl, MAX_EGRQ);
470 DECLARE_BITMAP(txq_maperr, MAX_EGRQ);
471 struct timer_list rx_timer;
472 struct timer_list tx_timer;
473};
474
475#define for_each_ethrxq(sge, i) for (i = 0; i < (sge)->ethqsets; i++)
476#define for_each_ofldrxq(sge, i) for (i = 0; i < (sge)->ofldqsets; i++)
477#define for_each_rdmarxq(sge, i) for (i = 0; i < (sge)->rdmaqs; i++)
478
479struct l2t_data;
480
481struct adapter {
482 void __iomem *regs;
483 struct pci_dev *pdev;
484 struct device *pdev_dev;
485 unsigned int fn;
486 unsigned int flags;
487
488 int msg_enable;
489
490 struct adapter_params params;
491 struct cxgb4_virt_res vres;
492 unsigned int swintr;
493
494 unsigned int wol;
495
496 struct {
497 unsigned short vec;
498 char desc[IFNAMSIZ + 10];
499 } msix_info[MAX_INGQ + 1];
500
501 struct sge sge;
502
503 struct net_device *port[MAX_NPORTS];
504 u8 chan_map[NCHAN];
505
506 struct l2t_data *l2t;
507 void *uld_handle[CXGB4_ULD_MAX];
508 struct list_head list_node;
509
510 struct tid_info tids;
511 void **tid_release_head;
512 spinlock_t tid_release_lock;
513 struct work_struct tid_release_task;
514 bool tid_release_task_busy;
515
516 struct dentry *debugfs_root;
517
518 spinlock_t stats_lock;
519};
520
521static inline u32 t4_read_reg(struct adapter *adap, u32 reg_addr)
522{
523 return readl(adap->regs + reg_addr);
524}
525
526static inline void t4_write_reg(struct adapter *adap, u32 reg_addr, u32 val)
527{
528 writel(val, adap->regs + reg_addr);
529}
530
531#ifndef readq
532static inline u64 readq(const volatile void __iomem *addr)
533{
534 return readl(addr) + ((u64)readl(addr + 4) << 32);
535}
536
537static inline void writeq(u64 val, volatile void __iomem *addr)
538{
539 writel(val, addr);
540 writel(val >> 32, addr + 4);
541}
542#endif
543
544static inline u64 t4_read_reg64(struct adapter *adap, u32 reg_addr)
545{
546 return readq(adap->regs + reg_addr);
547}
548
549static inline void t4_write_reg64(struct adapter *adap, u32 reg_addr, u64 val)
550{
551 writeq(val, adap->regs + reg_addr);
552}
553
554
555
556
557
558
559
560static inline struct port_info *netdev2pinfo(const struct net_device *dev)
561{
562 return netdev_priv(dev);
563}
564
565
566
567
568
569
570
571
572static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
573{
574 return netdev_priv(adap->port[idx]);
575}
576
577
578
579
580
581
582
583static inline struct adapter *netdev2adap(const struct net_device *dev)
584{
585 return netdev2pinfo(dev)->adapter;
586}
587
588void t4_os_portmod_changed(const struct adapter *adap, int port_id);
589void t4_os_link_changed(struct adapter *adap, int port_id, int link_stat);
590
591void *t4_alloc_mem(size_t size);
592
593void t4_free_sge_resources(struct adapter *adap);
594irq_handler_t t4_intr_handler(struct adapter *adap);
595netdev_tx_t t4_eth_xmit(struct sk_buff *skb, struct net_device *dev);
596int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
597 const struct pkt_gl *gl);
598int t4_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
599int t4_ofld_send(struct adapter *adap, struct sk_buff *skb);
600int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *iq, bool fwevtq,
601 struct net_device *dev, int intr_idx,
602 struct sge_fl *fl, rspq_handler_t hnd);
603int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
604 struct net_device *dev, struct netdev_queue *netdevq,
605 unsigned int iqid);
606int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq,
607 struct net_device *dev, unsigned int iqid,
608 unsigned int cmplqid);
609int t4_sge_alloc_ofld_txq(struct adapter *adap, struct sge_ofld_txq *txq,
610 struct net_device *dev, unsigned int iqid);
611irqreturn_t t4_sge_intr_msix(int irq, void *cookie);
612void t4_sge_init(struct adapter *adap);
613void t4_sge_start(struct adapter *adap);
614void t4_sge_stop(struct adapter *adap);
615
616#define for_each_port(adapter, iter) \
617 for (iter = 0; iter < (adapter)->params.nports; ++iter)
618
619static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
620{
621 return adap->params.vpd.cclk / 1000;
622}
623
624static inline unsigned int us_to_core_ticks(const struct adapter *adap,
625 unsigned int us)
626{
627 return (us * adap->params.vpd.cclk) / 1000;
628}
629
630void t4_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask,
631 u32 val);
632
633int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
634 void *rpl, bool sleep_ok);
635
636static inline int t4_wr_mbox(struct adapter *adap, int mbox, const void *cmd,
637 int size, void *rpl)
638{
639 return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, true);
640}
641
642static inline int t4_wr_mbox_ns(struct adapter *adap, int mbox, const void *cmd,
643 int size, void *rpl)
644{
645 return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, false);
646}
647
648void t4_intr_enable(struct adapter *adapter);
649void t4_intr_disable(struct adapter *adapter);
650int t4_slow_intr_handler(struct adapter *adapter);
651
652int t4_wait_dev_ready(struct adapter *adap);
653int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
654 struct link_config *lc);
655int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port);
656int t4_seeprom_wp(struct adapter *adapter, bool enable);
657int t4_load_fw(struct adapter *adapter, const u8 *fw_data, unsigned int size);
658int t4_check_fw_version(struct adapter *adapter);
659int t4_prep_adapter(struct adapter *adapter);
660int t4_port_init(struct adapter *adap, int mbox, int pf, int vf);
661void t4_fatal_err(struct adapter *adapter);
662int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
663 int start, int n, const u16 *rspq, unsigned int nrspq);
664int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
665 unsigned int flags);
666int t4_mc_read(struct adapter *adap, u32 addr, __be32 *data, u64 *parity);
667int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data,
668 u64 *parity);
669
670void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p);
671void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log);
672void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
673 struct tp_tcp_stats *v6);
674void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
675 const unsigned short *alpha, const unsigned short *beta);
676
677void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
678 const u8 *addr);
679int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
680 u64 mask0, u64 mask1, unsigned int crc, bool enable);
681
682int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
683 enum dev_master master, enum dev_state *state);
684int t4_fw_bye(struct adapter *adap, unsigned int mbox);
685int t4_early_init(struct adapter *adap, unsigned int mbox);
686int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset);
687int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
688 unsigned int vf, unsigned int nparams, const u32 *params,
689 u32 *val);
690int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
691 unsigned int vf, unsigned int nparams, const u32 *params,
692 const u32 *val);
693int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
694 unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
695 unsigned int rxqi, unsigned int rxq, unsigned int tc,
696 unsigned int vi, unsigned int cmask, unsigned int pmask,
697 unsigned int nexact, unsigned int rcaps, unsigned int wxcaps);
698int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
699 unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
700 unsigned int *rss_size);
701int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
702 int mtu, int promisc, int all_multi, int bcast, int vlanex,
703 bool sleep_ok);
704int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
705 unsigned int viid, bool free, unsigned int naddr,
706 const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok);
707int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
708 int idx, const u8 *addr, bool persist, bool add_smt);
709int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
710 bool ucast, u64 vec, bool sleep_ok);
711int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
712 bool rx_en, bool tx_en);
713int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
714 unsigned int nblinks);
715int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
716 unsigned int mmd, unsigned int reg, u16 *valp);
717int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
718 unsigned int mmd, unsigned int reg, u16 val);
719int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
720 unsigned int vf, unsigned int iqtype, unsigned int iqid,
721 unsigned int fl0id, unsigned int fl1id);
722int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
723 unsigned int vf, unsigned int eqid);
724int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
725 unsigned int vf, unsigned int eqid);
726int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
727 unsigned int vf, unsigned int eqid);
728int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl);
729#endif
730