cxgb_adapter.h revision 1.5 1 1.1 jklos /**************************************************************************
2 1.1 jklos
3 1.1 jklos Copyright (c) 2007, Chelsio Inc.
4 1.1 jklos All rights reserved.
5 1.1 jklos
6 1.1 jklos Redistribution and use in source and binary forms, with or without
7 1.1 jklos modification, are permitted provided that the following conditions are met:
8 1.1 jklos
9 1.1 jklos 1. Redistributions of source code must retain the above copyright notice,
10 1.1 jklos this list of conditions and the following disclaimer.
11 1.1 jklos
12 1.1 jklos 2. Neither the name of the Chelsio Corporation nor the names of its
13 1.1 jklos contributors may be used to endorse or promote products derived from
14 1.1 jklos this software without specific prior written permission.
15 1.1 jklos
16 1.1 jklos THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 1.1 jklos AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 jklos IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 jklos ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 1.1 jklos LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 jklos CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 jklos SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 jklos INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 jklos CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 jklos ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 jklos POSSIBILITY OF SUCH DAMAGE.
27 1.1 jklos
28 1.1 jklos
29 1.1 jklos ***************************************************************************/
30 1.1 jklos
31 1.1 jklos
32 1.1 jklos
33 1.1 jklos #ifndef _CXGB_ADAPTER_H_
34 1.1 jklos #define _CXGB_ADAPTER_H_
35 1.1 jklos
36 1.1 jklos #include <sys/lock.h>
37 1.1 jklos #include <sys/mutex.h>
38 1.1 jklos #include <sys/mbuf.h>
39 1.1 jklos #include <sys/socket.h>
40 1.1 jklos #include <sys/sockio.h>
41 1.1 jklos
42 1.1 jklos #include <net/if.h>
43 1.1 jklos #include <net/if_ether.h>
44 1.1 jklos #include <net/if_media.h>
45 1.1 jklos
46 1.2 dyoung #include <sys/bus.h>
47 1.1 jklos #include <dev/pci/pcireg.h>
48 1.1 jklos #include <dev/pci/pcivar.h>
49 1.1 jklos
50 1.1 jklos #ifdef CONFIG_DEFINED
51 1.1 jklos #include <cxgb_osdep.h>
52 1.1 jklos #include <ulp/toecore/toedev.h>
53 1.1 jklos #include <sys/mbufq.h>
54 1.1 jklos #else
55 1.1 jklos #include "cxgb_osdep.h"
56 1.1 jklos #include "cxgb_mbuf.h"
57 1.1 jklos #include "cxgb_toedev.h"
58 1.1 jklos #endif
59 1.1 jklos
60 1.1 jklos struct adapter;
61 1.1 jklos struct sge_qset;
62 1.1 jklos extern int cxgb_debug;
63 1.1 jklos
64 1.1 jklos #ifdef DEBUG_LOCKING
65 1.1 jklos #define MTX_INIT(lock, lockname, class, flags) \
66 1.1 jklos do { \
67 1.1 jklos printf("initializing %s at %s:%d\n", lockname, __FILE__, __LINE__); \
68 1.1 jklos mtx_init((lock), lockname, class, flags); \
69 1.1 jklos } while (0)
70 1.1 jklos
71 1.1 jklos #define MTX_DESTROY(lock) \
72 1.1 jklos do { \
73 1.1 jklos printf("destroying %s at %s:%d\n", (lock)->lock_object.lo_name, __FILE__, __LINE__); \
74 1.1 jklos mtx_destroy((lock)); \
75 1.1 jklos } while (0)
76 1.1 jklos
77 1.1 jklos #define SX_INIT(lock, lockname) \
78 1.1 jklos do { \
79 1.1 jklos printf("initializing %s at %s:%d\n", lockname, __FILE__, __LINE__); \
80 1.1 jklos sx_init((lock), lockname); \
81 1.1 jklos } while (0)
82 1.1 jklos
83 1.1 jklos #define SX_DESTROY(lock) \
84 1.1 jklos do { \
85 1.1 jklos printf("destroying %s at %s:%d\n", (lock)->lock_object.lo_name, __FILE__, __LINE__); \
86 1.1 jklos sx_destroy((lock)); \
87 1.1 jklos } while (0)
88 1.1 jklos #else
89 1.1 jklos #define MTX_INIT mtx_init
90 1.1 jklos #define MTX_DESTROY mtx_destroy
91 1.1 jklos #define SX_INIT sx_init
92 1.1 jklos #define SX_DESTROY sx_destroy
93 1.1 jklos #endif
94 1.1 jklos
95 1.1 jklos struct port_device {
96 1.1 jklos device_t dev;
97 1.1 jklos struct adapter *parent;
98 1.1 jklos int port_number;
99 1.1 jklos };
100 1.1 jklos
101 1.1 jklos struct port_info {
102 1.1 jklos struct adapter *adapter;
103 1.1 jklos struct ifnet *ifp;
104 1.1 jklos struct port_device *pd;
105 1.1 jklos int port;
106 1.5 msaitoh u_short if_flags;
107 1.1 jklos const struct port_type_info *port_type;
108 1.1 jklos struct cphy phy;
109 1.1 jklos struct cmac mac;
110 1.1 jklos struct link_config link_config;
111 1.1 jklos struct ifmedia media;
112 1.1 jklos #ifdef USE_SX
113 1.1 jklos struct sx lock;
114 1.1 jklos #else
115 1.1 jklos struct mtx lock;
116 1.1 jklos #endif
117 1.1 jklos uint8_t port_id;
118 1.1 jklos uint8_t tx_chan;
119 1.1 jklos uint8_t txpkt_intf;
120 1.1 jklos uint8_t nqsets;
121 1.1 jklos uint8_t first_qset;
122 1.1 jklos
123 1.1 jklos uint8_t hw_addr[ETHER_ADDR_LEN];
124 1.1 jklos struct cxgb_task start_task;
125 1.1 jklos struct cxgb_task timer_reclaim_task;
126 1.1 jklos struct cdev *port_cdev;
127 1.1 jklos
128 1.1 jklos #define PORT_NAME_LEN 32
129 1.1 jklos #define TASKQ_NAME_LEN 32
130 1.1 jklos char lockbuf[PORT_NAME_LEN];
131 1.1 jklos char taskqbuf[TASKQ_NAME_LEN];
132 1.1 jklos };
133 1.1 jklos
134 1.1 jklos enum { /* adapter flags */
135 1.1 jklos FULL_INIT_DONE = (1 << 0),
136 1.1 jklos USING_MSI = (1 << 1),
137 1.1 jklos USING_MSIX = (1 << 2),
138 1.1 jklos QUEUES_BOUND = (1 << 3),
139 1.1 jklos FW_UPTODATE = (1 << 4),
140 1.1 jklos TPS_UPTODATE = (1 << 5),
141 1.1 jklos };
142 1.1 jklos
143 1.1 jklos
144 1.1 jklos #define FL_Q_SIZE 4096
145 1.1 jklos #define JUMBO_Q_SIZE 512
146 1.1 jklos #define RSPQ_Q_SIZE 1024
147 1.1 jklos #define TX_ETH_Q_SIZE 1024
148 1.1 jklos
149 1.1 jklos
150 1.1 jklos
151 1.1 jklos /*
152 1.1 jklos * Types of Tx queues in each queue set. Order here matters, do not change.
153 1.1 jklos * XXX TOE is not implemented yet, so the extra queues are just placeholders.
154 1.1 jklos */
155 1.1 jklos enum { TXQ_ETH, TXQ_OFLD, TXQ_CTRL };
156 1.1 jklos
157 1.1 jklos
158 1.1 jklos /* careful, the following are set on priv_flags and must not collide with
159 1.1 jklos * IFF_ flags!
160 1.1 jklos */
161 1.1 jklos enum {
162 1.1 jklos LRO_ACTIVE = (1 << 8),
163 1.1 jklos };
164 1.1 jklos
165 1.1 jklos /* Max concurrent LRO sessions per queue set */
166 1.1 jklos #define MAX_LRO_SES 8
167 1.1 jklos
168 1.1 jklos struct t3_lro_session {
169 1.1 jklos struct mbuf *head;
170 1.1 jklos struct mbuf *tail;
171 1.1 jklos uint32_t seq;
172 1.1 jklos uint16_t ip_len;
173 1.1 jklos uint16_t mss;
174 1.1 jklos uint16_t vtag;
175 1.1 jklos uint8_t npkts;
176 1.1 jklos };
177 1.1 jklos
178 1.1 jklos struct lro_state {
179 1.1 jklos unsigned short enabled;
180 1.1 jklos unsigned short active_idx;
181 1.1 jklos unsigned int nactive;
182 1.1 jklos struct t3_lro_session sess[MAX_LRO_SES];
183 1.1 jklos };
184 1.1 jklos
185 1.1 jklos #define RX_BUNDLE_SIZE 8
186 1.1 jklos
187 1.1 jklos struct rsp_desc;
188 1.1 jklos
189 1.1 jklos struct sge_rspq {
190 1.1 jklos uint32_t credits;
191 1.1 jklos uint32_t size;
192 1.1 jklos uint32_t cidx;
193 1.1 jklos uint32_t gen;
194 1.1 jklos uint32_t polling;
195 1.1 jklos uint32_t holdoff_tmr;
196 1.1 jklos uint32_t next_holdoff;
197 1.1 jklos uint32_t imm_data;
198 1.1 jklos struct rsp_desc *desc;
199 1.1 jklos uint32_t cntxt_id;
200 1.1 jklos struct mtx lock;
201 1.1 jklos struct mbuf *rx_head; /* offload packet receive queue head */
202 1.1 jklos struct mbuf *rx_tail; /* offload packet receive queue tail */
203 1.1 jklos
204 1.1 jklos uint32_t offload_pkts;
205 1.1 jklos uint32_t offload_bundles;
206 1.1 jklos uint32_t pure_rsps;
207 1.1 jklos uint32_t unhandled_irqs;
208 1.1 jklos
209 1.1 jklos bus_addr_t phys_addr;
210 1.1 jklos bus_dma_tag_t desc_tag;
211 1.1 jklos bus_dmamap_t desc_map;
212 1.1 jklos
213 1.1 jklos struct t3_mbuf_hdr rspq_mh;
214 1.1 jklos #define RSPQ_NAME_LEN 32
215 1.1 jklos char lockbuf[RSPQ_NAME_LEN];
216 1.1 jklos
217 1.1 jklos };
218 1.1 jklos
219 1.1 jklos #ifndef DISABLE_MBUF_IOVEC
220 1.1 jklos #define rspq_mbuf rspq_mh.mh_head
221 1.1 jklos #endif
222 1.1 jklos
223 1.1 jklos struct rx_desc;
224 1.1 jklos struct rx_sw_desc;
225 1.1 jklos
226 1.1 jklos struct sge_fl {
227 1.1 jklos uint32_t buf_size;
228 1.1 jklos uint32_t credits;
229 1.1 jklos uint32_t size;
230 1.1 jklos uint32_t cidx;
231 1.1 jklos uint32_t pidx;
232 1.1 jklos uint32_t gen;
233 1.1 jklos struct rx_desc *desc;
234 1.1 jklos struct rx_sw_desc *sdesc;
235 1.1 jklos bus_addr_t phys_addr;
236 1.1 jklos uint32_t cntxt_id;
237 1.1 jklos uint64_t empty;
238 1.1 jklos bus_dma_tag_t desc_tag;
239 1.1 jklos bus_dmamap_t desc_map;
240 1.1 jklos bus_dma_tag_t entry_tag;
241 1.1 jklos int type;
242 1.1 jklos };
243 1.1 jklos
244 1.1 jklos struct tx_desc;
245 1.1 jklos struct tx_sw_desc;
246 1.1 jklos
247 1.1 jklos #define TXQ_TRANSMITTING 0x1
248 1.1 jklos
249 1.1 jklos struct sge_txq {
250 1.1 jklos uint64_t flags;
251 1.1 jklos uint32_t in_use;
252 1.1 jklos uint32_t size;
253 1.1 jklos uint32_t processed;
254 1.1 jklos uint32_t cleaned;
255 1.1 jklos uint32_t stop_thres;
256 1.1 jklos uint32_t cidx;
257 1.1 jklos uint32_t pidx;
258 1.1 jklos uint32_t gen;
259 1.1 jklos uint32_t unacked;
260 1.1 jklos struct tx_desc *desc;
261 1.1 jklos struct tx_sw_desc *sdesc;
262 1.1 jklos uint32_t token;
263 1.1 jklos bus_addr_t phys_addr;
264 1.1 jklos struct cxgb_task qresume_task;
265 1.1 jklos struct cxgb_task qreclaim_task;
266 1.1 jklos struct port_info *port;
267 1.1 jklos uint32_t cntxt_id;
268 1.1 jklos uint64_t stops;
269 1.1 jklos uint64_t restarts;
270 1.1 jklos bus_dma_tag_t desc_tag;
271 1.1 jklos bus_dmamap_t desc_map;
272 1.1 jklos bus_dma_tag_t entry_tag;
273 1.1 jklos struct mbuf_head sendq;
274 1.1 jklos struct mtx lock;
275 1.1 jklos #define TXQ_NAME_LEN 32
276 1.1 jklos char lockbuf[TXQ_NAME_LEN];
277 1.1 jklos };
278 1.1 jklos
279 1.1 jklos
280 1.1 jklos enum {
281 1.1 jklos SGE_PSTAT_TSO, /* # of TSO requests */
282 1.1 jklos SGE_PSTAT_RX_CSUM_GOOD, /* # of successful RX csum offloads */
283 1.1 jklos SGE_PSTAT_TX_CSUM, /* # of TX checksum offloads */
284 1.1 jklos SGE_PSTAT_VLANEX, /* # of VLAN tag extractions */
285 1.1 jklos SGE_PSTAT_VLANINS, /* # of VLAN tag insertions */
286 1.1 jklos SGE_PSTATS_LRO_QUEUED, /* # of LRO appended packets */
287 1.1 jklos SGE_PSTATS_LRO_FLUSHED, /* # of LRO flushed packets */
288 1.1 jklos SGE_PSTATS_LRO_X_STREAMS, /* # of exceeded LRO contexts */
289 1.1 jklos };
290 1.1 jklos
291 1.1 jklos #define SGE_PSTAT_MAX (SGE_PSTATS_LRO_X_STREAMS+1)
292 1.1 jklos
293 1.1 jklos struct sge_qset {
294 1.1 jklos struct sge_rspq rspq;
295 1.1 jklos struct sge_fl fl[SGE_RXQ_PER_SET];
296 1.1 jklos struct lro_state lro;
297 1.1 jklos struct sge_txq txq[SGE_TXQ_PER_SET];
298 1.1 jklos uint32_t txq_stopped; /* which Tx queues are stopped */
299 1.1 jklos uint64_t port_stats[SGE_PSTAT_MAX];
300 1.1 jklos struct port_info *port;
301 1.1 jklos int idx; /* qset # */
302 1.1 jklos };
303 1.1 jklos
304 1.1 jklos struct sge {
305 1.1 jklos struct sge_qset qs[SGE_QSETS];
306 1.1 jklos struct mtx reg_lock;
307 1.1 jklos };
308 1.1 jklos
309 1.1 jklos struct filter_info;
310 1.1 jklos
311 1.1 jklos struct adapter {
312 1.1 jklos device_t dev; // so we have a compatible pointer
313 1.1 jklos int flags;
314 1.1 jklos TAILQ_ENTRY(adapter) adapter_entry;
315 1.1 jklos
316 1.1 jklos /* PCI register resources */
317 1.1 jklos int regs_rid;
318 1.1 jklos struct resource *regs_res;
319 1.1 jklos bus_space_handle_t bh;
320 1.1 jklos bus_space_tag_t bt;
321 1.1 jklos bus_size_t mmio_len;
322 1.1 jklos uint32_t link_width;
323 1.1 jklos struct pci_attach_args pa;
324 1.1 jklos uint32_t bar0;
325 1.1 jklos bus_space_handle_t bar0_handle;
326 1.1 jklos pci_intr_handle_t intr_handle;
327 1.1 jklos void *intr_cookie;
328 1.1 jklos
329 1.1 jklos /* DMA resources */
330 1.1 jklos bus_dma_tag_t parent_dmat;
331 1.1 jklos bus_dma_tag_t rx_dmat;
332 1.1 jklos bus_dma_tag_t rx_jumbo_dmat;
333 1.1 jklos bus_dma_tag_t tx_dmat;
334 1.1 jklos
335 1.1 jklos /* Interrupt resources */
336 1.1 jklos int irq_rid;
337 1.1 jklos
338 1.1 jklos uint32_t msix_regs_rid;
339 1.1 jklos struct resource *msix_regs_res;
340 1.1 jklos
341 1.1 jklos struct resource *msix_irq_res[SGE_QSETS];
342 1.1 jklos int msix_irq_rid[SGE_QSETS];
343 1.1 jklos void *msix_intr_tag[SGE_QSETS];
344 1.1 jklos uint8_t rxpkt_map[8]; /* maps RX_PKT interface values to port ids */
345 1.1 jklos uint8_t rrss_map[SGE_QSETS]; /* revers RSS map table */
346 1.1 jklos
347 1.1 jklos struct filter_info *filters;
348 1.1 jklos
349 1.1 jklos /* Tasks */
350 1.1 jklos struct cxgb_task ext_intr_task;
351 1.1 jklos struct cxgb_task slow_intr_task;
352 1.1 jklos struct cxgb_task tick_task;
353 1.1 jklos struct callout cxgb_tick_ch;
354 1.1 jklos struct callout sge_timer_ch;
355 1.1 jklos
356 1.1 jklos /* Register lock for use by the hardware layer */
357 1.1 jklos struct mtx mdio_lock;
358 1.1 jklos struct mtx elmer_lock;
359 1.1 jklos
360 1.1 jklos /* Bookkeeping for the hardware layer */
361 1.1 jklos struct adapter_params params;
362 1.1 jklos unsigned int slow_intr_mask;
363 1.1 jklos unsigned long irq_stats[IRQ_NUM_STATS];
364 1.1 jklos
365 1.1 jklos struct sge sge;
366 1.1 jklos struct mc7 pmrx;
367 1.1 jklos struct mc7 pmtx;
368 1.1 jklos struct mc7 cm;
369 1.1 jklos struct mc5 mc5;
370 1.1 jklos
371 1.1 jklos struct port_info port[MAX_NPORTS];
372 1.1 jklos device_t portdev[MAX_NPORTS];
373 1.1 jklos struct toedev tdev;
374 1.1 jklos char fw_version[64];
375 1.1 jklos uint32_t open_device_map;
376 1.1 jklos uint32_t registered_device_map;
377 1.1 jklos #ifdef USE_SX
378 1.1 jklos struct sx lock;
379 1.1 jklos #else
380 1.1 jklos struct mtx lock;
381 1.1 jklos #endif
382 1.1 jklos int (*cxgb_intr)(void *);
383 1.1 jklos int msi_count;
384 1.1 jklos
385 1.1 jklos #define ADAPTER_LOCK_NAME_LEN 32
386 1.1 jklos char lockbuf[ADAPTER_LOCK_NAME_LEN];
387 1.1 jklos char reglockbuf[ADAPTER_LOCK_NAME_LEN];
388 1.1 jklos char mdiolockbuf[ADAPTER_LOCK_NAME_LEN];
389 1.1 jklos char elmerlockbuf[ADAPTER_LOCK_NAME_LEN];
390 1.1 jklos };
391 1.1 jklos
392 1.1 jklos struct t3_rx_mode {
393 1.1 jklos
394 1.1 jklos uint32_t idx;
395 1.1 jklos struct port_info *port;
396 1.1 jklos };
397 1.1 jklos
398 1.1 jklos
399 1.1 jklos #define MDIO_LOCK(adapter) mtx_lock(&(adapter)->mdio_lock)
400 1.1 jklos #define MDIO_UNLOCK(adapter) mtx_unlock(&(adapter)->mdio_lock)
401 1.1 jklos #define ELMR_LOCK(adapter) mtx_lock(&(adapter)->elmer_lock)
402 1.1 jklos #define ELMR_UNLOCK(adapter) mtx_unlock(&(adapter)->elmer_lock)
403 1.1 jklos
404 1.1 jklos
405 1.1 jklos #ifdef USE_SX
406 1.1 jklos #define PORT_LOCK(port) sx_xlock(&(port)->lock);
407 1.1 jklos #define PORT_UNLOCK(port) sx_xunlock(&(port)->lock);
408 1.1 jklos #define PORT_LOCK_INIT(port, name) SX_INIT(&(port)->lock, name)
409 1.1 jklos #define PORT_LOCK_DEINIT(port) SX_DESTROY(&(port)->lock)
410 1.1 jklos #define PORT_LOCK_ASSERT_OWNED(port) sx_assert(&(port)->lock, SA_LOCKED)
411 1.1 jklos
412 1.1 jklos #define ADAPTER_LOCK(adap) sx_xlock(&(adap)->lock);
413 1.1 jklos #define ADAPTER_UNLOCK(adap) sx_xunlock(&(adap)->lock);
414 1.1 jklos #define ADAPTER_LOCK_INIT(adap, name) SX_INIT(&(adap)->lock, name)
415 1.1 jklos #define ADAPTER_LOCK_DEINIT(adap) SX_DESTROY(&(adap)->lock)
416 1.1 jklos #define ADAPTER_LOCK_ASSERT_NOTOWNED(adap) sx_assert(&(adap)->lock, SA_UNLOCKED)
417 1.1 jklos #else
418 1.1 jklos #define PORT_LOCK(port) mtx_lock(&(port)->lock);
419 1.1 jklos #define PORT_UNLOCK(port) mtx_unlock(&(port)->lock);
420 1.1 jklos #define PORT_LOCK_INIT(port, name) mtx_init(&(port)->lock, name, 0, MTX_DEF)
421 1.1 jklos #define PORT_LOCK_DEINIT(port) mtx_destroy(&(port)->lock)
422 1.1 jklos #define PORT_LOCK_ASSERT_OWNED(port) mtx_assert(&(port)->lock, MA_OWNED)
423 1.1 jklos
424 1.1 jklos #define ADAPTER_LOCK(adap) mtx_lock(&(adap)->lock);
425 1.1 jklos #define ADAPTER_UNLOCK(adap) mtx_unlock(&(adap)->lock);
426 1.1 jklos #define ADAPTER_LOCK_INIT(adap, name) mtx_init(&(adap)->lock, name, 0, MTX_DEF)
427 1.1 jklos #define ADAPTER_LOCK_DEINIT(adap) mtx_destroy(&(adap)->lock)
428 1.1 jklos #define ADAPTER_LOCK_ASSERT_NOTOWNED(adap) mtx_assert(&(adap)->lock, MA_NOTOWNED)
429 1.1 jklos #endif
430 1.1 jklos
431 1.1 jklos
432 1.1 jklos static __inline uint32_t
433 1.1 jklos t3_read_reg(adapter_t *adapter, uint32_t reg_addr)
434 1.1 jklos {
435 1.1 jklos return (bus_space_read_4(adapter->bt, adapter->bh, reg_addr));
436 1.1 jklos }
437 1.1 jklos
438 1.1 jklos static __inline void
439 1.1 jklos t3_write_reg(adapter_t *adapter, uint32_t reg_addr, uint32_t val)
440 1.1 jklos {
441 1.1 jklos bus_space_write_4(adapter->bt, adapter->bh, reg_addr, val);
442 1.1 jklos }
443 1.1 jklos
444 1.1 jklos static __inline void
445 1.1 jklos t3_os_pci_read_config_4(adapter_t *adapter, int reg, uint32_t *val)
446 1.1 jklos {
447 1.1 jklos *val = pci_conf_read(adapter->pa.pa_pc, adapter->pa.pa_tag, reg);
448 1.1 jklos }
449 1.1 jklos
450 1.1 jklos static __inline void
451 1.1 jklos t3_os_pci_write_config_4(adapter_t *adapter, int reg, uint32_t val)
452 1.1 jklos {
453 1.1 jklos pci_conf_write(adapter->pa.pa_pc, adapter->pa.pa_tag, reg, val);
454 1.1 jklos }
455 1.1 jklos
456 1.1 jklos static __inline void
457 1.1 jklos t3_os_pci_read_config_2(adapter_t *adapter, int reg, uint16_t *val)
458 1.1 jklos {
459 1.1 jklos uint32_t temp;
460 1.1 jklos temp = pci_conf_read(adapter->pa.pa_pc, adapter->pa.pa_tag, reg&0xfc);
461 1.1 jklos if (reg&0x2)
462 1.1 jklos *val = (temp>>16)&0xffff;
463 1.1 jklos else
464 1.1 jklos *val = temp&0xffff;
465 1.1 jklos }
466 1.1 jklos
467 1.1 jklos static __inline void
468 1.1 jklos t3_os_pci_write_config_2(adapter_t *adapter, int reg, uint16_t val)
469 1.1 jklos {
470 1.1 jklos uint32_t temp = pci_conf_read(adapter->pa.pa_pc, adapter->pa.pa_tag, reg&0xfc);
471 1.1 jklos if (reg&0x2)
472 1.1 jklos temp = (temp&0xffff)|(val<<16);
473 1.1 jklos else
474 1.1 jklos temp = (temp&0xffff0000)|val;
475 1.1 jklos pci_conf_write(adapter->pa.pa_pc, adapter->pa.pa_tag, reg&0xfc, temp);
476 1.1 jklos }
477 1.1 jklos
478 1.1 jklos static __inline uint8_t *
479 1.1 jklos t3_get_next_mcaddr(struct t3_rx_mode *rm)
480 1.1 jklos {
481 1.1 jklos uint8_t *macaddr = NULL;
482 1.1 jklos
483 1.1 jklos if (rm->idx == 0)
484 1.1 jklos macaddr = rm->port->hw_addr;
485 1.1 jklos
486 1.1 jklos rm->idx++;
487 1.1 jklos return (macaddr);
488 1.1 jklos }
489 1.1 jklos
490 1.1 jklos static __inline void
491 1.1 jklos t3_init_rx_mode(struct t3_rx_mode *rm, struct port_info *port)
492 1.1 jklos {
493 1.1 jklos rm->idx = 0;
494 1.1 jklos rm->port = port;
495 1.1 jklos }
496 1.1 jklos
497 1.1 jklos static __inline struct port_info *
498 1.1 jklos adap2pinfo(struct adapter *adap, int idx)
499 1.1 jklos {
500 1.1 jklos return &adap->port[idx];
501 1.1 jklos }
502 1.1 jklos
503 1.1 jklos int t3_os_find_pci_capability(adapter_t *adapter, int cap);
504 1.1 jklos int t3_os_pci_save_state(struct adapter *adapter);
505 1.1 jklos int t3_os_pci_restore_state(struct adapter *adapter);
506 1.1 jklos void t3_os_link_changed(adapter_t *adapter, int port_id, int link_status,
507 1.1 jklos int speed, int duplex, int fc);
508 1.1 jklos void t3_sge_err_intr_handler(adapter_t *adapter);
509 1.1 jklos int t3_offload_tx(struct toedev *, struct mbuf *);
510 1.1 jklos void t3_os_ext_intr_handler(adapter_t *adapter);
511 1.1 jklos void t3_os_set_hw_addr(adapter_t *adapter, int port_idx, u8 hw_addr[]);
512 1.1 jklos int t3_mgmt_tx(adapter_t *adap, struct mbuf *m);
513 1.1 jklos
514 1.1 jklos
515 1.1 jklos int t3_sge_alloc(struct adapter *);
516 1.1 jklos int t3_sge_free(struct adapter *);
517 1.1 jklos int t3_sge_alloc_qset(adapter_t *, uint32_t, int, int, const struct qset_params *,
518 1.1 jklos int, struct port_info *);
519 1.1 jklos void t3_free_sge_resources(adapter_t *);
520 1.1 jklos void t3_sge_start(adapter_t *);
521 1.1 jklos void t3_sge_stop(adapter_t *);
522 1.1 jklos int t3b_intr(void *data);
523 1.1 jklos int t3_intr_msi(void *data);
524 1.1 jklos int t3_intr_msix(void *data);
525 1.1 jklos int t3_encap(struct port_info *, struct mbuf **, int *free);
526 1.1 jklos
527 1.1 jklos int t3_sge_init_adapter(adapter_t *);
528 1.1 jklos int t3_sge_init_port(struct port_info *);
529 1.1 jklos void t3_sge_deinit_sw(adapter_t *);
530 1.1 jklos
531 1.1 jklos void t3_rx_eth_lro(adapter_t *adap, struct sge_rspq *rq, struct mbuf *m,
532 1.1 jklos int ethpad, uint32_t rss_hash, uint32_t rss_csum, int lro);
533 1.1 jklos void t3_rx_eth(struct adapter *adap, struct sge_rspq *rq, struct mbuf *m, int ethpad);
534 1.1 jklos void t3_lro_flush(adapter_t *adap, struct sge_qset *qs, struct lro_state *state);
535 1.1 jklos
536 1.1 jklos void t3_add_sysctls(adapter_t *sc);
537 1.1 jklos int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
538 1.1 jklos unsigned char *data);
539 1.1 jklos void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
540 1.1 jklos /*
541 1.1 jklos * XXX figure out how we can return this to being private to sge
542 1.1 jklos */
543 1.1 jklos #define desc_reclaimable(q) ((int)((q)->processed - (q)->cleaned - TX_MAX_DESC))
544 1.1 jklos
545 1.1 jklos #define container_of(p, stype, field) ((stype *)(((uint8_t *)(p)) - offsetof(stype, field)))
546 1.1 jklos
547 1.1 jklos static __inline struct sge_qset *
548 1.1 jklos fl_to_qset(struct sge_fl *q, int qidx)
549 1.1 jklos {
550 1.1 jklos return container_of(q, struct sge_qset, fl[qidx]);
551 1.1 jklos }
552 1.1 jklos
553 1.1 jklos static __inline struct sge_qset *
554 1.1 jklos rspq_to_qset(struct sge_rspq *q)
555 1.1 jklos {
556 1.1 jklos return container_of(q, struct sge_qset, rspq);
557 1.1 jklos }
558 1.1 jklos
559 1.1 jklos static __inline struct sge_qset *
560 1.1 jklos txq_to_qset(struct sge_txq *q, int qidx)
561 1.1 jklos {
562 1.1 jklos return container_of(q, struct sge_qset, txq[qidx]);
563 1.1 jklos }
564 1.1 jklos
565 1.1 jklos static __inline struct adapter *
566 1.1 jklos tdev2adap(struct toedev *d)
567 1.1 jklos {
568 1.1 jklos return container_of(d, struct adapter, tdev);
569 1.1 jklos }
570 1.1 jklos
571 1.1 jklos #undef container_of
572 1.1 jklos
573 1.1 jklos #define OFFLOAD_DEVMAP_BIT 15
574 1.4 christos static __inline int offload_running(adapter_t *adapter)
575 1.1 jklos {
576 1.1 jklos return isset(&adapter->open_device_map, OFFLOAD_DEVMAP_BIT);
577 1.1 jklos }
578 1.1 jklos
579 1.1 jklos
580 1.1 jklos #endif
581