]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/ethernet/cavium/thunder/nic.h
net: thunderx: Moved HW capability info from macros to structure
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / cavium / thunder / nic.h
CommitLineData
4863dea3
SG
1/*
2 * Copyright (C) 2015 Cavium, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
7 */
8
9#ifndef NIC_H
10#define NIC_H
11
12#include <linux/netdevice.h>
13#include <linux/interrupt.h>
d768b678 14#include <linux/pci.h>
4863dea3
SG
15#include "thunder_bgx.h"
16
17/* PCI device IDs */
18#define PCI_DEVICE_ID_THUNDER_NIC_PF 0xA01E
19#define PCI_DEVICE_ID_THUNDER_PASS1_NIC_VF 0x0011
20#define PCI_DEVICE_ID_THUNDER_NIC_VF 0xA034
21#define PCI_DEVICE_ID_THUNDER_BGX 0xA026
22
a5c3d498
SG
23/* Subsystem device IDs */
24#define PCI_SUBSYS_DEVID_88XX_NIC_PF 0xA11E
25
4863dea3
SG
26/* PCI BAR nos */
27#define PCI_CFG_REG_BAR_NUM 0
28#define PCI_MSIX_REG_BAR_NUM 4
29
30/* NIC SRIOV VF count */
31#define MAX_NUM_VFS_SUPPORTED 128
32#define DEFAULT_NUM_VF_ENABLED 8
33
34#define NIC_TNS_BYPASS_MODE 0
35#define NIC_TNS_MODE 1
36
37/* NIC priv flags */
38#define NIC_SRIOV_ENABLED BIT(0)
39
40/* Min/Max packet size */
41#define NIC_HW_MIN_FRS 64
42#define NIC_HW_MAX_FRS 9200 /* 9216 max packet including FCS */
43
44/* Max pkinds */
45#define NIC_MAX_PKIND 16
46
a5c3d498
SG
47/* Max when CPI_ALG is IP diffserv */
48#define NIC_MAX_CPI_PER_LMAC 64
4863dea3
SG
49
50/* NIC VF Interrupts */
51#define NICVF_INTR_CQ 0
52#define NICVF_INTR_SQ 1
53#define NICVF_INTR_RBDR 2
54#define NICVF_INTR_PKT_DROP 3
55#define NICVF_INTR_TCP_TIMER 4
56#define NICVF_INTR_MBOX 5
57#define NICVF_INTR_QS_ERR 6
58
59#define NICVF_INTR_CQ_SHIFT 0
60#define NICVF_INTR_SQ_SHIFT 8
61#define NICVF_INTR_RBDR_SHIFT 16
62#define NICVF_INTR_PKT_DROP_SHIFT 20
63#define NICVF_INTR_TCP_TIMER_SHIFT 21
64#define NICVF_INTR_MBOX_SHIFT 22
65#define NICVF_INTR_QS_ERR_SHIFT 23
66
67#define NICVF_INTR_CQ_MASK (0xFF << NICVF_INTR_CQ_SHIFT)
68#define NICVF_INTR_SQ_MASK (0xFF << NICVF_INTR_SQ_SHIFT)
69#define NICVF_INTR_RBDR_MASK (0x03 << NICVF_INTR_RBDR_SHIFT)
70#define NICVF_INTR_PKT_DROP_MASK BIT(NICVF_INTR_PKT_DROP_SHIFT)
71#define NICVF_INTR_TCP_TIMER_MASK BIT(NICVF_INTR_TCP_TIMER_SHIFT)
72#define NICVF_INTR_MBOX_MASK BIT(NICVF_INTR_MBOX_SHIFT)
73#define NICVF_INTR_QS_ERR_MASK BIT(NICVF_INTR_QS_ERR_SHIFT)
74
75/* MSI-X interrupts */
76#define NIC_PF_MSIX_VECTORS 10
77#define NIC_VF_MSIX_VECTORS 20
78
79#define NIC_PF_INTR_ID_ECC0_SBE 0
80#define NIC_PF_INTR_ID_ECC0_DBE 1
81#define NIC_PF_INTR_ID_ECC1_SBE 2
82#define NIC_PF_INTR_ID_ECC1_DBE 3
83#define NIC_PF_INTR_ID_ECC2_SBE 4
84#define NIC_PF_INTR_ID_ECC2_DBE 5
85#define NIC_PF_INTR_ID_ECC3_SBE 6
86#define NIC_PF_INTR_ID_ECC3_DBE 7
87#define NIC_PF_INTR_ID_MBOX0 8
88#define NIC_PF_INTR_ID_MBOX1 9
89
4c0b6eaf
SG
90/* Minimum FIFO level before all packets for the CQ are dropped
91 *
92 * This value ensures that once a packet has been "accepted"
93 * for reception it will not get dropped due to non-availability
94 * of CQ descriptor. An errata in HW mandates this value to be
95 * atleast 0x100.
96 */
97#define NICPF_CQM_MIN_DROP_LEVEL 0x100
98
4863dea3
SG
99/* Global timer for CQ timer thresh interrupts
100 * Calculated for SCLK of 700Mhz
101 * value written should be a 1/16th of what is expected
102 *
006394a7 103 * 1 tick per 0.025usec
4863dea3 104 */
006394a7 105#define NICPF_CLK_PER_INT_TICK 1
4863dea3 106
3d7a8aaa
SG
107/* Time to wait before we decide that a SQ is stuck.
108 *
109 * Since both pkt rx and tx notifications are done with same CQ,
110 * when packets are being received at very high rate (eg: L2 forwarding)
111 * then freeing transmitted skbs will be delayed and watchdog
112 * will kick in, resetting interface. Hence keeping this value high.
113 */
114#define NICVF_TX_TIMEOUT (50 * HZ)
115
4863dea3 116struct nicvf_cq_poll {
39ad6eea 117 struct nicvf *nicvf;
4863dea3
SG
118 u8 cq_idx; /* Completion queue index */
119 struct napi_struct napi;
120};
121
4863dea3
SG
122#define NIC_MAX_RSS_HASH_BITS 8
123#define NIC_MAX_RSS_IDR_TBL_SIZE (1 << NIC_MAX_RSS_HASH_BITS)
124#define RSS_HASH_KEY_SIZE 5 /* 320 bit key */
125
126struct nicvf_rss_info {
127 bool enable;
128#define RSS_L2_EXTENDED_HASH_ENA BIT(0)
129#define RSS_IP_HASH_ENA BIT(1)
130#define RSS_TCP_HASH_ENA BIT(2)
131#define RSS_TCP_SYN_DIS BIT(3)
132#define RSS_UDP_HASH_ENA BIT(4)
133#define RSS_L4_EXTENDED_HASH_ENA BIT(5)
134#define RSS_ROCE_ENA BIT(6)
135#define RSS_L3_BI_DIRECTION_ENA BIT(7)
136#define RSS_L4_BI_DIRECTION_ENA BIT(8)
137 u64 cfg;
138 u8 hash_bits;
139 u16 rss_size;
140 u8 ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
141 u64 key[RSS_HASH_KEY_SIZE];
142} ____cacheline_aligned_in_smp;
143
144enum rx_stats_reg_offset {
145 RX_OCTS = 0x0,
146 RX_UCAST = 0x1,
147 RX_BCAST = 0x2,
148 RX_MCAST = 0x3,
149 RX_RED = 0x4,
150 RX_RED_OCTS = 0x5,
151 RX_ORUN = 0x6,
152 RX_ORUN_OCTS = 0x7,
153 RX_FCS = 0x8,
154 RX_L2ERR = 0x9,
155 RX_DRP_BCAST = 0xa,
156 RX_DRP_MCAST = 0xb,
157 RX_DRP_L3BCAST = 0xc,
158 RX_DRP_L3MCAST = 0xd,
159 RX_STATS_ENUM_LAST,
160};
161
162enum tx_stats_reg_offset {
163 TX_OCTS = 0x0,
164 TX_UCAST = 0x1,
165 TX_BCAST = 0x2,
166 TX_MCAST = 0x3,
167 TX_DROP = 0x4,
168 TX_STATS_ENUM_LAST,
169};
170
171struct nicvf_hw_stats {
a2dc5ded
SG
172 u64 rx_bytes;
173 u64 rx_ucast_frames;
174 u64 rx_bcast_frames;
175 u64 rx_mcast_frames;
4863dea3
SG
176 u64 rx_fcs_errors;
177 u64 rx_l2_errors;
178 u64 rx_drop_red;
179 u64 rx_drop_red_bytes;
180 u64 rx_drop_overrun;
181 u64 rx_drop_overrun_bytes;
182 u64 rx_drop_bcast;
183 u64 rx_drop_mcast;
184 u64 rx_drop_l3_bcast;
185 u64 rx_drop_l3_mcast;
a2dc5ded
SG
186 u64 rx_bgx_truncated_pkts;
187 u64 rx_jabber_errs;
188 u64 rx_fcs_errs;
189 u64 rx_bgx_errs;
190 u64 rx_prel2_errs;
191 u64 rx_l2_hdr_malformed;
192 u64 rx_oversize;
193 u64 rx_undersize;
194 u64 rx_l2_len_mismatch;
195 u64 rx_l2_pclp;
196 u64 rx_ip_ver_errs;
197 u64 rx_ip_csum_errs;
198 u64 rx_ip_hdr_malformed;
199 u64 rx_ip_payload_malformed;
200 u64 rx_ip_ttl_errs;
201 u64 rx_l3_pclp;
202 u64 rx_l4_malformed;
203 u64 rx_l4_csum_errs;
204 u64 rx_udp_len_errs;
205 u64 rx_l4_port_errs;
206 u64 rx_tcp_flag_errs;
207 u64 rx_tcp_offset_errs;
208 u64 rx_l4_pclp;
209 u64 rx_truncated_pkts;
210
4863dea3
SG
211 u64 tx_bytes_ok;
212 u64 tx_ucast_frames_ok;
213 u64 tx_bcast_frames_ok;
214 u64 tx_mcast_frames_ok;
215 u64 tx_drops;
216};
217
218struct nicvf_drv_stats {
219 /* Rx */
220 u64 rx_frames_ok;
221 u64 rx_frames_64;
222 u64 rx_frames_127;
223 u64 rx_frames_255;
224 u64 rx_frames_511;
225 u64 rx_frames_1023;
226 u64 rx_frames_1518;
227 u64 rx_frames_jumbo;
228 u64 rx_drops;
a2dc5ded 229
a05d4845
TS
230 u64 rcv_buffer_alloc_failures;
231
4863dea3
SG
232 /* Tx */
233 u64 tx_frames_ok;
234 u64 tx_drops;
4863dea3 235 u64 tx_tso;
a05d4845 236 u64 tx_timeout;
74840b83
SG
237 u64 txq_stop;
238 u64 txq_wake;
4863dea3
SG
239};
240
241struct nicvf {
92dc8769 242 struct nicvf *pnicvf;
4863dea3
SG
243 struct net_device *netdev;
244 struct pci_dev *pdev;
1d368790 245 void __iomem *reg_base;
a5c3d498 246#define MAX_QUEUES_PER_QSET 8
1d368790
SG
247 struct queue_set *qs;
248 struct nicvf_cq_poll *napi[8];
4863dea3 249 u8 vf_id;
1d368790
SG
250 u8 sqs_id;
251 bool sqs_mode;
40fb5f8a 252 bool hw_tso;
1d368790
SG
253
254 /* Receive buffer alloc */
255 u32 rb_page_offset;
256 u16 rb_pageref;
257 bool rb_alloc_fail;
258 bool rb_work_scheduled;
259 struct page *rb_page;
260 struct delayed_work rbdr_work;
261 struct tasklet_struct rbdr_task;
262
263 /* Secondary Qset */
264 u8 sqs_count;
92dc8769
SG
265#define MAX_SQS_PER_VF_SINGLE_NODE 5
266#define MAX_SQS_PER_VF 11
92dc8769 267 struct nicvf *snicvf[MAX_SQS_PER_VF];
1d368790
SG
268
269 /* Queue count */
92dc8769
SG
270 u8 rx_queues;
271 u8 tx_queues;
272 u8 max_queues;
1d368790
SG
273
274 u8 node;
275 u8 cpi_alg;
276 u16 mtu;
4863dea3
SG
277 bool link_up;
278 u8 duplex;
279 u32 speed;
1d368790
SG
280 bool tns_mode;
281 bool loopback_supported;
4863dea3 282 struct nicvf_rss_info rss_info;
1d368790
SG
283 struct tasklet_struct qs_err_task;
284 struct work_struct reset_task;
285
4863dea3
SG
286 /* Interrupt coalescing settings */
287 u32 cq_coalesce_usecs;
4863dea3 288 u32 msg_enable;
1d368790
SG
289
290 /* Stats */
a2dc5ded 291 struct nicvf_hw_stats hw_stats;
4863dea3
SG
292 struct nicvf_drv_stats drv_stats;
293 struct bgx_stats bgx_stats;
4863dea3
SG
294
295 /* MSI-X */
296 bool msix_enabled;
297 u8 num_vec;
298 struct msix_entry msix_entries[NIC_VF_MSIX_VECTORS];
299 char irq_name[NIC_VF_MSIX_VECTORS][20];
300 bool irq_allocated[NIC_VF_MSIX_VECTORS];
fb4b7d98 301 cpumask_var_t affinity_mask[NIC_VF_MSIX_VECTORS];
4863dea3 302
6051cba7 303 /* VF <-> PF mailbox communication */
4863dea3
SG
304 bool pf_acked;
305 bool pf_nacked;
bd049a90 306 bool set_mac_pending;
4863dea3
SG
307} ____cacheline_aligned_in_smp;
308
309/* PF <--> VF Mailbox communication
310 * Eight 64bit registers are shared between PF and VF.
311 * Separate set for each VF.
312 * Writing '1' into last register mbx7 means end of message.
313 */
314
315/* PF <--> VF mailbox communication */
316#define NIC_PF_VF_MAILBOX_SIZE 2
317#define NIC_MBOX_MSG_TIMEOUT 2000 /* ms */
318
319/* Mailbox message types */
320#define NIC_MBOX_MSG_READY 0x01 /* Is PF ready to rcv msgs */
321#define NIC_MBOX_MSG_ACK 0x02 /* ACK the message received */
322#define NIC_MBOX_MSG_NACK 0x03 /* NACK the message received */
323#define NIC_MBOX_MSG_QS_CFG 0x04 /* Configure Qset */
324#define NIC_MBOX_MSG_RQ_CFG 0x05 /* Configure receive queue */
325#define NIC_MBOX_MSG_SQ_CFG 0x06 /* Configure Send queue */
326#define NIC_MBOX_MSG_RQ_DROP_CFG 0x07 /* Configure receive queue */
327#define NIC_MBOX_MSG_SET_MAC 0x08 /* Add MAC ID to DMAC filter */
328#define NIC_MBOX_MSG_SET_MAX_FRS 0x09 /* Set max frame size */
329#define NIC_MBOX_MSG_CPI_CFG 0x0A /* Config CPI, RSSI */
330#define NIC_MBOX_MSG_RSS_SIZE 0x0B /* Get RSS indir_tbl size */
331#define NIC_MBOX_MSG_RSS_CFG 0x0C /* Config RSS table */
332#define NIC_MBOX_MSG_RSS_CFG_CONT 0x0D /* RSS config continuation */
333#define NIC_MBOX_MSG_RQ_BP_CFG 0x0E /* RQ backpressure config */
334#define NIC_MBOX_MSG_RQ_SW_SYNC 0x0F /* Flush inflight pkts to RQ */
335#define NIC_MBOX_MSG_BGX_STATS 0x10 /* Get stats from BGX */
336#define NIC_MBOX_MSG_BGX_LINK_CHANGE 0x11 /* BGX:LMAC link status */
92dc8769
SG
337#define NIC_MBOX_MSG_ALLOC_SQS 0x12 /* Allocate secondary Qset */
338#define NIC_MBOX_MSG_NICVF_PTR 0x13 /* Send nicvf ptr to PF */
339#define NIC_MBOX_MSG_PNICVF_PTR 0x14 /* Get primary qset nicvf ptr */
340#define NIC_MBOX_MSG_SNICVF_PTR 0x15 /* Send sqet nicvf ptr to PVF */
d77a2384 341#define NIC_MBOX_MSG_LOOPBACK 0x16 /* Set interface in loopback */
92dc8769
SG
342#define NIC_MBOX_MSG_CFG_DONE 0xF0 /* VF configuration done */
343#define NIC_MBOX_MSG_SHUTDOWN 0xF1 /* VF is being shutdown */
4863dea3
SG
344
345struct nic_cfg_msg {
346 u8 msg;
347 u8 vf_id;
4863dea3 348 u8 node_id;
92dc8769
SG
349 u8 tns_mode:1;
350 u8 sqs_mode:1;
d77a2384 351 u8 loopback_supported:1;
e610cb32 352 u8 mac_addr[ETH_ALEN];
4863dea3
SG
353};
354
355/* Qset configuration */
356struct qs_cfg_msg {
357 u8 msg;
358 u8 num;
92dc8769 359 u8 sqs_count;
4863dea3
SG
360 u64 cfg;
361};
362
363/* Receive queue configuration */
364struct rq_cfg_msg {
365 u8 msg;
366 u8 qs_num;
367 u8 rq_num;
368 u64 cfg;
369};
370
371/* Send queue configuration */
372struct sq_cfg_msg {
373 u8 msg;
374 u8 qs_num;
375 u8 sq_num;
92dc8769 376 bool sqs_mode;
4863dea3
SG
377 u64 cfg;
378};
379
380/* Set VF's MAC address */
381struct set_mac_msg {
382 u8 msg;
383 u8 vf_id;
e610cb32 384 u8 mac_addr[ETH_ALEN];
4863dea3
SG
385};
386
387/* Set Maximum frame size */
388struct set_frs_msg {
389 u8 msg;
390 u8 vf_id;
391 u16 max_frs;
392};
393
394/* Set CPI algorithm type */
395struct cpi_cfg_msg {
396 u8 msg;
397 u8 vf_id;
398 u8 rq_cnt;
399 u8 cpi_alg;
400};
401
402/* Get RSS table size */
403struct rss_sz_msg {
404 u8 msg;
405 u8 vf_id;
406 u16 ind_tbl_size;
407};
408
409/* Set RSS configuration */
410struct rss_cfg_msg {
411 u8 msg;
412 u8 vf_id;
413 u8 hash_bits;
414 u8 tbl_len;
415 u8 tbl_offset;
416#define RSS_IND_TBL_LEN_PER_MBX_MSG 8
417 u8 ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG];
418};
419
420struct bgx_stats_msg {
421 u8 msg;
422 u8 vf_id;
423 u8 rx;
424 u8 idx;
425 u64 stats;
426};
427
428/* Physical interface link status */
429struct bgx_link_status {
430 u8 msg;
431 u8 link_up;
432 u8 duplex;
433 u32 speed;
434};
435
92dc8769
SG
436/* Get Extra Qset IDs */
437struct sqs_alloc {
438 u8 msg;
439 u8 vf_id;
440 u8 qs_count;
441};
442
443struct nicvf_ptr {
444 u8 msg;
445 u8 vf_id;
446 bool sqs_mode;
447 u8 sqs_id;
448 u64 nicvf;
449};
450
d77a2384
SG
451/* Set interface in loopback mode */
452struct set_loopback {
453 u8 msg;
454 u8 vf_id;
455 bool enable;
456};
457
4863dea3
SG
458/* 128 bit shared memory between PF and each VF */
459union nic_mbx {
460 struct { u8 msg; } msg;
461 struct nic_cfg_msg nic_cfg;
462 struct qs_cfg_msg qs;
463 struct rq_cfg_msg rq;
464 struct sq_cfg_msg sq;
465 struct set_mac_msg mac;
466 struct set_frs_msg frs;
467 struct cpi_cfg_msg cpi_cfg;
468 struct rss_sz_msg rss_size;
469 struct rss_cfg_msg rss_cfg;
470 struct bgx_stats_msg bgx_stats;
471 struct bgx_link_status link_status;
92dc8769
SG
472 struct sqs_alloc sqs_alloc;
473 struct nicvf_ptr nicvf;
d77a2384 474 struct set_loopback lbk;
4863dea3
SG
475};
476
d768b678
RR
477#define NIC_NODE_ID_MASK 0x03
478#define NIC_NODE_ID_SHIFT 44
479
480static inline int nic_get_node_id(struct pci_dev *pdev)
481{
482 u64 addr = pci_resource_start(pdev, PCI_CFG_REG_BAR_NUM);
483 return ((addr >> NIC_NODE_ID_SHIFT) & NIC_NODE_ID_MASK);
484}
485
40fb5f8a
SG
486static inline bool pass1_silicon(struct pci_dev *pdev)
487{
488 return pdev->revision < 8;
489}
490
4863dea3
SG
491int nicvf_set_real_num_queues(struct net_device *netdev,
492 int tx_queues, int rx_queues);
493int nicvf_open(struct net_device *netdev);
494int nicvf_stop(struct net_device *netdev);
495int nicvf_send_msg_to_pf(struct nicvf *vf, union nic_mbx *mbx);
4863dea3
SG
496void nicvf_config_rss(struct nicvf *nic);
497void nicvf_set_rss_key(struct nicvf *nic);
4863dea3
SG
498void nicvf_set_ethtool_ops(struct net_device *netdev);
499void nicvf_update_stats(struct nicvf *nic);
500void nicvf_update_lmac_stats(struct nicvf *nic);
501
502#endif /* NIC_H */