xref: /netbsd/sys/dev/pci/cxgb/cxgb_toedev.h (revision 6550d01e)
1 
2 /**************************************************************************
3 
4 Copyright (c) 2007, Chelsio Inc.
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12 
13  2. Neither the name of the Chelsio Corporation nor the names of its
14     contributors may be used to endorse or promote products derived from
15     this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 
29 ***************************************************************************/
30 
31 #ifndef _OFFLOAD_DEV_H_
32 #define _OFFLOAD_DEV_H_
33 
34 #include <net/route.h>
35 
36 /* Parameter values for offload_get_phys_egress() */
37 enum {
38     TOE_OPEN,
39     TOE_FAILOVER,
40 };
41 
42 /* Parameter values for toe_failover() */
43 enum {
44     TOE_ACTIVE_SLAVE,
45     TOE_LINK_DOWN,
46     TOE_LINK_UP,
47     TOE_RELEASE,
48     TOE_RELEASE_ALL,
49 };
50 
51 
52 #define TOENAMSIZ 16
53 
54 /* belongs in linux/netdevice.h */
55 #define NETIF_F_TCPIP_OFFLOAD (1 << 15)
56 
57 /* Get the toedev associated with a ifnet */
58 #define TOEDEV(netdev) (*(struct toedev **)&(netdev)->if_softc)
59 
60 /* offload type ids */
61 enum {
62     TOE_ID_CHELSIO_T1 = 1,
63     TOE_ID_CHELSIO_T1C,
64     TOE_ID_CHELSIO_T2,
65     TOE_ID_CHELSIO_T3,
66     TOE_ID_CHELSIO_T3B,
67 };
68 
69 struct offload_id {
70     unsigned int id;
71     unsigned long data;
72 };
73 
74 struct ifnet;
75 struct rt_entry;
76 struct tom_info;
77 struct sysctl_oid;
78 struct socket;
79 struct mbuf;
80 
81 enum toetype {
82         T3A = 0,
83         T3B
84 };
85 
86 struct toedev {
87     char name[TOENAMSIZ];       /* TOE device name */
88     enum toetype type;
89     struct adapter *adapter;
90     unsigned int ttid;          /* TOE type id */
91     unsigned long flags;        /* device flags */
92     unsigned int mtu;           /* max size of TX offloaded data */
93     unsigned int nconn;         /* max # of offloaded connections */
94     struct ifnet *lldev;   /* LL device associated with TOE messages */
95     const struct tom_info *offload_mod; /* attached TCP offload module */
96     struct sysctl_oid *sysctl_root;    /* root of proc dir for this TOE */
97     TAILQ_ENTRY(toedev) ofld_entry;  /* for list linking */
98     int (*open)(struct toedev *dev);
99     int (*close)(struct toedev *dev);
100     int (*can_offload)(struct toedev *dev, struct socket *so);
101     int (*connect)(struct toedev *dev, struct socket *so,
102                struct ifnet *egress_ifp);
103     int (*send)(struct toedev *dev, struct mbuf *m);
104     int (*recv)(struct toedev *dev, struct mbuf **m, int n);
105     int (*ctl)(struct toedev *dev, unsigned int req, void *data);
106     void (*neigh_update)(struct toedev *dev, struct rtentry *neigh);
107     void (*failover)(struct toedev *dev, struct ifnet *bond_ifp,
108              struct ifnet *ndev, int event);
109     void *priv;                 /* driver private data */
110     void *l2opt;                /* optional layer 2 data */
111     void *l3opt;                /* optional layer 3 data */
112     void *l4opt;                /* optional layer 4 data */
113     void *ulp;                  /* ulp stuff */
114 };
115 
116 struct tom_info {
117     int (*attach)(struct toedev *dev, const struct offload_id *entry);
118     int (*detach)(struct toedev *dev);
119     const char *name;
120     const struct offload_id *id_table;
121     TAILQ_ENTRY(tom_info) entry;
122 };
123 
124 static inline void init_offload_dev(struct toedev *dev)
125 {
126 
127 }
128 
129 extern int register_tom(struct tom_info *t);
130 extern int unregister_tom(struct tom_info *t);
131 extern int register_toedev(struct toedev *dev, const char *name);
132 extern int unregister_toedev(struct toedev *dev);
133 extern int activate_offload(struct toedev *dev);
134 extern int toe_send(struct toedev *dev, struct mbuf *m);
135 extern struct ifnet *offload_get_phys_egress(struct ifnet *dev,
136                           struct socket *so,
137                           int context);
138 
139 #if defined(CONFIG_TCP_OFFLOAD_MODULE)
140 static inline int toe_receive_mbuf(struct toedev *dev, struct mbuf **m,
141                   int n)
142 {
143     return dev->recv(dev, m, n);
144 }
145 
146 extern int  prepare_tcp_for_offload(void);
147 extern void restore_tcp_to_nonoffload(void);
148 #elif defined(CONFIG_TCP_OFFLOAD)
149 extern int toe_receive_mbuf(struct toedev *dev, struct mbuf **m, int n);
150 #endif
151 
152 #if defined(CONFIG_TCP_OFFLOAD) || \
153     (defined(CONFIG_TCP_OFFLOAD_MODULE) && defined(MODULE))
154 extern void toe_neigh_update(struct rtentry *neigh);
155 extern void toe_failover(struct ifnet *bond_ifp,
156              struct ifnet *fail_ifp, int event);
157 extern int toe_enslave(struct ifnet *bond_ifp,
158                struct ifnet *slave_ifp);
159 #else
160 static inline void toe_neigh_update(struct ifnet *neigh) {}
161 static inline void toe_failover(struct ifnet *bond_ifp,
162                 struct ifnet *fail_ifp, int event)
163 {}
164 static inline int toe_enslave(struct ifnet *bond_ifp,
165                   struct ifnet *slave_ifp)
166 {
167     return 0;
168 }
169 #endif /* CONFIG_TCP_OFFLOAD */
170 
171 #endif /* _OFFLOAD_DEV_H_ */
172