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