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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_HXGE_HXGE_IMPL_H 27 #define _SYS_HXGE_HXGE_IMPL_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #ifndef _ASM 34 #include <sys/types.h> 35 #include <sys/byteorder.h> 36 #include <sys/debug.h> 37 #include <sys/stropts.h> 38 #include <sys/stream.h> 39 #include <sys/strlog.h> 40 #include <sys/strsubr.h> 41 #include <sys/cmn_err.h> 42 #include <sys/vtrace.h> 43 #include <sys/kmem.h> 44 #include <sys/ddi.h> 45 #include <sys/sunddi.h> 46 #include <sys/strsun.h> 47 #include <sys/stat.h> 48 #include <sys/cpu.h> 49 #include <sys/kstat.h> 50 #include <inet/common.h> 51 #include <inet/ip.h> 52 #include <inet/ip6.h> 53 #include <sys/dlpi.h> 54 #include <inet/nd.h> 55 #include <netinet/in.h> 56 #include <sys/ethernet.h> 57 #include <sys/vlan.h> 58 #include <sys/pci.h> 59 #include <sys/taskq.h> 60 #include <sys/atomic.h> 61 62 #include <hxge_defs.h> 63 #include <hxge_peu.h> 64 #include <hxge_pfc.h> 65 #include <hxge_pfc_hw.h> 66 #include <hxge_vmac.h> 67 #include <hxge_fm.h> 68 #include <sys/netlb.h> 69 #include <sys/ddi_intr.h> 70 71 #include <sys/mac_provider.h> 72 #include <sys/mac_ether.h> 73 74 /* 75 * Handy macros (taken from bge driver) 76 */ 77 #define RBR_SIZE 4 78 #define DMA_COMMON_VPTR(area) ((area.kaddrp)) 79 #define DMA_COMMON_HANDLE(area) ((area.dma_handle)) 80 #define DMA_COMMON_ACC_HANDLE(area) ((area.acc_handle)) 81 #define DMA_COMMON_IOADDR(area) ((area.dma_cookie.dmac_laddress)) 82 #define DMA_COMMON_SYNC(area, flag) ((void) ddi_dma_sync((area).dma_handle,\ 83 (area).offset, (area).alength, \ 84 (flag))) 85 #define DMA_COMMON_SYNC_OFFSET(area, bufoffset, len, flag) \ 86 ((void) ddi_dma_sync((area).dma_handle,\ 87 (area.offset + bufoffset), len, \ 88 (flag))) 89 90 #define NEXT_ENTRY(index, wrap) ((index + 1) & wrap) 91 #define NEXT_ENTRY_PTR(ptr, first, last) \ 92 ((ptr == last) ? first : (ptr + 1)) 93 94 /* 95 * HPI related macros 96 */ 97 #define HXGE_DEV_HPI_HANDLE(hxgep) (hxgep->hpi_handle) 98 99 #define HPI_PCI_ACC_HANDLE_SET(hxgep, ah) (hxgep->hpi_pci_handle.regh = ah) 100 #define HPI_PCI_ADD_HANDLE_SET(hxgep, ap) (hxgep->hpi_pci_handle.regp = ap) 101 102 #define HPI_ACC_HANDLE_SET(hxgep, ah) (hxgep->hpi_handle.regh = ah) 103 #define HPI_ADD_HANDLE_SET(hxgep, ap) \ 104 hxgep->hpi_handle.is_vraddr = B_FALSE; \ 105 hxgep->hpi_handle.function.instance = hxgep->instance; \ 106 hxgep->hpi_handle.function.function = 0; \ 107 hxgep->hpi_handle.hxgep = (void *) hxgep; \ 108 hxgep->hpi_handle.regp = ap; 109 110 #define HPI_REG_ACC_HANDLE_SET(hxgep, ah) (hxgep->hpi_reg_handle.regh = ah) 111 #define HPI_REG_ADD_HANDLE_SET(hxgep, ap) \ 112 hxgep->hpi_reg_handle.is_vraddr = B_FALSE; \ 113 hxgep->hpi_handle.function.instance = hxgep->instance; \ 114 hxgep->hpi_handle.function.function = 0; \ 115 hxgep->hpi_reg_handle.hxgep = (void *) hxgep; \ 116 hxgep->hpi_reg_handle.regp = ap; 117 118 #define HPI_MSI_ACC_HANDLE_SET(hxgep, ah) (hxgep->hpi_msi_handle.regh = ah) 119 #define HPI_MSI_ADD_HANDLE_SET(hxgep, ap) (hxgep->hpi_msi_handle.regp = ap) 120 121 #define HPI_DMA_ACC_HANDLE_SET(dmap, ah) (dmap->hpi_handle.regh = ah) 122 #define HPI_DMA_ACC_HANDLE_GET(dmap) (dmap->hpi_handle.regh) 123 124 #define LDV_ON(ldv, vector) ((vector >> ldv) & 0x1) 125 126 typedef uint32_t hxge_status_t; 127 128 typedef enum { 129 DVMA, 130 DMA, 131 SDMA 132 } dma_method_t; 133 134 typedef enum { 135 BKSIZE_4K, 136 BKSIZE_8K, 137 BKSIZE_16K, 138 BKSIZE_32K 139 } hxge_rx_block_size_t; 140 141 #ifdef TX_ONE_BUF 142 #define TX_BCOPY_MAX 512 143 #else 144 #define TX_BCOPY_MAX 512 145 #define TX_BCOPY_SIZE 512 146 #endif 147 148 #define TX_STREAM_MIN 512 149 #define TX_FASTDVMA_MIN 1024 150 151 #define HXGE_RDC_RCR_THRESHOLD_MAX 256 152 #define HXGE_RDC_RCR_TIMEOUT_MAX 64 153 #define HXGE_RDC_RCR_THRESHOLD_MIN 1 154 #define HXGE_RDC_RCR_TIMEOUT_MIN 1 155 156 #define HXGE_IS_VLAN_PACKET(ptr) \ 157 ((((struct ether_vlan_header *)ptr)->ether_tpid) == \ 158 htons(VLAN_ETHERTYPE)) 159 160 typedef enum { 161 USE_NONE, 162 USE_BCOPY, 163 USE_DVMA, 164 USE_DMA, 165 USE_SDMA 166 } dma_type_t; 167 168 struct _hxge_block_mv_t { 169 uint32_t msg_type; 170 dma_type_t dma_type; 171 }; 172 173 typedef struct _hxge_block_mv_t hxge_block_mv_t, *p_hxge_block_mv_t; 174 175 typedef struct ether_addr ether_addr_st, *p_ether_addr_t; 176 typedef struct ether_header ether_header_t, *p_ether_header_t; 177 typedef queue_t *p_queue_t; 178 typedef mblk_t *p_mblk_t; 179 180 /* 181 * Common DMA data elements. 182 */ 183 struct _hxge_dma_common_t { 184 uint16_t dma_channel; 185 void *kaddrp; 186 void *ioaddr_pp; 187 ddi_dma_cookie_t dma_cookie; 188 uint32_t ncookies; 189 190 ddi_dma_handle_t dma_handle; 191 hxge_os_acc_handle_t acc_handle; 192 hpi_handle_t hpi_handle; 193 194 size_t block_size; 195 uint32_t nblocks; 196 size_t alength; 197 uint_t offset; 198 uint_t dma_chunk_index; 199 void *orig_ioaddr_pp; 200 uint64_t orig_vatopa; 201 void *orig_kaddrp; 202 size_t orig_alength; 203 boolean_t contig_alloc_type; 204 }; 205 206 typedef struct _hxge_t hxge_t, *p_hxge_t; 207 typedef struct _hxge_dma_common_t hxge_dma_common_t, *p_hxge_dma_common_t; 208 209 typedef struct _hxge_dma_pool_t { 210 p_hxge_dma_common_t *dma_buf_pool_p; 211 uint32_t ndmas; 212 uint32_t *num_chunks; 213 boolean_t buf_allocated; 214 } hxge_dma_pool_t, *p_hxge_dma_pool_t; 215 216 /* 217 * Each logical device (69): 218 * - LDG # 219 * - flag bits 220 * - masks. 221 * - interrupt handler function. 222 * 223 * Generic system interrupt handler with two arguments: 224 * (hxge_sys_intr_t) 225 * Per device instance data structure 226 * Logical group data structure. 227 * 228 * Logical device interrupt handler with two arguments: 229 * (hxge_ldv_intr_t) 230 * Per device instance data structure 231 * Logical device number 232 */ 233 typedef struct _hxge_ldg_t hxge_ldg_t, *p_hxge_ldg_t; 234 typedef struct _hxge_ldv_t hxge_ldv_t, *p_hxge_ldv_t; 235 typedef uint_t (*hxge_sys_intr_t)(caddr_t arg1, caddr_t arg2); 236 typedef uint_t (*hxge_ldv_intr_t)(caddr_t arg1, caddr_t arg2); 237 238 /* 239 * Each logical device Group (64) needs to have the following 240 * configurations: 241 * - timer counter (6 bits) 242 * - timer resolution (20 bits, number of system clocks) 243 * - system data (7 bits) 244 */ 245 struct _hxge_ldg_t { 246 uint8_t ldg; /* logical group number */ 247 uint8_t vldg_index; 248 boolean_t arm; 249 boolean_t interrupted; 250 uint16_t ldg_timer; /* counter */ 251 uint8_t vector; 252 uint8_t nldvs; 253 p_hxge_ldv_t ldvp; 254 hxge_sys_intr_t sys_intr_handler; 255 p_hxge_t hxgep; 256 }; 257 258 struct _hxge_ldv_t { 259 uint8_t ldg_assigned; 260 uint8_t ldv; 261 boolean_t is_rxdma; 262 boolean_t is_txdma; 263 boolean_t is_vmac; 264 boolean_t is_syserr; 265 boolean_t is_pfc; 266 boolean_t use_timer; 267 uint8_t channel; 268 uint8_t vdma_index; 269 p_hxge_ldg_t ldgp; 270 uint8_t ldv_ldf_masks; 271 hxge_ldv_intr_t ldv_intr_handler; 272 p_hxge_t hxgep; 273 }; 274 275 typedef struct _pci_cfg_t { 276 uint16_t vendorid; 277 uint16_t devid; 278 uint16_t command; 279 uint16_t status; 280 uint8_t revid; 281 uint8_t res0; 282 uint16_t junk1; 283 uint8_t cache_line; 284 uint8_t latency; 285 uint8_t header; 286 uint8_t bist; 287 uint32_t base; 288 uint32_t base14; 289 uint32_t base18; 290 uint32_t base1c; 291 uint32_t base20; 292 uint32_t base24; 293 uint32_t base28; 294 uint32_t base2c; 295 uint32_t base30; 296 uint32_t res1[2]; 297 uint8_t int_line; 298 uint8_t int_pin; 299 uint8_t min_gnt; 300 uint8_t max_lat; 301 } pci_cfg_t, *p_pci_cfg_t; 302 303 typedef struct _dev_regs_t { 304 hxge_os_acc_handle_t hxge_pciregh; /* PCI config DDI IO handle */ 305 p_pci_cfg_t hxge_pciregp; /* mapped PCI registers */ 306 307 hxge_os_acc_handle_t hxge_regh; /* device DDI IO (BAR 0) */ 308 void *hxge_regp; /* mapped device registers */ 309 310 hxge_os_acc_handle_t hxge_msix_regh; /* MSI/X DDI handle (BAR 2) */ 311 void *hxge_msix_regp; /* MSI/X register */ 312 313 hxge_os_acc_handle_t hxge_romh; /* fcode rom handle */ 314 unsigned char *hxge_romp; /* fcode pointer */ 315 } dev_regs_t, *p_dev_regs_t; 316 317 #include <hxge_common_impl.h> 318 #include <hxge_common.h> 319 #include <hxge_rxdma.h> 320 #include <hxge_txdma.h> 321 #include <hxge_fzc.h> 322 #include <hxge_flow.h> 323 #include <hxge_virtual.h> 324 #include <hxge.h> 325 #include <sys/modctl.h> 326 #include <sys/pattr.h> 327 #include <hpi_vir.h> 328 329 /* 330 * Reconfiguring the network devices requires the net_config privilege 331 * in Solaris 10+. Prior to this, root privilege is required. In order 332 * that the driver binary can run on both S10+ and earlier versions, we 333 * make the decisiion as to which to use at runtime. These declarations 334 * allow for either (or both) to exist ... 335 */ 336 extern int secpolicy_net_config(const cred_t *, boolean_t); 337 extern void hxge_fm_report_error(p_hxge_t hxgep, 338 uint8_t err_chan, hxge_fm_ereport_id_t fm_ereport_id); 339 extern int fm_check_acc_handle(ddi_acc_handle_t); 340 extern int fm_check_dma_handle(ddi_dma_handle_t); 341 342 #pragma weak secpolicy_net_config 343 344 hxge_status_t hxge_classify_init(p_hxge_t hxgep); 345 hxge_status_t hxge_classify_uninit(p_hxge_t hxgep); 346 void hxge_put_tcam(p_hxge_t hxgep, p_mblk_t mp); 347 void hxge_get_tcam(p_hxge_t hxgep, p_mblk_t mp); 348 349 hxge_status_t hxge_classify_init_hw(p_hxge_t hxgep); 350 hxge_status_t hxge_classify_init_sw(p_hxge_t hxgep); 351 hxge_status_t hxge_classify_exit_sw(p_hxge_t hxgep); 352 hxge_status_t hxge_pfc_ip_class_config_all(p_hxge_t hxgep); 353 hxge_status_t hxge_pfc_ip_class_config(p_hxge_t hxgep, tcam_class_t l3_class, 354 uint32_t class_config); 355 hxge_status_t hxge_pfc_ip_class_config_get(p_hxge_t hxgep, 356 tcam_class_t l3_class, uint32_t *class_config); 357 358 hxge_status_t hxge_pfc_set_hash(p_hxge_t, uint32_t); 359 hxge_status_t hxge_pfc_config_tcam_enable(p_hxge_t); 360 hxge_status_t hxge_pfc_config_tcam_disable(p_hxge_t); 361 hxge_status_t hxge_pfc_ip_class_config(p_hxge_t, tcam_class_t, uint32_t); 362 hxge_status_t hxge_pfc_ip_class_config_get(p_hxge_t, tcam_class_t, uint32_t *); 363 hxge_status_t hxge_pfc_mac_addrs_get(p_hxge_t hxgep); 364 365 366 hxge_status_t hxge_pfc_hw_reset(p_hxge_t hxgep); 367 hxge_status_t hxge_pfc_handle_sys_errors(p_hxge_t hxgep); 368 369 /* hxge_kstats.c */ 370 void hxge_init_statsp(p_hxge_t); 371 void hxge_setup_kstats(p_hxge_t); 372 void hxge_destroy_kstats(p_hxge_t); 373 int hxge_port_kstat_update(kstat_t *, int); 374 375 int hxge_m_stat(void *arg, uint_t stat, uint64_t *val); 376 377 /* hxge_hw.c */ 378 void 379 hxge_hw_ioctl(p_hxge_t, queue_t *, mblk_t *, struct iocblk *); 380 void hxge_loopback_ioctl(p_hxge_t, queue_t *, mblk_t *, struct iocblk *); 381 void hxge_global_reset(p_hxge_t); 382 uint_t hxge_intr(caddr_t arg1, caddr_t arg2); 383 void hxge_intr_enable(p_hxge_t hxgep); 384 void hxge_intr_disable(p_hxge_t hxgep); 385 void hxge_hw_id_init(p_hxge_t hxgep); 386 void hxge_hw_init_niu_common(p_hxge_t hxgep); 387 void hxge_intr_hw_enable(p_hxge_t hxgep); 388 void hxge_intr_hw_disable(p_hxge_t hxgep); 389 void hxge_hw_stop(p_hxge_t hxgep); 390 void hxge_global_reset(p_hxge_t hxgep); 391 void hxge_check_hw_state(p_hxge_t hxgep); 392 393 /* hxge_send.c. */ 394 uint_t hxge_reschedule(caddr_t arg); 395 396 /* hxge_ndd.c */ 397 void hxge_get_param_soft_properties(p_hxge_t); 398 void hxge_setup_param(p_hxge_t); 399 void hxge_init_param(p_hxge_t); 400 void hxge_destroy_param(p_hxge_t); 401 boolean_t hxge_check_rxdma_port_member(p_hxge_t, uint8_t); 402 boolean_t hxge_check_txdma_port_member(p_hxge_t, uint8_t); 403 int hxge_param_get_generic(p_hxge_t, queue_t *, mblk_t *, caddr_t); 404 int hxge_param_set_generic(p_hxge_t, queue_t *, mblk_t *, char *, caddr_t); 405 int hxge_get_default(p_hxge_t, queue_t *, p_mblk_t, caddr_t); 406 int hxge_set_default(p_hxge_t, queue_t *, p_mblk_t, char *, caddr_t); 407 int hxge_nd_get_names(p_hxge_t, queue_t *, p_mblk_t, caddr_t); 408 int hxge_mk_mblk_tail_space(p_mblk_t mp, p_mblk_t *nmp, size_t size); 409 void hxge_param_ioctl(p_hxge_t hxgep, queue_t *, mblk_t *, struct iocblk *); 410 boolean_t hxge_nd_load(caddr_t *, char *, pfi_t, pfi_t, caddr_t); 411 void hxge_nd_free(caddr_t *); 412 int hxge_nd_getset(p_hxge_t, queue_t *, caddr_t, p_mblk_t); 413 boolean_t hxge_set_lb(p_hxge_t, queue_t *wq, p_mblk_t mp); 414 int hxge_param_rx_intr_pkts(p_hxge_t hxgep, queue_t *, mblk_t *, char *, 415 caddr_t); 416 int hxge_param_rx_intr_time(p_hxge_t hxgep, queue_t *, mblk_t *, char *, 417 caddr_t); 418 int hxge_param_set_ip_opt(p_hxge_t hxgep, queue_t *, mblk_t *, char *, caddr_t); 419 int hxge_param_get_ip_opt(p_hxge_t hxgep, queue_t *, mblk_t *, caddr_t); 420 421 /* hxge_virtual.c */ 422 hxge_status_t hxge_get_config_properties(p_hxge_t); 423 hxge_status_t hxge_init_fzc_txdma_channel(p_hxge_t hxgep, uint16_t channel, 424 p_tx_ring_t tx_ring_p, p_tx_mbox_t mbox_p); 425 hxge_status_t hxge_init_fzc_rxdma_channel(p_hxge_t hxgep, uint16_t channel, 426 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p); 427 hxge_status_t hxge_init_fzc_rx_common(p_hxge_t hxgep); 428 hxge_status_t hxge_init_fzc_rxdma_channel_pages(p_hxge_t hxgep, 429 uint16_t channel, p_rx_rbr_ring_t rbr_p); 430 hxge_status_t hxge_init_fzc_txdma_channel_pages(p_hxge_t hxgep, 431 uint16_t channel, p_tx_ring_t tx_ring_p); 432 hxge_status_t hxge_intr_mask_mgmt_set(p_hxge_t hxgep, boolean_t on); 433 434 /* MAC functions */ 435 hxge_status_t hxge_vmac_init(p_hxge_t hxgep); 436 hxge_status_t hxge_link_init(p_hxge_t hxgep); 437 hxge_status_t hxge_tx_vmac_init(p_hxge_t hxgep); 438 hxge_status_t hxge_rx_vmac_init(p_hxge_t hxgep); 439 hxge_status_t hxge_tx_vmac_enable(p_hxge_t hxgep); 440 hxge_status_t hxge_tx_vmac_disable(p_hxge_t hxgep); 441 hxge_status_t hxge_rx_vmac_enable(p_hxge_t hxgep); 442 hxge_status_t hxge_rx_vmac_disable(p_hxge_t hxgep); 443 hxge_status_t hxge_tx_vmac_reset(p_hxge_t hxgep); 444 hxge_status_t hxge_rx_vmac_reset(p_hxge_t hxgep); 445 hxge_status_t hxge_add_mcast_addr(p_hxge_t, struct ether_addr *); 446 hxge_status_t hxge_del_mcast_addr(p_hxge_t, struct ether_addr *); 447 hxge_status_t hxge_pfc_set_mac_address(p_hxge_t hxgep, uint32_t slot, 448 struct ether_addr *addrp); 449 hxge_status_t hxge_pfc_num_macs_get(p_hxge_t hxgep, uint8_t *nmacs); 450 hxge_status_t hxge_pfc_clear_mac_address(p_hxge_t, uint32_t slot); 451 hxge_status_t hxge_set_promisc(p_hxge_t hxgep, boolean_t on); 452 void hxge_save_cntrs(p_hxge_t hxgep); 453 int hxge_vmac_set_framesize(p_hxge_t hxgep); 454 455 void hxge_debug_msg(p_hxge_t, uint64_t, char *, ...); 456 457 #ifdef HXGE_DEBUG 458 char *hxge_dump_packet(char *addr, int size); 459 #endif 460 461 #endif /* !_ASM */ 462 463 #ifdef __cplusplus 464 } 465 #endif 466 467 #endif /* _SYS_HXGE_HXGE_IMPL_H */ 468