Merge tag 'rtc-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
[linux-2.6-block.git] / include / linux / qed / qed_ll2_if.h
1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015-2017  QLogic Corporation
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and /or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef _QED_LL2_IF_H
34 #define _QED_LL2_IF_H
35
36 #include <linux/types.h>
37 #include <linux/interrupt.h>
38 #include <linux/netdevice.h>
39 #include <linux/pci.h>
40 #include <linux/skbuff.h>
41 #include <linux/version.h>
42 #include <linux/kernel.h>
43 #include <linux/slab.h>
44 #include <linux/qed/qed_if.h>
45
46 struct qed_ll2_stats {
47         u64 gsi_invalid_hdr;
48         u64 gsi_invalid_pkt_length;
49         u64 gsi_unsupported_pkt_typ;
50         u64 gsi_crcchksm_error;
51
52         u64 packet_too_big_discard;
53         u64 no_buff_discard;
54
55         u64 rcv_ucast_bytes;
56         u64 rcv_mcast_bytes;
57         u64 rcv_bcast_bytes;
58         u64 rcv_ucast_pkts;
59         u64 rcv_mcast_pkts;
60         u64 rcv_bcast_pkts;
61
62         u64 sent_ucast_bytes;
63         u64 sent_mcast_bytes;
64         u64 sent_bcast_bytes;
65         u64 sent_ucast_pkts;
66         u64 sent_mcast_pkts;
67         u64 sent_bcast_pkts;
68 };
69
70 #define QED_LL2_UNUSED_HANDLE   (0xff)
71
72 struct qed_ll2_cb_ops {
73         int (*rx_cb)(void *, struct sk_buff *, u32, u32);
74         int (*tx_cb)(void *, struct sk_buff *, bool);
75 };
76
77 struct qed_ll2_params {
78         u16 mtu;
79         bool drop_ttl0_packets;
80         bool rx_vlan_stripping;
81         u8 tx_tc;
82         bool frags_mapped;
83         u8 ll2_mac_address[ETH_ALEN];
84 };
85
86 struct qed_ll2_ops {
87 /**
88  * @brief start - initializes ll2
89  *
90  * @param cdev
91  * @param params - protocol driver configuration for the ll2.
92  *
93  * @return 0 on success, otherwise error value.
94  */
95         int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
96
97 /**
98  * @brief stop - stops the ll2
99  *
100  * @param cdev
101  *
102  * @return 0 on success, otherwise error value.
103  */
104         int (*stop)(struct qed_dev *cdev);
105
106 /**
107  * @brief start_xmit - transmits an skb over the ll2 interface
108  *
109  * @param cdev
110  * @param skb
111  *
112  * @return 0 on success, otherwise error value.
113  */
114         int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb);
115
116 /**
117  * @brief register_cb_ops - protocol driver register the callback for Rx/Tx
118  * packets. Should be called before `start'.
119  *
120  * @param cdev
121  * @param cookie - to be passed to the callback functions.
122  * @param ops - the callback functions to register for Rx / Tx.
123  *
124  * @return 0 on success, otherwise error value.
125  */
126         void (*register_cb_ops)(struct qed_dev *cdev,
127                                 const struct qed_ll2_cb_ops *ops,
128                                 void *cookie);
129
130 /**
131  * @brief get LL2 related statistics
132  *
133  * @param cdev
134  * @param stats - pointer to struct that would be filled with stats
135  *
136  * @return 0 on success, error otherwise.
137  */
138         int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
139 };
140
141 #ifdef CONFIG_QED_LL2
142 int qed_ll2_alloc_if(struct qed_dev *);
143 void qed_ll2_dealloc_if(struct qed_dev *);
144 #else
145 static const struct qed_ll2_ops qed_ll2_ops_pass = {
146         .start = NULL,
147         .stop = NULL,
148         .start_xmit = NULL,
149         .register_cb_ops = NULL,
150         .get_stats = NULL,
151 };
152
153 static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
154 {
155         return 0;
156 }
157
158 static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)
159 {
160 }
161 #endif
162 #endif