Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/myri10ge/drv/myri10ge_var.h
+++ new/usr/src/uts/common/io/myri10ge/drv/myri10ge_var.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2007-2009 Myricom, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #ifndef MYRI10GE_VAR_H
28 28 #define MYRI10GE_VAR_H
29 29
30 30 #ifdef __cplusplus
31 31 extern "C" {
32 32 #endif
33 33
34 34 #include <sys/types.h>
35 35 #include <sys/errno.h>
36 36 #include <sys/param.h>
37 37 #include <sys/atomic.h>
38 38 #include <sys/stropts.h>
39 39 #include <sys/stream.h>
40 40 #include <sys/kmem.h>
41 41 #include <sys/ksynch.h>
42 42 #include <sys/stat.h>
43 43 #include <sys/modctl.h>
44 44 #include <sys/debug.h>
45 45 #include <sys/dlpi.h>
46 46 #include <sys/ethernet.h>
47 47 #include <sys/mac_provider.h>
48 48 #define MAC_CAPAB_POLL 0
49 49 #define MC_RESOURCES 0
50 50 #include <sys/mac_ether.h>
51 51 #ifndef MYRICOM_PRIV
52 52 #include <sys/vlan.h>
53 53 #endif
54 54 #include <sys/pci.h>
55 55 #include <sys/pcie.h>
56 56 #include <sys/ddi.h>
57 57 #include <sys/sunddi.h>
58 58 #include <sys/strsubr.h> /* for hw cksum stuff */
59 59 #include <sys/pattr.h> /* for hw cksum stuff */
60 60 #include <netinet/in.h> /* for hw cksum stuff */
61 61 #include <netinet/ip.h> /* for hw cksum stuff */
62 62 #include <netinet/ip6.h> /* for hw cksum stuff */
63 63 #include <netinet/tcp.h> /* for hw cksum stuff */
64 64 #include <netinet/udp.h> /* for hw cksum stuff */
65 65 #include <sys/strsun.h>
66 66 #include <inet/common.h>
67 67 #include <inet/mi.h>
68 68 #include <inet/nd.h>
69 69 #include <sys/zmod.h>
70 70 #include <sys/cpuvar.h>
71 71 #include <sys/proc.h>
72 72 #include <sys/callb.h>
73 73
74 74 #include "myri10ge_mcp.h"
75 75 #include "myri10ge_version.h"
76 76
77 77 #define MYRI10GE_FW_OFFSET 1024*1024
78 78 #define MYRI10GE_EEPROM_STRINGS_SIZE 256
79 79 #define MYRI10GE_HIGHPART_TO_U32(X) \
80 80 (sizeof (X) == 8) ? ((uint32_t)((uint64_t)(X) >> 32)) : (0)
81 81 #define MYRI10GE_LOWPART_TO_U32(X) ((uint32_t)(X))
82 82
83 83 #define MYRI10GE_DDI_REG_SET_32_BIT_MEMORY_SPACE 2
84 84 #define MYRI10GE_DDI_REG_SET_64_BIT_MEMORY_SPACE 3
85 85
86 86 /*
87 87 * Max descriptors a TSO send can use; worst case is every descriptor
88 88 * crosses a 2KB boundary, as do the headers
89 89 */
90 90
91 91 #define MYRI10GE_MAX_SEND_DESC_TSO (2 + (65536 / 2048) * 2)
92 92
93 93 #ifdef MYRICOM_PRIV
94 94 #define VLAN_TAGSZ 4
95 95 #endif
96 96
97 97 #if defined DDI_INTR_IS_MSI_OR_MSIX
98 98 #define MYRI10GE_USE_MSI 1
99 99 #else
100 100 #define MYRI10GE_USE_MSI 0
101 101 #endif
102 102
103 103
104 104 struct myri10ge_dma_stuff {
105 105 ddi_dma_handle_t handle;
106 106 ddi_acc_handle_t acc_handle;
107 107 uint32_t low;
108 108 uint32_t high;
109 109 };
110 110
111 111 typedef struct myri10ge_mblkq {
112 112 struct myri10ge_priv *mgp;
113 113 kmutex_t lock;
114 114 mblk_t *head;
115 115 mblk_t *tail;
116 116 unsigned long cnt;
117 117 } myri10ge_mblkq_t;
118 118
119 119 typedef struct {
120 120 mcp_slot_t *entry;
121 121 struct myri10ge_dma_stuff dma;
122 122 int cnt;
123 123 int idx;
124 124 } myri10ge_rx_done_t;
125 125
126 126
127 127 typedef struct
128 128 {
129 129 uint32_t data0;
130 130 uint32_t data1;
131 131 uint32_t data2;
132 132 } myri10ge_cmd_t;
133 133
134 134 struct myri10ge_pci_saved_state {
135 135 uint32_t base[16];
136 136 uint32_t msi_addr_low;
137 137 uint32_t msi_addr_high;
138 138 uint16_t msi_data_32;
139 139 uint16_t msi_data_64;
140 140 uint16_t msi_ctrl;
141 141 };
142 142
143 143 struct myri10ge_jpool_entry;
144 144
145 145 struct myri10ge_jpool_entry {
146 146 struct myri10ge_jpool_entry *next;
147 147 ddi_dma_handle_t dma_handle;
148 148 ddi_acc_handle_t acc_handle;
149 149 caddr_t buf;
150 150 struct myri10ge_slice_state *ss;
151 151 mcp_dma_addr_t dma; /* Kept in network byte order */
152 152 frtn_t free_func;
153 153 };
154 154
155 155 #define MYRI10GE_CPU_CACHE_SZ 64
156 156 struct myri10ge_per_cpu_jpool {
157 157 struct myri10ge_jpool_entry *head;
158 158 uint8_t _pad[MYRI10GE_CPU_CACHE_SZ - sizeof (void *)];
159 159 };
160 160
161 161 #define MYRI10GE_MAX_CPUS 64
162 162 #define MYRI10GE_MAX_CPU_MASK (64 - 1)
163 163
164 164 struct myri10ge_jpool_stuff {
165 165 struct myri10ge_jpool_entry *head;
166 166 struct myri10ge_per_cpu_jpool cpu[MYRI10GE_MAX_CPUS];
167 167 kmutex_t mtx;
168 168 int num_alloc;
169 169 int low_water;
170 170 };
171 171
172 172 struct myri10ge_tx_ring_stats
173 173 {
174 174 uint64_t multixmt;
175 175 uint64_t brdcstxmt;
176 176 uint64_t opackets;
177 177 uint64_t obytes;
178 178 };
179 179
180 180 struct myri10ge_rx_ring_stats
181 181 {
182 182 uint64_t multircv;
183 183 uint64_t brdcstrcv;
184 184 uint64_t ipackets;
185 185 uint64_t ibytes;
186 186 };
187 187
188 188 struct myri10ge_tx_ring_entry_stats
189 189 {
190 190 uint32_t obytes;
191 191 uint16_t opackets;
192 192 uint8_t brdcstxmt;
193 193 uint8_t multixmt;
194 194 };
195 195
196 196 struct myri10ge_tx_pkt_stats {
197 197 union {
198 198 uint64_t all;
199 199 struct myri10ge_tx_ring_entry_stats s;
200 200 } un;
201 201 };
202 202
203 203 #define ostat stat.un.s
204 204
205 205 struct myri10ge_tx_dma_handle {
206 206 struct myri10ge_tx_dma_handle *next;
207 207 ddi_dma_handle_t h;
208 208 };
209 209
210 210 struct myri10ge_tx_dma_handle_head {
211 211 struct myri10ge_tx_dma_handle *head;
212 212 struct myri10ge_tx_dma_handle *tail;
213 213 };
214 214
215 215 struct myri10ge_rx_buffer_state {
216 216 caddr_t ptr;
217 217 struct myri10ge_jpool_entry *j;
218 218 };
219 219
220 220 struct myri10ge_tx_buffer_state {
221 221 mblk_t *m;
222 222 struct myri10ge_tx_dma_handle *handle;
223 223 struct myri10ge_tx_pkt_stats stat;
224 224 };
225 225
226 226 struct myri10ge_nic_stat {
227 227 struct kstat_named dma_force_physical;
228 228 struct kstat_named dma_read_bw_MBs;
229 229 struct kstat_named dma_write_bw_MBs;
230 230 struct kstat_named dma_read_write_bw_MBs;
231 231 struct kstat_named lanes;
232 232 struct kstat_named dropped_bad_crc32;
233 233 struct kstat_named dropped_bad_phy;
234 234 struct kstat_named dropped_link_error_or_filtered;
235 235 struct kstat_named dropped_link_overflow;
236 236 struct kstat_named dropped_multicast_filtered;
237 237 struct kstat_named dropped_no_big_buffer;
238 238 struct kstat_named dropped_no_small_buffer;
239 239 struct kstat_named dropped_overrun;
240 240 struct kstat_named dropped_pause;
241 241 struct kstat_named dropped_runt;
242 242 struct kstat_named dropped_unicast_filtered;
243 243 struct kstat_named link_changes;
244 244 struct kstat_named link_up;
245 245 };
246 246
247 247 struct myri10ge_slice_stat {
248 248 struct kstat_named lro_bad_csum;
249 249 struct kstat_named lro_flushed;
250 250 struct kstat_named lro_queued;
251 251 struct kstat_named rx_big;
252 252 struct kstat_named rx_bigbuf_firmware;
253 253 struct kstat_named rx_bigbuf_pool;
254 254 struct kstat_named rx_bigbuf_smalls;
255 255 struct kstat_named rx_copy;
256 256 struct kstat_named rx_small;
257 257 struct kstat_named rx_big_nobuf;
258 258 struct kstat_named rx_small_nobuf;
259 259 struct kstat_named tx_activate;
260 260 struct kstat_named tx_done;
261 261 struct kstat_named tx_handles_alloced;
262 262 struct kstat_named tx_req;
263 263 struct kstat_named xmit_err;
264 264 struct kstat_named xmit_lowbuf;
265 265 struct kstat_named xmit_lsobadflags;
266 266 struct kstat_named xmit_pullup;
267 267 struct kstat_named xmit_pullup_first;
268 268 struct kstat_named xmit_sched;
269 269 struct kstat_named xmit_stall;
270 270 struct kstat_named xmit_stall_early;
271 271 struct kstat_named xmit_stall_late;
272 272 struct kstat_named xmit_zero_len;
273 273 };
274 274
275 275 struct myri10ge_info {
276 276 struct kstat_named driver_version;
277 277 struct kstat_named firmware_version;
278 278 struct kstat_named firmware_name;
279 279 struct kstat_named interrupt_type;
280 280 struct kstat_named product_code;
281 281 struct kstat_named serial_number;
282 282 };
283 283
↓ open down ↓ |
283 lines elided |
↑ open up ↑ |
284 284
285 285 #define MYRI10GE_NIC_STAT_INC(field) \
286 286 (((struct myri10ge_nic_stat *)mgp->ksp_stat->ks_data)->field.value.ul)++
287 287 #define MYRI10GE_SLICE_STAT_INC(field) \
288 288 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)++
289 289 #define MYRI10GE_SLICE_STAT_ADD(field, val) \
290 290 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul) += val
291 291 #define MYRI10GE_SLICE_STAT_DEC(field) \
292 292 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)--
293 293 #define MYRI10GE_ATOMIC_SLICE_STAT_INC(field) \
294 -atomic_add_long(&(((struct myri10ge_slice_stat *) \
295 - ss->ksp_stat->ks_data)->field.value.ul), 1)
294 +atomic_inc_ulong(&(((struct myri10ge_slice_stat *) \
295 + ss->ksp_stat->ks_data)->field.value.ul))
296 296 #define MYRI10GE_ATOMIC_SLICE_STAT_DEC(field) \
297 -atomic_add_long(&(((struct myri10ge_slice_stat *) \
298 - ss->ksp_stat->ks_data)->field.value.ul), -1)
297 +atomic_dec_ulong(&(((struct myri10ge_slice_stat *) \
298 + ss->ksp_stat->ks_data)->field.value.ul))
299 299 #define MYRI10GE_SLICE_STAT(field) \
300 300 (((struct myri10ge_slice_stat *)ss->ksp_stat->ks_data)->field.value.ul)
301 301
302 302
303 303 struct myri10ge_tx_copybuf
304 304 {
305 305 caddr_t va;
306 306 int len;
307 307 struct myri10ge_dma_stuff dma;
308 308 };
309 309
310 310 typedef struct
311 311 {
312 312 mcp_kreq_ether_recv_t *lanai; /* lanai ptr for recv ring */
313 313 mcp_kreq_ether_recv_t *shadow; /* host shadow of recv ring */
314 314 struct myri10ge_rx_buffer_state *info;
315 315 int cnt;
316 316 int alloc_fail;
317 317 int mask; /* number of rx slots -1 */
318 318 boolean_t polling;
319 319 } myri10ge_rx_ring_t;
320 320
321 321 typedef struct
322 322 {
323 323 mcp_kreq_ether_send_t *lanai; /* lanai ptr for sendq */
324 324 char *go; /* doorbell to poll sendq */
325 325 char *stop; /* doorbell to !poll sendq */
326 326 struct myri10ge_tx_buffer_state *info;
327 327 struct myri10ge_tx_copybuf *cp;
328 328 int req; /* transmits submitted */
329 329 int mask; /* number of transmit slots -1 */
330 330 int done; /* transmits completed */
331 331 int pkt_done; /* packets completed */
332 332 int active;
333 333 uint32_t stall;
334 334 uint32_t stall_early;
335 335 uint32_t stall_late;
336 336 int sched;
337 337 kmutex_t lock;
338 338 struct myri10ge_tx_ring_stats stats;
339 339 int watchdog_req;
340 340 int watchdog_done;
341 341 unsigned long activate;
342 342 kmutex_t handle_lock;
343 343 struct myri10ge_tx_dma_handle *free_tx_handles;
344 344 mac_ring_handle_t rh;
345 345 } myri10ge_tx_ring_t;
346 346
347 347 struct lro_entry;
348 348
349 349 struct lro_entry
350 350 {
351 351 struct lro_entry *next;
352 352 mblk_t *m_head;
353 353 mblk_t *m_tail;
354 354 int timestamp;
355 355 struct ip *ip;
356 356 uint32_t tsval;
357 357 uint32_t tsecr;
358 358 uint32_t source_ip;
359 359 uint32_t dest_ip;
360 360 uint32_t next_seq;
361 361 uint32_t ack_seq;
362 362 uint32_t len;
363 363 uint32_t data_csum;
364 364 uint16_t window;
365 365 uint16_t source_port;
366 366 uint16_t dest_port;
367 367 uint16_t append_cnt;
368 368 uint16_t mss;
369 369 uint8_t flags;
370 370 };
371 371
372 372 struct myri10ge_mblk_list
373 373 {
374 374 mblk_t *head;
375 375 mblk_t **tail;
376 376 int cnt;
377 377 };
378 378
379 379 struct myri10ge_priv;
380 380
381 381 struct myri10ge_slice_state {
382 382 struct myri10ge_priv *mgp;
383 383 myri10ge_tx_ring_t tx; /* transmit ring */
384 384 myri10ge_rx_ring_t rx_small;
385 385 myri10ge_rx_ring_t rx_big;
386 386 myri10ge_rx_done_t rx_done;
387 387 struct myri10ge_jpool_stuff jpool;
388 388 struct myri10ge_rx_ring_stats rx_stats;
389 389 volatile uint32_t *irq_claim;
390 390 mcp_irq_data_t *fw_stats;
391 391 struct lro_entry *lro_active;
392 392 struct lro_entry *lro_free;
393 393 struct myri10ge_dma_stuff fw_stats_dma;
394 394 int jbufs_for_smalls;
395 395 struct myri10ge_jpool_entry *small_jpool;
396 396 int j_rx_cnt;
397 397 mac_resource_handle_t mrh;
398 398 kstat_t *ksp_stat;
399 399 mac_ring_handle_t rx_rh;
400 400 kmutex_t rx_lock;
401 401 kmutex_t poll_lock;
402 402 uint64_t rx_gen_num;
403 403 boolean_t rx_polling;
404 404 int rx_token;
405 405 int watchdog_rx_copy;
406 406 };
407 407
408 408 struct myri10ge_priv {
409 409 struct myri10ge_slice_state *ss;
410 410 int max_intr_slots;
411 411 int num_slices;
412 412 dev_info_t *dip;
413 413 mac_handle_t mh;
414 414 ddi_acc_handle_t io_handle;
415 415 int tx_boundary;
416 416 int watchdog_rx_pause;
417 417 kstat_t *ksp_stat;
418 418 kstat_t *ksp_info;
419 419 int running; /* running? */
420 420 int csum_flag; /* rx_csums? */
421 421 uint8_t mac_addr[6]; /* eeprom mac address */
422 422 volatile uint8_t *sram;
423 423 int sram_size;
424 424 unsigned long board_span;
425 425 unsigned long iomem_base;
426 426 volatile uint32_t *irq_deassert;
427 427 char *mac_addr_string;
428 428 mcp_cmd_response_t *cmd;
429 429 struct myri10ge_dma_stuff cmd_dma;
430 430 int msi_enabled;
431 431 int link_state;
432 432 int rdma_tags_available;
433 433 int intr_coal_delay;
434 434 volatile uint32_t *intr_coal_delay_ptr;
435 435 kmutex_t cmd_lock;
436 436 kmutex_t intrlock;
437 437 int down_cnt;
438 438 int watchdog_resets;
439 439 unsigned char *eth_z8e;
440 440 unsigned int eth_z8e_length;
441 441 ddi_iblock_cookie_t icookie;
442 442 ddi_intr_handle_t *htable;
443 443 int intr_size;
444 444 int intr_cnt;
445 445 int intr_cap;
446 446 unsigned int intr_pri;
447 447 int ddi_intr_type;
448 448 int pause;
449 449 timeout_id_t timer_id;
450 450 clock_t timer_ticks;
451 451 int vso;
452 452 uint32_t mcp_index;
453 453 char fw_version[128];
454 454 char name[32];
455 455 char *fw_name;
456 456 char *intr_type;
457 457 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
458 458 char *sn_str;
459 459 char *pc_str;
460 460 uint32_t read_dma;
461 461 uint32_t write_dma;
462 462 uint32_t read_write_dma;
463 463 uint32_t pcie_link_width;
464 464 int max_read_request_4k;
465 465 caddr_t nd_head;
466 466 struct myri10ge_priv *next;
467 467 uint_t refcnt;
468 468 int reg_set;
469 469 int features;
470 470 struct myri10ge_pci_saved_state pci_saved_state;
471 471 uint32_t *toeplitz_hash_table;
472 472 uint32_t rss_key[8];
473 473 ddi_acc_handle_t cfg_hdl;
474 474 int macaddr_cnt;
475 475 };
476 476
477 477 /* features bitmask */
478 478 #define MYRI10GE_TSO 1
479 479
480 480 #if defined(__GNUC__)
481 481 #define likely(x) __builtin_expect((x), 1)
482 482 #define unlikely(x) __builtin_expect((x), 0)
483 483 #else
484 484 #define likely(x) (x)
485 485 #define unlikely(x) (x)
486 486 #endif /* defined(__GNUC__) */
487 487
488 488 #define mb membar_producer
489 489
490 490 struct myri10ge_priv *myri10ge_get_instance(uint_t unit);
491 491 void myri10ge_put_instance(struct myri10ge_priv *);
492 492 int myri10ge_send_cmd(struct myri10ge_priv *mgp, uint32_t cmd,
493 493 myri10ge_cmd_t *data);
494 494 caddr_t myri10ge_dma_alloc(dev_info_t *dip, size_t len,
495 495 ddi_dma_attr_t *attr, ddi_device_acc_attr_t *accattr,
496 496 uint_t alloc_flags, int bind_flags, struct myri10ge_dma_stuff *dma,
497 497 int warn, int (*waitfp)(caddr_t));
498 498 void myri10ge_dma_free(struct myri10ge_dma_stuff *dma);
499 499
500 500 void myri10ge_lro_flush(struct myri10ge_slice_state *ss,
501 501 struct lro_entry *lro, struct myri10ge_mblk_list *mbl);
502 502 int myri10ge_lro_rx(struct myri10ge_slice_state *ss, mblk_t *m_head,
503 503 uint32_t csum, struct myri10ge_mblk_list *mbl);
504 504 void myri10ge_mbl_append(struct myri10ge_slice_state *ss,
505 505 struct myri10ge_mblk_list *mbl, mblk_t *mp);
506 506 uint16_t myri10ge_csum_generic(uint16_t *raw, int len);
507 507 extern int myri10ge_lro_max_aggr;
508 508 extern int myri10ge_mtu;
509 509
510 510 #ifndef ETHERNET_HEADER_SIZE
511 511 #define ETHERNET_HEADER_SIZE 14
512 512 #endif
513 513
514 514 #define MYRI10GE_TOEPLITZ_HASH (MXGEFW_RSS_HASH_TYPE_TCP_IPV4|\
515 515 MXGEFW_RSS_HASH_TYPE_IPV4)
516 516 #define MYRI10GE_POLL_NULL INT_MAX
517 517
518 518 /*
519 519 * This file uses MyriGE driver indentation.
520 520 *
521 521 * Local Variables:
522 522 * c-file-style:"sun"
523 523 * tab-width:8
524 524 * End:
525 525 */
526 526
527 527 #ifdef __cplusplus
528 528 }
529 529 #endif
530 530
531 531 #endif /* MYRI10GE_VAR_H */
↓ open down ↓ |
223 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX