OSDN Git Service

net: sxgbe: add Checksum offload support for Samsung sxgbe
[android-x86/kernel.git] / drivers / net / ethernet / samsung / sxgbe / sxgbe_common.h
1 /* 10G controller driver for Samsung SoCs
2  *
3  * Copyright (C) 2013 Samsung Electronics Co., Ltd.
4  *              http://www.samsung.com
5  *
6  * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #ifndef __SXGBE_COMMON_H__
14 #define __SXGBE_COMMON_H__
15
16 /* forward references */
17 struct sxgbe_desc_ops;
18 struct sxgbe_dma_ops;
19 struct sxgbe_mtl_ops;
20
21 #define SXGBE_RESOURCE_NAME     "sam_sxgbeeth"
22 #define DRV_MODULE_VERSION      "November_2013"
23
24 /* MAX HW feature words */
25 #define SXGBE_HW_WORDS 3
26
27 #define SXGBE_RX_COE_NONE       0
28
29 /* CSR Frequency Access Defines*/
30 #define SXGBE_CSR_F_150M        150000000
31 #define SXGBE_CSR_F_250M        250000000
32 #define SXGBE_CSR_F_300M        300000000
33 #define SXGBE_CSR_F_350M        350000000
34 #define SXGBE_CSR_F_400M        400000000
35 #define SXGBE_CSR_F_500M        500000000
36
37 /* pause time */
38 #define SXGBE_PAUSE_TIME 0x200
39
40 /* tx queues */
41 #define SXGBE_TX_QUEUES   8
42 #define SXGBE_RX_QUEUES   16
43
44 /* Calculated based how much time does it take to fill 256KB Rx memory
45  * at 10Gb speed at 156MHz clock rate and considered little less then
46  * the actual value.
47  */
48 #define SXGBE_MAX_DMA_RIWT      0x70
49 #define SXGBE_MIN_DMA_RIWT      0x01
50
51 /* Tx coalesce parameters */
52 #define SXGBE_COAL_TX_TIMER     40000
53 #define SXGBE_MAX_COAL_TX_TICK  100000
54 #define SXGBE_TX_MAX_FRAMES     512
55 #define SXGBE_TX_FRAMES 128
56
57 /* SXGBE TX FIFO is 8K, Rx FIFO is 16K */
58 #define BUF_SIZE_16KiB 16384
59 #define BUF_SIZE_8KiB 8192
60 #define BUF_SIZE_4KiB 4096
61 #define BUF_SIZE_2KiB 2048
62
63 #define SXGBE_DEFAULT_LIT_LS    0x3E8
64 #define SXGBE_DEFAULT_TWT_LS    0x0
65
66 /* Flow Control defines */
67 #define SXGBE_FLOW_OFF          0
68 #define SXGBE_FLOW_RX           1
69 #define SXGBE_FLOW_TX           2
70 #define SXGBE_FLOW_AUTO         (SXGBE_FLOW_TX | SXGBE_FLOW_RX)
71
72 #define SF_DMA_MODE 1           /* DMA STORE-AND-FORWARD Operation Mode */
73
74 /* errors */
75 #define RX_GMII_ERR             0x01
76 #define RX_WATCHDOG_ERR         0x02
77 #define RX_CRC_ERR              0x03
78 #define RX_GAINT_ERR            0x04
79 #define RX_IP_HDR_ERR           0x05
80 #define RX_PAYLOAD_ERR          0x06
81 #define RX_OVERFLOW_ERR         0x07
82
83 /* pkt type */
84 #define RX_LEN_PKT              0x00
85 #define RX_MACCTL_PKT           0x01
86 #define RX_DCBCTL_PKT           0x02
87 #define RX_ARP_PKT              0x03
88 #define RX_OAM_PKT              0x04
89 #define RX_UNTAG_PKT            0x05
90 #define RX_OTHER_PKT            0x07
91 #define RX_SVLAN_PKT            0x08
92 #define RX_CVLAN_PKT            0x09
93 #define RX_DVLAN_OCVLAN_ICVLAN_PKT              0x0A
94 #define RX_DVLAN_OSVLAN_ISVLAN_PKT              0x0B
95 #define RX_DVLAN_OSVLAN_ICVLAN_PKT              0x0C
96 #define RX_DVLAN_OCVLAN_ISVLAN_PKT              0x0D
97
98 #define RX_NOT_IP_PKT           0x00
99 #define RX_IPV4_TCP_PKT         0x01
100 #define RX_IPV4_UDP_PKT         0x02
101 #define RX_IPV4_ICMP_PKT        0x03
102 #define RX_IPV4_UNKNOWN_PKT     0x07
103 #define RX_IPV6_TCP_PKT         0x09
104 #define RX_IPV6_UDP_PKT         0x0A
105 #define RX_IPV6_ICMP_PKT        0x0B
106 #define RX_IPV6_UNKNOWN_PKT     0x0F
107
108 #define RX_NO_PTP               0x00
109 #define RX_PTP_SYNC             0x01
110 #define RX_PTP_FOLLOW_UP        0x02
111 #define RX_PTP_DELAY_REQ        0x03
112 #define RX_PTP_DELAY_RESP       0x04
113 #define RX_PTP_PDELAY_REQ       0x05
114 #define RX_PTP_PDELAY_RESP      0x06
115 #define RX_PTP_PDELAY_FOLLOW_UP 0x07
116 #define RX_PTP_ANNOUNCE         0x08
117 #define RX_PTP_MGMT             0x09
118 #define RX_PTP_SIGNAL           0x0A
119 #define RX_PTP_RESV_MSG         0x0F
120
121 /* EEE-LPI mode  flags*/
122 #define TX_ENTRY_LPI_MODE       0x10
123 #define TX_EXIT_LPI_MODE        0x20
124 #define RX_ENTRY_LPI_MODE       0x40
125 #define RX_EXIT_LPI_MODE        0x80
126
127 /* EEE-LPI Interrupt status flag */
128 #define LPI_INT_STATUS          BIT(5)
129
130 /* EEE-LPI Default timer values */
131 #define LPI_LINK_STATUS_TIMER   0x3E8
132 #define LPI_MAC_WAIT_TIMER      0x00
133
134 /* EEE-LPI Control and status definitions */
135 #define LPI_CTRL_STATUS_TXA     BIT(19)
136 #define LPI_CTRL_STATUS_PLSDIS  BIT(18)
137 #define LPI_CTRL_STATUS_PLS     BIT(17)
138 #define LPI_CTRL_STATUS_LPIEN   BIT(16)
139 #define LPI_CTRL_STATUS_TXRSTP  BIT(11)
140 #define LPI_CTRL_STATUS_RXRSTP  BIT(10)
141 #define LPI_CTRL_STATUS_RLPIST  BIT(9)
142 #define LPI_CTRL_STATUS_TLPIST  BIT(8)
143 #define LPI_CTRL_STATUS_RLPIEX  BIT(3)
144 #define LPI_CTRL_STATUS_RLPIEN  BIT(2)
145 #define LPI_CTRL_STATUS_TLPIEX  BIT(1)
146 #define LPI_CTRL_STATUS_TLPIEN  BIT(0)
147
148 enum dma_irq_status {
149         tx_hard_error   = BIT(0),
150         tx_bump_tc      = BIT(1),
151         handle_tx       = BIT(2),
152         rx_hard_error   = BIT(3),
153         rx_bump_tc      = BIT(4),
154         handle_rx       = BIT(5),
155 };
156
157 #define NETIF_F_HW_VLAN_ALL     (NETIF_F_HW_VLAN_CTAG_RX |      \
158                                  NETIF_F_HW_VLAN_STAG_RX |      \
159                                  NETIF_F_HW_VLAN_CTAG_TX |      \
160                                  NETIF_F_HW_VLAN_STAG_TX |      \
161                                  NETIF_F_HW_VLAN_CTAG_FILTER |  \
162                                  NETIF_F_HW_VLAN_STAG_FILTER)
163
164 /* MMC control defines */
165 #define SXGBE_MMC_CTRL_CNT_FRZ  0x00000008
166
167 /* SXGBE HW ADDR regs */
168 #define SXGBE_ADDR_HIGH(reg)    (((reg > 15) ? 0x00000800 : 0x00000040) + \
169                                  (reg * 8))
170 #define SXGBE_ADDR_LOW(reg)     (((reg > 15) ? 0x00000804 : 0x00000044) + \
171                                  (reg * 8))
172 #define SXGBE_MAX_PERFECT_ADDRESSES 32 /* Maximum unicast perfect filtering */
173 #define SXGBE_FRAME_FILTER       0x00000004      /* Frame Filter */
174
175 /* SXGBE Frame Filter defines */
176 #define SXGBE_FRAME_FILTER_PR    0x00000001      /* Promiscuous Mode */
177 #define SXGBE_FRAME_FILTER_HUC   0x00000002      /* Hash Unicast */
178 #define SXGBE_FRAME_FILTER_HMC   0x00000004      /* Hash Multicast */
179 #define SXGBE_FRAME_FILTER_DAIF  0x00000008      /* DA Inverse Filtering */
180 #define SXGBE_FRAME_FILTER_PM    0x00000010      /* Pass all multicast */
181 #define SXGBE_FRAME_FILTER_DBF   0x00000020      /* Disable Broadcast frames */
182 #define SXGBE_FRAME_FILTER_SAIF  0x00000100      /* Inverse Filtering */
183 #define SXGBE_FRAME_FILTER_SAF   0x00000200      /* Source Address Filter */
184 #define SXGBE_FRAME_FILTER_HPF   0x00000400      /* Hash or perfect Filter */
185 #define SXGBE_FRAME_FILTER_RA    0x80000000      /* Receive all mode */
186
187 #define SXGBE_HASH_TABLE_SIZE    64
188 #define SXGBE_HASH_HIGH          0x00000008      /* Multicast Hash Table High */
189 #define SXGBE_HASH_LOW           0x0000000c      /* Multicast Hash Table Low */
190
191 #define SXGBE_HI_REG_AE          0x80000000
192
193 /* Minimum and maximum MTU */
194 #define MIN_MTU         68
195 #define MAX_MTU         9000
196
197 #define SXGBE_FOR_EACH_QUEUE(max_queues, queue_num)                     \
198         for (queue_num = 0; queue_num < max_queues; queue_num++)
199
200 /* sxgbe statistics counters */
201 struct sxgbe_extra_stats {
202         /* TX/RX IRQ events */
203         unsigned long tx_underflow_irq;
204         unsigned long tx_process_stopped_irq;
205         unsigned long tx_ctxt_desc_err;
206         unsigned long tx_threshold;
207         unsigned long rx_threshold;
208         unsigned long tx_pkt_n;
209         unsigned long rx_pkt_n;
210         unsigned long normal_irq_n;
211         unsigned long tx_normal_irq_n;
212         unsigned long rx_normal_irq_n;
213         unsigned long napi_poll;
214         unsigned long tx_clean;
215         unsigned long tx_reset_ic_bit;
216         unsigned long rx_process_stopped_irq;
217         unsigned long rx_underflow_irq;
218
219         /* Bus access errors */
220         unsigned long fatal_bus_error_irq;
221         unsigned long tx_read_transfer_err;
222         unsigned long tx_write_transfer_err;
223         unsigned long tx_desc_access_err;
224         unsigned long tx_buffer_access_err;
225         unsigned long tx_data_transfer_err;
226         unsigned long rx_read_transfer_err;
227         unsigned long rx_write_transfer_err;
228         unsigned long rx_desc_access_err;
229         unsigned long rx_buffer_access_err;
230         unsigned long rx_data_transfer_err;
231
232         /* EEE-LPI stats */
233         unsigned long tx_lpi_entry_n;
234         unsigned long tx_lpi_exit_n;
235         unsigned long rx_lpi_entry_n;
236         unsigned long rx_lpi_exit_n;
237         unsigned long eee_wakeup_error_n;
238
239         /* RX specific */
240         /* L2 error */
241         unsigned long rx_code_gmii_err;
242         unsigned long rx_watchdog_err;
243         unsigned long rx_crc_err;
244         unsigned long rx_gaint_pkt_err;
245         unsigned long ip_hdr_err;
246         unsigned long ip_payload_err;
247         unsigned long overflow_error;
248
249         /* L2 Pkt type */
250         unsigned long len_pkt;
251         unsigned long mac_ctl_pkt;
252         unsigned long dcb_ctl_pkt;
253         unsigned long arp_pkt;
254         unsigned long oam_pkt;
255         unsigned long untag_okt;
256         unsigned long other_pkt;
257         unsigned long svlan_tag_pkt;
258         unsigned long cvlan_tag_pkt;
259         unsigned long dvlan_ocvlan_icvlan_pkt;
260         unsigned long dvlan_osvlan_isvlan_pkt;
261         unsigned long dvlan_osvlan_icvlan_pkt;
262         unsigned long dvan_ocvlan_icvlan_pkt;
263
264         /* L3/L4 Pkt type */
265         unsigned long not_ip_pkt;
266         unsigned long ip4_tcp_pkt;
267         unsigned long ip4_udp_pkt;
268         unsigned long ip4_icmp_pkt;
269         unsigned long ip4_unknown_pkt;
270         unsigned long ip6_tcp_pkt;
271         unsigned long ip6_udp_pkt;
272         unsigned long ip6_icmp_pkt;
273         unsigned long ip6_unknown_pkt;
274
275         /* Filter specific */
276         unsigned long vlan_filter_match;
277         unsigned long sa_filter_fail;
278         unsigned long da_filter_fail;
279         unsigned long hash_filter_pass;
280         unsigned long l3_filter_match;
281         unsigned long l4_filter_match;
282
283         /* RX context specific */
284         unsigned long timestamp_dropped;
285         unsigned long rx_msg_type_no_ptp;
286         unsigned long rx_ptp_type_sync;
287         unsigned long rx_ptp_type_follow_up;
288         unsigned long rx_ptp_type_delay_req;
289         unsigned long rx_ptp_type_delay_resp;
290         unsigned long rx_ptp_type_pdelay_req;
291         unsigned long rx_ptp_type_pdelay_resp;
292         unsigned long rx_ptp_type_pdelay_follow_up;
293         unsigned long rx_ptp_announce;
294         unsigned long rx_ptp_mgmt;
295         unsigned long rx_ptp_signal;
296         unsigned long rx_ptp_resv_msg_type;
297 };
298
299 struct mac_link {
300         int port;
301         int duplex;
302         int speed;
303 };
304
305 struct mii_regs {
306         unsigned int addr;      /* MII Address */
307         unsigned int data;      /* MII Data */
308 };
309
310 struct sxgbe_core_ops {
311         /* MAC core initialization */
312         void (*core_init)(void __iomem *ioaddr);
313         /* Dump MAC registers */
314         void (*dump_regs)(void __iomem *ioaddr);
315         /* Handle extra events on specific interrupts hw dependent */
316         int (*host_irq_status)(void __iomem *ioaddr,
317                                struct sxgbe_extra_stats *x);
318         /* Set power management mode (e.g. magic frame) */
319         void (*pmt)(void __iomem *ioaddr, unsigned long mode);
320         /* Set/Get Unicast MAC addresses */
321         void (*set_umac_addr)(void __iomem *ioaddr, unsigned char *addr,
322                               unsigned int reg_n);
323         void (*get_umac_addr)(void __iomem *ioaddr, unsigned char *addr,
324                               unsigned int reg_n);
325         void (*enable_rx)(void __iomem *ioaddr, bool enable);
326         void (*enable_tx)(void __iomem *ioaddr, bool enable);
327
328         /* controller version specific operations */
329         int (*get_controller_version)(void __iomem *ioaddr);
330
331         /* If supported then get the optional core features */
332         unsigned int (*get_hw_feature)(void __iomem *ioaddr,
333                                        unsigned char feature_index);
334         /* adjust SXGBE speed */
335         void (*set_speed)(void __iomem *ioaddr, unsigned char speed);
336
337         /* EEE-LPI specific operations */
338         void (*set_eee_mode)(void __iomem *ioaddr);
339         void (*reset_eee_mode)(void __iomem *ioaddr);
340         void (*set_eee_timer)(void __iomem *ioaddr, const int ls,
341                               const int tw);
342         void (*set_eee_pls)(void __iomem *ioaddr, const int link);
343
344         /* Enable disable checksum offload operations */
345         void (*enable_rx_csum)(void __iomem *ioaddr);
346         void (*disable_rx_csum)(void __iomem *ioaddr);
347 };
348
349 const struct sxgbe_core_ops *sxgbe_get_core_ops(void);
350
351 struct sxgbe_ops {
352         const struct sxgbe_core_ops *mac;
353         const struct sxgbe_desc_ops *desc;
354         const struct sxgbe_dma_ops *dma;
355         const struct sxgbe_mtl_ops *mtl;
356         struct mii_regs mii;    /* MII register Addresses */
357         struct mac_link link;
358         unsigned int ctrl_uid;
359         unsigned int ctrl_id;
360 };
361
362 /* SXGBE private data structures */
363 struct sxgbe_tx_queue {
364         unsigned int irq_no;
365         struct sxgbe_priv_data *priv_ptr;
366         struct sxgbe_tx_norm_desc *dma_tx;
367         dma_addr_t dma_tx_phy;
368         dma_addr_t *tx_skbuff_dma;
369         struct sk_buff **tx_skbuff;
370         struct timer_list txtimer;
371         spinlock_t tx_lock;     /* lock for tx queues */
372         unsigned int cur_tx;
373         unsigned int dirty_tx;
374         u32 tx_count_frames;
375         u32 tx_coal_frames;
376         u32 tx_coal_timer;
377         int hwts_tx_en;
378         u16 prev_mss;
379         u8 queue_no;
380 };
381
382 struct sxgbe_rx_queue {
383         struct sxgbe_priv_data *priv_ptr;
384         struct sxgbe_rx_norm_desc *dma_rx;
385         struct sk_buff **rx_skbuff;
386         unsigned int cur_rx;
387         unsigned int dirty_rx;
388         unsigned int irq_no;
389         u32 rx_riwt;
390         dma_addr_t *rx_skbuff_dma;
391         dma_addr_t dma_rx_phy;
392         u8 queue_no;
393 };
394
395 /* SXGBE HW capabilities */
396 struct sxgbe_hw_features {
397         /****** CAP [0] *******/
398         unsigned int pmt_remote_wake_up;
399         unsigned int pmt_magic_frame;
400         /* IEEE 1588-2008 */
401         unsigned int atime_stamp;
402
403         unsigned int eee;
404
405         unsigned int tx_csum_offload;
406         unsigned int rx_csum_offload;
407         unsigned int multi_macaddr;
408         unsigned int tstamp_srcselect;
409         unsigned int sa_vlan_insert;
410
411         /****** CAP [1] *******/
412         unsigned int rxfifo_size;
413         unsigned int txfifo_size;
414         unsigned int atstmap_hword;
415         unsigned int dcb_enable;
416         unsigned int splithead_enable;
417         unsigned int tcpseg_offload;
418         unsigned int debug_mem;
419         unsigned int rss_enable;
420         unsigned int hash_tsize;
421         unsigned int l3l4_filer_size;
422
423         /* This value is in bytes and
424          * as mentioned in HW features
425          * of SXGBE data book
426          */
427         unsigned int rx_mtl_qsize;
428         unsigned int tx_mtl_qsize;
429
430         /****** CAP [2] *******/
431         /* TX and RX number of channels */
432         unsigned int rx_mtl_queues;
433         unsigned int tx_mtl_queues;
434         unsigned int rx_dma_channels;
435         unsigned int tx_dma_channels;
436         unsigned int pps_output_count;
437         unsigned int aux_input_count;
438 };
439
440 struct sxgbe_priv_data {
441         /* DMA descriptos */
442         struct sxgbe_tx_queue *txq[SXGBE_TX_QUEUES];
443         struct sxgbe_rx_queue *rxq[SXGBE_RX_QUEUES];
444         u8 cur_rx_qnum;
445
446         unsigned int dma_tx_size;
447         unsigned int dma_rx_size;
448         unsigned int dma_buf_sz;
449         u32 rx_riwt;
450
451         struct napi_struct napi;
452
453         void __iomem *ioaddr;
454         struct net_device *dev;
455         struct device *device;
456         struct sxgbe_ops *hw;   /* sxgbe specific ops */
457         int no_csum_insertion;
458         int irq;
459         int rxcsum_insertion;
460         spinlock_t stats_lock;  /* lock for tx/rx statatics */
461
462         struct phy_device *phydev;
463         int oldlink;
464         int speed;
465         int oldduplex;
466         struct mii_bus *mii;
467         int mii_irq[PHY_MAX_ADDR];
468         u8 rx_pause;
469         u8 tx_pause;
470
471         struct sxgbe_extra_stats xstats;
472         struct sxgbe_plat_data *plat;
473         struct sxgbe_hw_features hw_cap;
474
475         u32 msg_enable;
476
477         struct clk *sxgbe_clk;
478         int clk_csr;
479         unsigned int mode;
480         unsigned int default_addend;
481
482         /* advanced time stamp support */
483         u32 adv_ts;
484         int use_riwt;
485
486         /* tc control */
487         int tx_tc;
488         int rx_tc;
489         /* EEE-LPI specific members */
490         struct timer_list eee_ctrl_timer;
491         bool tx_path_in_lpi_mode;
492         int lpi_irq;
493         int eee_enabled;
494         int eee_active;
495         int tx_lpi_timer;
496 };
497
498 /* Function prototypes */
499 struct sxgbe_priv_data *sxgbe_drv_probe(struct device *device,
500                                         struct sxgbe_plat_data *plat_dat,
501                                         void __iomem *addr);
502 int sxgbe_drv_remove(struct net_device *ndev);
503 void sxgbe_set_ethtool_ops(struct net_device *netdev);
504 int sxgbe_mdio_unregister(struct net_device *ndev);
505 int sxgbe_mdio_register(struct net_device *ndev);
506 int sxgbe_register_platform(void);
507 void sxgbe_unregister_platform(void);
508
509 #ifdef CONFIG_PM
510 int sxgbe_suspend(struct net_device *ndev);
511 int sxgbe_resume(struct net_device *ndev);
512 int sxgbe_freeze(struct net_device *ndev);
513 int sxgbe_restore(struct net_device *ndev);
514 #endif /* CONFIG_PM */
515
516 const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void);
517
518 void sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv);
519 bool sxgbe_eee_init(struct sxgbe_priv_data * const priv);
520
521 #endif /* __SXGBE_COMMON_H__ */