2 * Copyright(c) 2002-2011 Exar Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification are permitted provided the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Exar Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include <dev/vxge/vxgehal/vxgehal.h>
37 #include <dev/vxge/vxge-osdep.h>
38 #include "vxge-firmware.h"
40 #define VXGE_GET_PARAM(str_kenv, to, param, hardcode) { \
41 static int __CONCAT(param, __LINE__); \
42 if (testenv(str_kenv) == 1) \
43 TUNABLE_INT_FETCH(str_kenv, \
44 &__CONCAT(param, __LINE__)); \
46 __CONCAT(param, __LINE__) = hardcode; \
48 to.param = __CONCAT(param, __LINE__); \
51 #define VXGE_BUFFER_ALIGN(buffer_length, to) { \
52 if (buffer_length % to) \
54 (to - (buffer_length % to)); \
57 #define VXGE_HAL_VPATH_MSIX_ACTIVE 4
58 #define VXGE_HAL_VPATH_MSIX_ALARM_ID 2
59 #define VXGE_MSIX_ALARM_ID(hldev, i) \
60 ((__hal_device_t *) hldev)->first_vp_id * \
61 VXGE_HAL_VPATH_MSIX_ACTIVE + i;
63 #define VXGE_DUAL_PORT_MODE 2
64 #define VXGE_DUAL_PORT_MAP 0xAAAAULL
65 #define VXGE_BAUDRATE 1000000000
66 #define VXGE_MAX_SEGS VXGE_HAL_MAX_FIFO_FRAGS
67 #define VXGE_TSO_SIZE 65600
68 #define VXGE_STATS_BUFFER_SIZE 65536
69 #define VXGE_PRINT_BUF_SIZE 128
70 #define VXGE_PMD_INFO_LEN 24
71 #define VXGE_RXD_REPLENISH_COUNT 4
72 #define VXGE_TX_LOW_THRESHOLD 32
74 /* Default configuration parameters */
75 #define VXGE_DEFAULT_USER_HARDCODED -1
76 #define VXGE_DEFAULT_CONFIG_VALUE 0xFF
77 #define VXGE_DEFAULT_CONFIG_ENABLE 1
78 #define VXGE_DEFAULT_CONFIG_DISABLE 0
80 #if __FreeBSD_version >= 800000
81 #define VXGE_DEFAULT_CONFIG_MQ_ENABLE 1
83 #define VXGE_DEFAULT_CONFIG_MQ_ENABLE 0
86 #define VXGE_DEFAULT_CONFIG_IFQ_MAXLEN 1024
88 #define VXGE_DEFAULT_BR_SIZE 4096
89 #define VXGE_DEFAULT_RTH_BUCKET_SIZE 8
90 #define VXGE_DEFAULT_RING_BLOCK 2
91 #define VXGE_DEFAULT_SUPPORTED_DEVICES 1
92 #define VXGE_DEFAULT_DEVICE_POLL_MILLIS 2000
93 #define VXGE_DEFAULT_FIFO_ALIGNED_FRAGS 1
94 #define VXGE_DEFAULT_VPATH_PRIORITY_LOW 3
95 #define VXGE_DEFAULT_VPATH_PRIORITY_HIGH 0
96 #define VXGE_DEFAULT_ALL_VID_ENABLE \
97 VXGE_HAL_VPATH_RPA_ALL_VID_ENABLE
99 #define VXGE_DEFAULT_STRIP_VLAN_TAG \
100 VXGE_HAL_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
102 #define VXGE_DEFAULT_TTI_BTIMER_VAL 250000
103 #define VXGE_DEFAULT_TTI_LTIMER_VAL 80
104 #define VXGE_DEFAULT_TTI_RTIMER_VAL 0
106 #define VXGE_DEFAULT_RTI_BTIMER_VAL 250
107 #define VXGE_DEFAULT_RTI_LTIMER_VAL 100
108 #define VXGE_DEFAULT_RTI_RTIMER_VAL 0
110 #define VXGE_TTI_RTIMER_ADAPT_VAL 10
111 #define VXGE_RTI_RTIMER_ADAPT_VAL 15
113 #define VXGE_DEFAULT_TTI_TX_URANGE_A 5
114 #define VXGE_DEFAULT_TTI_TX_URANGE_B 15
115 #define VXGE_DEFAULT_TTI_TX_URANGE_C 40
117 #define VXGE_DEFAULT_RTI_RX_URANGE_A 5
118 #define VXGE_DEFAULT_RTI_RX_URANGE_B 15
119 #define VXGE_DEFAULT_RTI_RX_URANGE_C 40
121 #define VXGE_DEFAULT_TTI_TX_UFC_A 1
122 #define VXGE_DEFAULT_TTI_TX_UFC_B 5
123 #define VXGE_DEFAULT_TTI_TX_UFC_C 15
124 #define VXGE_DEFAULT_TTI_TX_UFC_D 40
126 #define VXGE_DEFAULT_RTI_RX_UFC_A 1
127 #define VXGE_DEFAULT_RTI_RX_UFC_B 20
128 #define VXGE_DEFAULT_RTI_RX_UFC_C 40
129 #define VXGE_DEFAULT_RTI_RX_UFC_D 100
131 #define VXGE_MAX_RX_INTERRUPT_COUNT 100
132 #define VXGE_MAX_TX_INTERRUPT_COUNT 200
134 #define is_multi_func(func_mode) \
135 ((func_mode == VXGE_HAL_PCIE_FUNC_MODE_MF8_VP2) || \
136 (func_mode == VXGE_HAL_PCIE_FUNC_MODE_MF2_VP8) || \
137 (func_mode == VXGE_HAL_PCIE_FUNC_MODE_MF4_VP4) || \
138 (func_mode == VXGE_HAL_PCIE_FUNC_MODE_MF8P_VP2))
140 #define is_single_func(func_mode) \
141 (func_mode == VXGE_HAL_PCIE_FUNC_MODE_SF1_VP17)
143 #define VXGE_DRV_STATS(v, x) v->driver_stats.x++
144 #define VXGE_MAX_MSIX_MESSAGES (VXGE_HAL_MAX_VIRTUAL_PATHS * 2 + 2)
146 #define VXGE_DRV_LOCK(x) mtx_lock(&(x)->mtx_drv)
147 #define VXGE_DRV_UNLOCK(x) mtx_unlock(&(x)->mtx_drv)
148 #define VXGE_DRV_LOCK_DESTROY(x) mtx_destroy(&(x)->mtx_drv)
149 #define VXGE_DRV_LOCK_ASSERT(x) mtx_assert(&(x)->mtx_drv, MA_OWNED)
151 #define VXGE_TX_LOCK(x) mtx_lock(&(x)->mtx_tx)
152 #define VXGE_TX_TRYLOCK(x) mtx_trylock(&(x)->mtx_tx)
153 #define VXGE_TX_UNLOCK(x) mtx_unlock(&(x)->mtx_tx)
154 #define VXGE_TX_LOCK_DESTROY(x) mtx_destroy(&(x)->mtx_tx)
155 #define VXGE_TX_LOCK_ASSERT(x) mtx_assert(&(x)->mtx_tx, MA_OWNED)
169 vxge_port_failure[3] =
173 "Failover & Failback"
176 /* IOCTLs to identify vxge-manage requests */
177 typedef enum _vxge_query_device_info_e {
179 VXGE_GET_PCI_CONF = 100,
180 VXGE_GET_MRPCIM_STATS = 101,
181 VXGE_GET_DEVICE_STATS = 102,
182 VXGE_GET_DEVICE_HWINFO = 103,
183 VXGE_GET_DRIVER_STATS = 104,
184 VXGE_GET_INTR_STATS = 105,
185 VXGE_GET_VERSION = 106,
186 VXGE_GET_TCODE = 107,
187 VXGE_GET_VPATH_COUNT = 108,
188 VXGE_GET_BANDWIDTH = 109,
189 VXGE_SET_BANDWIDTH = 110,
190 VXGE_GET_PORT_MODE = 111,
191 VXGE_SET_PORT_MODE = 112
193 } vxge_query_device_info_e;
195 typedef enum _vxge_firmware_upgrade_e {
197 VXGE_FW_UPGRADE_NONE = 0,
198 VXGE_FW_UPGRADE_ALL = 1,
199 VXGE_FW_UPGRADE_FORCE = 2
201 } vxge_firmware_upgrade_e;
203 typedef enum _vxge_free_resources_e {
207 VXGE_FREE_PCI_INFO = 2,
211 VXGE_FREE_ISR_RESOURCE = 6,
213 VXGE_FREE_INTERFACE = 8,
214 VXGE_FREE_DEVICE_CONFIG = 9,
215 VXGE_FREE_TERMINATE_DEVICE = 10,
216 VXGE_FREE_TERMINATE_DRIVER = 11,
217 VXGE_DISABLE_PCI_BUSMASTER = 12,
218 VXGE_FREE_VPATH = 13,
221 } vxge_free_resources_e;
223 typedef enum _vxge_device_attributes_e {
225 VXGE_PRINT_DRV_VERSION = 0,
226 VXGE_PRINT_PCIE_INFO = 1,
227 VXGE_PRINT_SERIAL_NO = 2,
228 VXGE_PRINT_PART_NO = 3,
229 VXGE_PRINT_FW_VERSION = 4,
230 VXGE_PRINT_FW_DATE = 5,
231 VXGE_PRINT_FUNC_MODE = 6,
232 VXGE_PRINT_INTR_MODE = 7,
233 VXGE_PRINT_VPATH_COUNT = 8,
234 VXGE_PRINT_MTU_SIZE = 9,
235 VXGE_PRINT_LRO_MODE = 10,
236 VXGE_PRINT_RTH_MODE = 11,
237 VXGE_PRINT_TSO_MODE = 12,
238 VXGE_PRINT_PMD_PORTS_0 = 13,
239 VXGE_PRINT_PMD_PORTS_1 = 14,
240 VXGE_PRINT_ADAPTER_TYPE = 15,
241 VXGE_PRINT_PORT_MODE = 16,
242 VXGE_PRINT_PORT_FAILURE = 17,
243 VXGE_PRINT_ACTIVE_PORT = 18,
244 VXGE_PRINT_L2SWITCH_MODE = 19
246 } vxge_device_attribute_e;
248 typedef struct _vxge_isr_info_t {
252 struct resource *irq_res;
256 typedef struct _vxge_drv_stats_t {
266 u64 tx_reserve_failed;
280 typedef struct vxge_dev_t vxge_dev_t;
282 /* Rx descriptor private structure */
283 typedef struct _vxge_rxd_priv_t {
286 bus_size_t dma_sizes[1];
287 bus_addr_t dma_addr[1];
288 bus_dmamap_t dma_map;
292 /* Tx descriptor private structure */
293 typedef struct _vxge_txdl_priv_t {
296 bus_dmamap_t dma_map;
297 bus_dma_segment_t dma_buffers[VXGE_MAX_SEGS];
301 typedef struct _vxge_vpath_t {
324 int tx_intr_coalesce;
325 int rx_intr_coalesce;
328 vxge_hal_vpath_h handle;
329 char mtx_tx_name[16];
331 bus_dma_tag_t dma_tag_tx;
332 bus_dma_tag_t dma_tag_rx;
333 bus_dmamap_t extra_dma_map;
335 vxge_drv_stats_t driver_stats;
339 #if __FreeBSD_version >= 800000
345 typedef struct _vxge_bw_info_t {
354 typedef struct _vxge_port_info_t {
362 typedef struct _vxge_device_hw_info_t {
364 vxge_hal_device_hw_info_t hw_info;
365 vxge_hal_xmac_nwif_dp_mode port_mode;
366 vxge_hal_xmac_nwif_behavior_on_failure port_failure;
368 } vxge_device_hw_info_t;
370 typedef struct _vxge_config_t {
386 char nic_attr[20][128];
388 vxge_hal_device_hw_info_t hw_info;
389 vxge_firmware_upgrade_e fw_option;
390 vxge_hal_xmac_nwif_behavior_on_failure port_failure;
392 vxge_bw_info_t bw_info[VXGE_HAL_MAX_FUNCTIONS];
393 vxge_isr_info_t isr_info[VXGE_MAX_MSIX_MESSAGES];
410 u32 max_supported_vpath;
416 vxge_hal_xmac_nwif_dp_mode port_mode;
417 vxge_hal_xmac_nwif_l2_switch_status l2_switch;
418 vxge_hal_xmac_nwif_behavior_on_failure port_failure;
421 char mtx_drv_name[16];
424 struct ifmedia media;
426 vxge_pci_info_t *pdev;
427 vxge_hal_device_t *devh;
428 vxge_vpath_t *vpaths;
429 vxge_config_t config;
430 vxge_hal_device_config_t *device_config;
431 vxge_hal_vpath_h vpath_handles[VXGE_HAL_MAX_VIRTUAL_PATHS];
434 int vxge_probe(device_t);
435 int vxge_attach(device_t);
436 int vxge_detach(device_t);
437 int vxge_shutdown(device_t);
439 int vxge_alloc_resources(vxge_dev_t *);
440 int vxge_alloc_isr_resources(vxge_dev_t *);
441 int vxge_alloc_bar_resources(vxge_dev_t *, int);
442 void vxge_free_resources(device_t, vxge_free_resources_e);
443 void vxge_free_isr_resources(vxge_dev_t *);
444 void vxge_free_bar_resources(vxge_dev_t *, int);
446 int vxge_device_hw_info_get(vxge_dev_t *);
447 int vxge_firmware_verify(vxge_dev_t *);
450 vxge_driver_init(vxge_dev_t *);
453 vxge_firmware_upgrade(vxge_dev_t *);
456 vxge_func_mode_set(vxge_dev_t *);
459 vxge_port_mode_set(vxge_dev_t *);
462 vxge_port_behavior_on_failure_set(vxge_dev_t *);
465 vxge_l2switch_mode_set(vxge_dev_t *);
467 void vxge_init(void *);
468 void vxge_init_locked(vxge_dev_t *);
470 void vxge_stop(vxge_dev_t *);
471 void vxge_stop_locked(vxge_dev_t *);
473 void vxge_reset(vxge_dev_t *);
474 int vxge_ifp_setup(device_t);
475 int vxge_isr_setup(vxge_dev_t *);
477 void vxge_media_init(vxge_dev_t *);
478 int vxge_media_change(ifnet_t);
479 void vxge_media_status(ifnet_t, struct ifmediareq *);
481 void vxge_mutex_init(vxge_dev_t *);
482 void vxge_mutex_destroy(vxge_dev_t *);
483 void vxge_link_up(vxge_hal_device_h, void *);
484 void vxge_link_down(vxge_hal_device_h, void *);
485 void vxge_crit_error(vxge_hal_device_h, void *, vxge_hal_event_e, u64);
487 int vxge_ioctl(ifnet_t, u_long, caddr_t);
488 int vxge_ioctl_regs(vxge_dev_t *, struct ifreq *);
489 int vxge_ioctl_stats(vxge_dev_t *, struct ifreq *);
490 void vxge_promisc_set(vxge_dev_t *);
492 void vxge_vpath_config(vxge_dev_t *);
493 int vxge_vpath_open(vxge_dev_t *);
494 void vxge_vpath_close(vxge_dev_t *);
495 void vxge_vpath_reset(vxge_dev_t *);
497 int vxge_change_mtu(vxge_dev_t *, unsigned long);
499 u32 vxge_ring_length_get(u32);
501 void vxge_isr_line(void *);
502 int vxge_isr_filter(void *);
503 void vxge_isr_msix(void *);
504 void vxge_isr_msix_alarm(void *);
507 vxge_intr_coalesce_tx(vxge_vpath_t *);
510 vxge_intr_coalesce_rx(vxge_vpath_t *);
513 vxge_msix_enable(vxge_dev_t *);
516 vxge_rth_config(vxge_dev_t *);
518 int vxge_dma_tags_create(vxge_vpath_t *);
519 void vxge_device_hw_info_print(vxge_dev_t *);
520 int vxge_driver_config(vxge_dev_t *);
522 #if __FreeBSD_version >= 800000
525 vxge_mq_send(ifnet_t, mbuf_t);
528 vxge_mq_send_locked(ifnet_t, vxge_vpath_t *, mbuf_t);
531 vxge_mq_qflush(ifnet_t);
539 vxge_send_locked(ifnet_t, vxge_vpath_t *);
542 vxge_xmit(ifnet_t, vxge_vpath_t *, mbuf_t *);
545 vxge_dma_mbuf_coalesce(bus_dma_tag_t, bus_dmamap_t,
546 mbuf_t *, bus_dma_segment_t *, int *);
549 vxge_rx_checksum(vxge_hal_ring_rxd_info_t, mbuf_t);
552 vxge_rx_input(ifnet_t, mbuf_t, vxge_vpath_t *);
554 static inline vxge_hal_vpath_h
555 vxge_vpath_handle_get(vxge_dev_t *, int);
558 vxge_vpath_get(vxge_dev_t *, mbuf_t);
561 vxge_tso_config(vxge_dev_t *);
564 vxge_tx_replenish(vxge_hal_vpath_h, vxge_hal_txdl_h, void *,
565 u32, void *, vxge_hal_reopen_e);
568 vxge_tx_compl(vxge_hal_vpath_h, vxge_hal_txdl_h, void *,
569 vxge_hal_fifo_tcode_e, void *);
572 vxge_tx_term(vxge_hal_vpath_h, vxge_hal_txdl_h, void *,
573 vxge_hal_txdl_state_e, void *, vxge_hal_reopen_e);
576 vxge_rx_replenish(vxge_hal_vpath_h, vxge_hal_rxd_h, void *,
577 u32, void *, vxge_hal_reopen_e);
580 vxge_rx_compl(vxge_hal_vpath_h, vxge_hal_rxd_h, void *, u8, void *);
583 vxge_rx_term(vxge_hal_vpath_h, vxge_hal_rxd_h, void *,
584 vxge_hal_rxd_state_e, void *, vxge_hal_reopen_e);
587 vxge_rx_rxd_1b_get(vxge_vpath_t *, vxge_hal_rxd_h, void *);
590 vxge_rx_rxd_1b_set(vxge_vpath_t *, vxge_hal_rxd_h, void *);
593 vxge_bw_priority_config(vxge_dev_t *);
596 vxge_bw_priority_get(vxge_dev_t *, vxge_bw_info_t *);
599 vxge_bw_priority_set(vxge_dev_t *, struct ifreq *);
602 vxge_bw_priority_update(vxge_dev_t *, u32, bool);
605 vxge_port_mode_update(vxge_dev_t *);
608 vxge_port_mode_get(vxge_dev_t *, vxge_port_info_t *);
611 vxge_pmd_port_type_get(vxge_dev_t *, u32, char *, u8);
614 vxge_active_port_update(vxge_dev_t *);
617 vxge_null_terminate(char *, size_t);
619 #endif /* _VXGE_H_ */