1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-config.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
13 ******************************************************************************/
14 #include <linux/vmalloc.h>
15 #include <linux/etherdevice.h>
16 #include <linux/pci.h>
17 #include <linux/pci_hotplug.h>
18 #include <linux/slab.h>
20 #include "vxge-traffic.h"
21 #include "vxge-config.h"
22 #include "vxge-main.h"
24 #define VXGE_HW_VPATH_STATS_PIO_READ(offset) { \
25 status = __vxge_hw_vpath_stats_access(vpath, \
26 VXGE_HW_STATS_OP_READ, \
29 if (status != VXGE_HW_OK) \
34 vxge_hw_vpath_set_zero_rx_frm_len(struct vxge_hw_vpath_reg __iomem
*vp_reg
)
38 val64
= readq(&vp_reg
->rxmac_vcfg0
);
39 val64
&= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
40 writeq(val64
, &vp_reg
->rxmac_vcfg0
);
41 val64
= readq(&vp_reg
->rxmac_vcfg0
);
45 * vxge_hw_vpath_wait_receive_idle - Wait for Rx to become idle
47 int vxge_hw_vpath_wait_receive_idle(struct __vxge_hw_device
*hldev
, u32 vp_id
)
49 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
50 struct __vxge_hw_virtualpath
*vpath
;
51 u64 val64
, rxd_count
, rxd_spat
;
52 int count
= 0, total_count
= 0;
54 vpath
= &hldev
->virtual_paths
[vp_id
];
55 vp_reg
= vpath
->vp_reg
;
57 vxge_hw_vpath_set_zero_rx_frm_len(vp_reg
);
59 /* Check that the ring controller for this vpath has enough free RxDs
60 * to send frames to the host. This is done by reading the
61 * PRC_RXD_DOORBELL_VPn register and comparing the read value to the
62 * RXD_SPAT value for the vpath.
64 val64
= readq(&vp_reg
->prc_cfg6
);
65 rxd_spat
= VXGE_HW_PRC_CFG6_GET_RXD_SPAT(val64
) + 1;
66 /* Use a factor of 2 when comparing rxd_count against rxd_spat for some
74 rxd_count
= readq(&vp_reg
->prc_rxd_doorbell
);
76 /* Check that the ring controller for this vpath does
77 * not have any frame in its pipeline.
79 val64
= readq(&vp_reg
->frm_in_progress_cnt
);
80 if ((rxd_count
<= rxd_spat
) || (val64
> 0))
85 } while ((count
< VXGE_HW_MIN_SUCCESSIVE_IDLE_COUNT
) &&
86 (total_count
< VXGE_HW_MAX_POLLING_COUNT
));
88 if (total_count
>= VXGE_HW_MAX_POLLING_COUNT
)
89 printk(KERN_ALERT
"%s: Still Receiving traffic. Abort wait\n",
95 /* vxge_hw_device_wait_receive_idle - This function waits until all frames
96 * stored in the frame buffer for each vpath assigned to the given
97 * function (hldev) have been sent to the host.
99 void vxge_hw_device_wait_receive_idle(struct __vxge_hw_device
*hldev
)
101 int i
, total_count
= 0;
103 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
104 if (!(hldev
->vpaths_deployed
& vxge_mBIT(i
)))
107 total_count
+= vxge_hw_vpath_wait_receive_idle(hldev
, i
);
108 if (total_count
>= VXGE_HW_MAX_POLLING_COUNT
)
114 * __vxge_hw_device_register_poll
115 * Will poll certain register for specified amount of time.
116 * Will poll until masked bit is not cleared.
118 static enum vxge_hw_status
119 __vxge_hw_device_register_poll(void __iomem
*reg
, u64 mask
, u32 max_millis
)
139 } while (++i
<= max_millis
);
144 static inline enum vxge_hw_status
145 __vxge_hw_pio_mem_write64(u64 val64
, void __iomem
*addr
,
146 u64 mask
, u32 max_millis
)
148 __vxge_hw_pio_mem_write32_lower((u32
)vxge_bVALn(val64
, 32, 32), addr
);
150 __vxge_hw_pio_mem_write32_upper((u32
)vxge_bVALn(val64
, 0, 32), addr
);
153 return __vxge_hw_device_register_poll(addr
, mask
, max_millis
);
156 static enum vxge_hw_status
157 vxge_hw_vpath_fw_api(struct __vxge_hw_virtualpath
*vpath
, u32 action
,
158 u32 fw_memo
, u32 offset
, u64
*data0
, u64
*data1
,
161 struct vxge_hw_vpath_reg __iomem
*vp_reg
= vpath
->vp_reg
;
162 enum vxge_hw_status status
;
164 u32 retry
= 0, max_retry
= 3;
166 spin_lock(&vpath
->lock
);
167 if (!vpath
->vp_open
) {
168 spin_unlock(&vpath
->lock
);
172 writeq(*data0
, &vp_reg
->rts_access_steer_data0
);
173 writeq(*data1
, &vp_reg
->rts_access_steer_data1
);
176 val64
= VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION(action
) |
177 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL(fw_memo
) |
178 VXGE_HW_RTS_ACCESS_STEER_CTRL_OFFSET(offset
) |
179 VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE
|
182 status
= __vxge_hw_pio_mem_write64(val64
,
183 &vp_reg
->rts_access_steer_ctrl
,
184 VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE
,
185 VXGE_HW_DEF_DEVICE_POLL_MILLIS
);
187 /* The __vxge_hw_device_register_poll can udelay for a significant
188 * amount of time, blocking other process from the CPU. If it delays
189 * for ~5secs, a NMI error can occur. A way around this is to give up
190 * the processor via msleep, but this is not allowed is under lock.
191 * So, only allow it to sleep for ~4secs if open. Otherwise, delay for
192 * 1sec and sleep for 10ms until the firmware operation has completed
195 while ((status
!= VXGE_HW_OK
) && retry
++ < max_retry
) {
198 status
= __vxge_hw_device_register_poll(
199 &vp_reg
->rts_access_steer_ctrl
,
200 VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE
,
201 VXGE_HW_DEF_DEVICE_POLL_MILLIS
);
204 if (status
!= VXGE_HW_OK
)
207 val64
= readq(&vp_reg
->rts_access_steer_ctrl
);
208 if (val64
& VXGE_HW_RTS_ACCESS_STEER_CTRL_RMACJ_STATUS
) {
209 *data0
= readq(&vp_reg
->rts_access_steer_data0
);
210 *data1
= readq(&vp_reg
->rts_access_steer_data1
);
213 status
= VXGE_HW_FAIL
;
217 spin_unlock(&vpath
->lock
);
222 vxge_hw_upgrade_read_version(struct __vxge_hw_device
*hldev
, u32
*major
,
223 u32
*minor
, u32
*build
)
225 u64 data0
= 0, data1
= 0, steer_ctrl
= 0;
226 struct __vxge_hw_virtualpath
*vpath
;
227 enum vxge_hw_status status
;
229 vpath
= &hldev
->virtual_paths
[hldev
->first_vp_id
];
231 status
= vxge_hw_vpath_fw_api(vpath
,
232 VXGE_HW_FW_UPGRADE_ACTION
,
233 VXGE_HW_FW_UPGRADE_MEMO
,
234 VXGE_HW_FW_UPGRADE_OFFSET_READ
,
235 &data0
, &data1
, &steer_ctrl
);
236 if (status
!= VXGE_HW_OK
)
239 *major
= VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0
);
240 *minor
= VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0
);
241 *build
= VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0
);
246 enum vxge_hw_status
vxge_hw_flash_fw(struct __vxge_hw_device
*hldev
)
248 u64 data0
= 0, data1
= 0, steer_ctrl
= 0;
249 struct __vxge_hw_virtualpath
*vpath
;
250 enum vxge_hw_status status
;
253 vpath
= &hldev
->virtual_paths
[hldev
->first_vp_id
];
255 status
= vxge_hw_vpath_fw_api(vpath
,
256 VXGE_HW_FW_UPGRADE_ACTION
,
257 VXGE_HW_FW_UPGRADE_MEMO
,
258 VXGE_HW_FW_UPGRADE_OFFSET_COMMIT
,
259 &data0
, &data1
, &steer_ctrl
);
260 if (status
!= VXGE_HW_OK
) {
261 vxge_debug_init(VXGE_ERR
, "%s: FW upgrade failed", __func__
);
265 ret
= VXGE_HW_RTS_ACCESS_STEER_CTRL_GET_ACTION(steer_ctrl
) & 0x7F;
267 vxge_debug_init(VXGE_ERR
, "%s: FW commit failed with error %d",
269 status
= VXGE_HW_FAIL
;
277 vxge_update_fw_image(struct __vxge_hw_device
*hldev
, const u8
*fwdata
, int size
)
279 u64 data0
= 0, data1
= 0, steer_ctrl
= 0;
280 struct __vxge_hw_virtualpath
*vpath
;
281 enum vxge_hw_status status
;
282 int ret_code
, sec_code
;
284 vpath
= &hldev
->virtual_paths
[hldev
->first_vp_id
];
286 /* send upgrade start command */
287 status
= vxge_hw_vpath_fw_api(vpath
,
288 VXGE_HW_FW_UPGRADE_ACTION
,
289 VXGE_HW_FW_UPGRADE_MEMO
,
290 VXGE_HW_FW_UPGRADE_OFFSET_START
,
291 &data0
, &data1
, &steer_ctrl
);
292 if (status
!= VXGE_HW_OK
) {
293 vxge_debug_init(VXGE_ERR
, " %s: Upgrade start cmd failed",
298 /* Transfer fw image to adapter 16 bytes at a time */
299 for (; size
> 0; size
-= VXGE_HW_FW_UPGRADE_BLK_SIZE
) {
302 /* The next 128bits of fwdata to be loaded onto the adapter */
303 data0
= *((u64
*)fwdata
);
304 data1
= *((u64
*)fwdata
+ 1);
306 status
= vxge_hw_vpath_fw_api(vpath
,
307 VXGE_HW_FW_UPGRADE_ACTION
,
308 VXGE_HW_FW_UPGRADE_MEMO
,
309 VXGE_HW_FW_UPGRADE_OFFSET_SEND
,
310 &data0
, &data1
, &steer_ctrl
);
311 if (status
!= VXGE_HW_OK
) {
312 vxge_debug_init(VXGE_ERR
, "%s: Upgrade send failed",
317 ret_code
= VXGE_HW_UPGRADE_GET_RET_ERR_CODE(data0
);
319 case VXGE_HW_FW_UPGRADE_OK
:
320 /* All OK, send next 16 bytes. */
322 case VXGE_FW_UPGRADE_BYTES2SKIP
:
323 /* skip bytes in the stream */
324 fwdata
+= (data0
>> 8) & 0xFFFFFFFF;
326 case VXGE_HW_FW_UPGRADE_DONE
:
328 case VXGE_HW_FW_UPGRADE_ERR
:
329 sec_code
= VXGE_HW_UPGRADE_GET_SEC_ERR_CODE(data0
);
331 case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_1
:
332 case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_7
:
334 "corrupted data from .ncf file\n");
336 case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_3
:
337 case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_4
:
338 case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_5
:
339 case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_6
:
340 case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_8
:
341 printk(KERN_ERR
"invalid .ncf file\n");
343 case VXGE_HW_FW_UPGRADE_ERR_BUFFER_OVERFLOW
:
344 printk(KERN_ERR
"buffer overflow\n");
346 case VXGE_HW_FW_UPGRADE_ERR_FAILED_TO_FLASH
:
347 printk(KERN_ERR
"failed to flash the image\n");
349 case VXGE_HW_FW_UPGRADE_ERR_GENERIC_ERROR_UNKNOWN
:
351 "generic error. Unknown error type\n");
354 printk(KERN_ERR
"Unknown error of type %d\n",
358 status
= VXGE_HW_FAIL
;
361 printk(KERN_ERR
"Unknown FW error: %d\n", ret_code
);
362 status
= VXGE_HW_FAIL
;
365 /* point to next 16 bytes */
366 fwdata
+= VXGE_HW_FW_UPGRADE_BLK_SIZE
;
373 vxge_hw_vpath_eprom_img_ver_get(struct __vxge_hw_device
*hldev
,
374 struct eprom_image
*img
)
376 u64 data0
= 0, data1
= 0, steer_ctrl
= 0;
377 struct __vxge_hw_virtualpath
*vpath
;
378 enum vxge_hw_status status
;
381 vpath
= &hldev
->virtual_paths
[hldev
->first_vp_id
];
383 for (i
= 0; i
< VXGE_HW_MAX_ROM_IMAGES
; i
++) {
384 data0
= VXGE_HW_RTS_ACCESS_STEER_ROM_IMAGE_INDEX(i
);
385 data1
= steer_ctrl
= 0;
387 status
= vxge_hw_vpath_fw_api(vpath
,
388 VXGE_HW_FW_API_GET_EPROM_REV
,
389 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
390 0, &data0
, &data1
, &steer_ctrl
);
391 if (status
!= VXGE_HW_OK
)
394 img
[i
].is_valid
= VXGE_HW_GET_EPROM_IMAGE_VALID(data0
);
395 img
[i
].index
= VXGE_HW_GET_EPROM_IMAGE_INDEX(data0
);
396 img
[i
].type
= VXGE_HW_GET_EPROM_IMAGE_TYPE(data0
);
397 img
[i
].version
= VXGE_HW_GET_EPROM_IMAGE_REV(data0
);
404 * __vxge_hw_channel_free - Free memory allocated for channel
405 * This function deallocates memory from the channel and various arrays
408 static void __vxge_hw_channel_free(struct __vxge_hw_channel
*channel
)
410 kfree(channel
->work_arr
);
411 kfree(channel
->free_arr
);
412 kfree(channel
->reserve_arr
);
413 kfree(channel
->orig_arr
);
418 * __vxge_hw_channel_initialize - Initialize a channel
419 * This function initializes a channel by properly setting the
422 static enum vxge_hw_status
423 __vxge_hw_channel_initialize(struct __vxge_hw_channel
*channel
)
426 struct __vxge_hw_virtualpath
*vpath
;
428 vpath
= channel
->vph
->vpath
;
430 if ((channel
->reserve_arr
!= NULL
) && (channel
->orig_arr
!= NULL
)) {
431 for (i
= 0; i
< channel
->length
; i
++)
432 channel
->orig_arr
[i
] = channel
->reserve_arr
[i
];
435 switch (channel
->type
) {
436 case VXGE_HW_CHANNEL_TYPE_FIFO
:
437 vpath
->fifoh
= (struct __vxge_hw_fifo
*)channel
;
438 channel
->stats
= &((struct __vxge_hw_fifo
*)
439 channel
)->stats
->common_stats
;
441 case VXGE_HW_CHANNEL_TYPE_RING
:
442 vpath
->ringh
= (struct __vxge_hw_ring
*)channel
;
443 channel
->stats
= &((struct __vxge_hw_ring
*)
444 channel
)->stats
->common_stats
;
454 * __vxge_hw_channel_reset - Resets a channel
455 * This function resets a channel by properly setting the various references
457 static enum vxge_hw_status
458 __vxge_hw_channel_reset(struct __vxge_hw_channel
*channel
)
462 for (i
= 0; i
< channel
->length
; i
++) {
463 if (channel
->reserve_arr
!= NULL
)
464 channel
->reserve_arr
[i
] = channel
->orig_arr
[i
];
465 if (channel
->free_arr
!= NULL
)
466 channel
->free_arr
[i
] = NULL
;
467 if (channel
->work_arr
!= NULL
)
468 channel
->work_arr
[i
] = NULL
;
470 channel
->free_ptr
= channel
->length
;
471 channel
->reserve_ptr
= channel
->length
;
472 channel
->reserve_top
= 0;
473 channel
->post_index
= 0;
474 channel
->compl_index
= 0;
480 * __vxge_hw_device_pci_e_init
481 * Initialize certain PCI/PCI-X configuration registers
482 * with recommended values. Save config space for future hw resets.
484 static void __vxge_hw_device_pci_e_init(struct __vxge_hw_device
*hldev
)
488 /* Set the PErr Repconse bit and SERR in PCI command register. */
489 pci_read_config_word(hldev
->pdev
, PCI_COMMAND
, &cmd
);
491 pci_write_config_word(hldev
->pdev
, PCI_COMMAND
, cmd
);
493 pci_save_state(hldev
->pdev
);
496 /* __vxge_hw_device_vpath_reset_in_prog_check - Check if vpath reset
498 * This routine checks the vpath reset in progress register is turned zero
500 static enum vxge_hw_status
501 __vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem
*vpath_rst_in_prog
)
503 enum vxge_hw_status status
;
504 status
= __vxge_hw_device_register_poll(vpath_rst_in_prog
,
505 VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(0x1ffff),
506 VXGE_HW_DEF_DEVICE_POLL_MILLIS
);
511 * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion.
512 * Set the swapper bits appropriately for the lagacy section.
514 static enum vxge_hw_status
515 __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem
*legacy_reg
)
518 enum vxge_hw_status status
= VXGE_HW_OK
;
520 val64
= readq(&legacy_reg
->toc_swapper_fb
);
525 case VXGE_HW_SWAPPER_INITIAL_VALUE
:
528 case VXGE_HW_SWAPPER_BYTE_SWAPPED_BIT_FLIPPED
:
529 writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE
,
530 &legacy_reg
->pifm_rd_swap_en
);
531 writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE
,
532 &legacy_reg
->pifm_rd_flip_en
);
533 writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE
,
534 &legacy_reg
->pifm_wr_swap_en
);
535 writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE
,
536 &legacy_reg
->pifm_wr_flip_en
);
539 case VXGE_HW_SWAPPER_BYTE_SWAPPED
:
540 writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE
,
541 &legacy_reg
->pifm_rd_swap_en
);
542 writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE
,
543 &legacy_reg
->pifm_wr_swap_en
);
546 case VXGE_HW_SWAPPER_BIT_FLIPPED
:
547 writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE
,
548 &legacy_reg
->pifm_rd_flip_en
);
549 writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE
,
550 &legacy_reg
->pifm_wr_flip_en
);
556 val64
= readq(&legacy_reg
->toc_swapper_fb
);
558 if (val64
!= VXGE_HW_SWAPPER_INITIAL_VALUE
)
559 status
= VXGE_HW_ERR_SWAPPER_CTRL
;
565 * __vxge_hw_device_toc_get
566 * This routine sets the swapper and reads the toc pointer and returns the
567 * memory mapped address of the toc
569 static struct vxge_hw_toc_reg __iomem
*
570 __vxge_hw_device_toc_get(void __iomem
*bar0
)
573 struct vxge_hw_toc_reg __iomem
*toc
= NULL
;
574 enum vxge_hw_status status
;
576 struct vxge_hw_legacy_reg __iomem
*legacy_reg
=
577 (struct vxge_hw_legacy_reg __iomem
*)bar0
;
579 status
= __vxge_hw_legacy_swapper_set(legacy_reg
);
580 if (status
!= VXGE_HW_OK
)
583 val64
= readq(&legacy_reg
->toc_first_pointer
);
590 * __vxge_hw_device_reg_addr_get
591 * This routine sets the swapper and reads the toc pointer and initializes the
592 * register location pointers in the device object. It waits until the ric is
593 * completed initializing registers.
595 static enum vxge_hw_status
596 __vxge_hw_device_reg_addr_get(struct __vxge_hw_device
*hldev
)
600 enum vxge_hw_status status
= VXGE_HW_OK
;
602 hldev
->legacy_reg
= hldev
->bar0
;
604 hldev
->toc_reg
= __vxge_hw_device_toc_get(hldev
->bar0
);
605 if (hldev
->toc_reg
== NULL
) {
606 status
= VXGE_HW_FAIL
;
610 val64
= readq(&hldev
->toc_reg
->toc_common_pointer
);
611 hldev
->common_reg
= hldev
->bar0
+ val64
;
613 val64
= readq(&hldev
->toc_reg
->toc_mrpcim_pointer
);
614 hldev
->mrpcim_reg
= hldev
->bar0
+ val64
;
616 for (i
= 0; i
< VXGE_HW_TITAN_SRPCIM_REG_SPACES
; i
++) {
617 val64
= readq(&hldev
->toc_reg
->toc_srpcim_pointer
[i
]);
618 hldev
->srpcim_reg
[i
] = hldev
->bar0
+ val64
;
621 for (i
= 0; i
< VXGE_HW_TITAN_VPMGMT_REG_SPACES
; i
++) {
622 val64
= readq(&hldev
->toc_reg
->toc_vpmgmt_pointer
[i
]);
623 hldev
->vpmgmt_reg
[i
] = hldev
->bar0
+ val64
;
626 for (i
= 0; i
< VXGE_HW_TITAN_VPATH_REG_SPACES
; i
++) {
627 val64
= readq(&hldev
->toc_reg
->toc_vpath_pointer
[i
]);
628 hldev
->vpath_reg
[i
] = hldev
->bar0
+ val64
;
631 val64
= readq(&hldev
->toc_reg
->toc_kdfc
);
633 switch (VXGE_HW_TOC_GET_KDFC_INITIAL_BIR(val64
)) {
635 hldev
->kdfc
= hldev
->bar0
+ VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64
) ;
641 status
= __vxge_hw_device_vpath_reset_in_prog_check(
642 (u64 __iomem
*)&hldev
->common_reg
->vpath_rst_in_prog
);
648 * __vxge_hw_device_access_rights_get: Get Access Rights of the driver
649 * This routine returns the Access Rights of the driver
652 __vxge_hw_device_access_rights_get(u32 host_type
, u32 func_id
)
654 u32 access_rights
= VXGE_HW_DEVICE_ACCESS_RIGHT_VPATH
;
657 case VXGE_HW_NO_MR_NO_SR_NORMAL_FUNCTION
:
659 access_rights
|= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
|
660 VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
;
663 case VXGE_HW_MR_NO_SR_VH0_BASE_FUNCTION
:
664 access_rights
|= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
|
665 VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
;
667 case VXGE_HW_NO_MR_SR_VH0_FUNCTION0
:
668 access_rights
|= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
|
669 VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
;
671 case VXGE_HW_NO_MR_SR_VH0_VIRTUAL_FUNCTION
:
672 case VXGE_HW_SR_VH_VIRTUAL_FUNCTION
:
673 case VXGE_HW_MR_SR_VH0_INVALID_CONFIG
:
675 case VXGE_HW_SR_VH_FUNCTION0
:
676 case VXGE_HW_VH_NORMAL_FUNCTION
:
677 access_rights
|= VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
;
681 return access_rights
;
684 * __vxge_hw_device_is_privilaged
685 * This routine checks if the device function is privilaged or not
689 __vxge_hw_device_is_privilaged(u32 host_type
, u32 func_id
)
691 if (__vxge_hw_device_access_rights_get(host_type
,
693 VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
)
696 return VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
700 * __vxge_hw_vpath_func_id_get - Get the function id of the vpath.
701 * Returns the function number of the vpath.
704 __vxge_hw_vpath_func_id_get(struct vxge_hw_vpmgmt_reg __iomem
*vpmgmt_reg
)
708 val64
= readq(&vpmgmt_reg
->vpath_to_func_map_cfg1
);
711 (u32
)VXGE_HW_VPATH_TO_FUNC_MAP_CFG1_GET_VPATH_TO_FUNC_MAP_CFG1(val64
);
715 * __vxge_hw_device_host_info_get
716 * This routine returns the host type assignments
718 static void __vxge_hw_device_host_info_get(struct __vxge_hw_device
*hldev
)
723 val64
= readq(&hldev
->common_reg
->host_type_assignments
);
726 (u32
)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64
);
728 hldev
->vpath_assignments
= readq(&hldev
->common_reg
->vpath_assignments
);
730 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
731 if (!(hldev
->vpath_assignments
& vxge_mBIT(i
)))
735 __vxge_hw_vpath_func_id_get(hldev
->vpmgmt_reg
[i
]);
737 hldev
->access_rights
= __vxge_hw_device_access_rights_get(
738 hldev
->host_type
, hldev
->func_id
);
740 hldev
->virtual_paths
[i
].vp_open
= VXGE_HW_VP_NOT_OPEN
;
741 hldev
->virtual_paths
[i
].vp_reg
= hldev
->vpath_reg
[i
];
743 hldev
->first_vp_id
= i
;
749 * __vxge_hw_verify_pci_e_info - Validate the pci-e link parameters such as
750 * link width and signalling rate.
752 static enum vxge_hw_status
753 __vxge_hw_verify_pci_e_info(struct __vxge_hw_device
*hldev
)
755 struct pci_dev
*dev
= hldev
->pdev
;
758 /* Get the negotiated link width and speed from PCI config space */
759 pcie_capability_read_word(dev
, PCI_EXP_LNKSTA
, &lnk
);
761 if ((lnk
& PCI_EXP_LNKSTA_CLS
) != 1)
762 return VXGE_HW_ERR_INVALID_PCI_INFO
;
764 switch ((lnk
& PCI_EXP_LNKSTA_NLW
) >> 4) {
765 case PCIE_LNK_WIDTH_RESRV
:
772 return VXGE_HW_ERR_INVALID_PCI_INFO
;
779 * __vxge_hw_device_initialize
780 * Initialize Titan-V hardware.
782 static enum vxge_hw_status
783 __vxge_hw_device_initialize(struct __vxge_hw_device
*hldev
)
785 enum vxge_hw_status status
= VXGE_HW_OK
;
787 if (VXGE_HW_OK
== __vxge_hw_device_is_privilaged(hldev
->host_type
,
789 /* Validate the pci-e link width and speed */
790 status
= __vxge_hw_verify_pci_e_info(hldev
);
791 if (status
!= VXGE_HW_OK
)
800 * __vxge_hw_vpath_fw_ver_get - Get the fw version
803 static enum vxge_hw_status
804 __vxge_hw_vpath_fw_ver_get(struct __vxge_hw_virtualpath
*vpath
,
805 struct vxge_hw_device_hw_info
*hw_info
)
807 struct vxge_hw_device_version
*fw_version
= &hw_info
->fw_version
;
808 struct vxge_hw_device_date
*fw_date
= &hw_info
->fw_date
;
809 struct vxge_hw_device_version
*flash_version
= &hw_info
->flash_version
;
810 struct vxge_hw_device_date
*flash_date
= &hw_info
->flash_date
;
811 u64 data0
, data1
= 0, steer_ctrl
= 0;
812 enum vxge_hw_status status
;
814 status
= vxge_hw_vpath_fw_api(vpath
,
815 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY
,
816 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
817 0, &data0
, &data1
, &steer_ctrl
);
818 if (status
!= VXGE_HW_OK
)
822 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_DAY(data0
);
824 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MONTH(data0
);
826 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_YEAR(data0
);
828 snprintf(fw_date
->date
, VXGE_HW_FW_STRLEN
, "%2.2d/%2.2d/%4.4d",
829 fw_date
->month
, fw_date
->day
, fw_date
->year
);
832 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0
);
834 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0
);
836 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0
);
838 snprintf(fw_version
->version
, VXGE_HW_FW_STRLEN
, "%d.%d.%d",
839 fw_version
->major
, fw_version
->minor
, fw_version
->build
);
842 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_DAY(data1
);
844 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MONTH(data1
);
846 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_YEAR(data1
);
848 snprintf(flash_date
->date
, VXGE_HW_FW_STRLEN
, "%2.2d/%2.2d/%4.4d",
849 flash_date
->month
, flash_date
->day
, flash_date
->year
);
851 flash_version
->major
=
852 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MAJOR(data1
);
853 flash_version
->minor
=
854 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MINOR(data1
);
855 flash_version
->build
=
856 (u32
) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_BUILD(data1
);
858 snprintf(flash_version
->version
, VXGE_HW_FW_STRLEN
, "%d.%d.%d",
859 flash_version
->major
, flash_version
->minor
,
860 flash_version
->build
);
867 * __vxge_hw_vpath_card_info_get - Get the serial numbers,
868 * part number and product description.
870 static enum vxge_hw_status
871 __vxge_hw_vpath_card_info_get(struct __vxge_hw_virtualpath
*vpath
,
872 struct vxge_hw_device_hw_info
*hw_info
)
874 enum vxge_hw_status status
;
875 u64 data0
, data1
= 0, steer_ctrl
= 0;
876 u8
*serial_number
= hw_info
->serial_number
;
877 u8
*part_number
= hw_info
->part_number
;
878 u8
*product_desc
= hw_info
->product_desc
;
881 data0
= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_SERIAL_NUMBER
;
883 status
= vxge_hw_vpath_fw_api(vpath
,
884 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY
,
885 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
886 0, &data0
, &data1
, &steer_ctrl
);
887 if (status
!= VXGE_HW_OK
)
890 ((u64
*)serial_number
)[0] = be64_to_cpu(data0
);
891 ((u64
*)serial_number
)[1] = be64_to_cpu(data1
);
893 data0
= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_PART_NUMBER
;
894 data1
= steer_ctrl
= 0;
896 status
= vxge_hw_vpath_fw_api(vpath
,
897 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY
,
898 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
899 0, &data0
, &data1
, &steer_ctrl
);
900 if (status
!= VXGE_HW_OK
)
903 ((u64
*)part_number
)[0] = be64_to_cpu(data0
);
904 ((u64
*)part_number
)[1] = be64_to_cpu(data1
);
906 for (i
= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_0
;
907 i
<= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_3
; i
++) {
909 data1
= steer_ctrl
= 0;
911 status
= vxge_hw_vpath_fw_api(vpath
,
912 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY
,
913 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
914 0, &data0
, &data1
, &steer_ctrl
);
915 if (status
!= VXGE_HW_OK
)
918 ((u64
*)product_desc
)[j
++] = be64_to_cpu(data0
);
919 ((u64
*)product_desc
)[j
++] = be64_to_cpu(data1
);
926 * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode
927 * Returns pci function mode
929 static enum vxge_hw_status
930 __vxge_hw_vpath_pci_func_mode_get(struct __vxge_hw_virtualpath
*vpath
,
931 struct vxge_hw_device_hw_info
*hw_info
)
933 u64 data0
, data1
= 0, steer_ctrl
= 0;
934 enum vxge_hw_status status
;
938 status
= vxge_hw_vpath_fw_api(vpath
,
939 VXGE_HW_FW_API_GET_FUNC_MODE
,
940 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
941 0, &data0
, &data1
, &steer_ctrl
);
942 if (status
!= VXGE_HW_OK
)
945 hw_info
->function_mode
= VXGE_HW_GET_FUNC_MODE_VAL(data0
);
950 * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath
951 * from MAC address table.
953 static enum vxge_hw_status
954 __vxge_hw_vpath_addr_get(struct __vxge_hw_virtualpath
*vpath
,
955 u8
*macaddr
, u8
*macaddr_mask
)
957 u64 action
= VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_FIRST_ENTRY
,
958 data0
= 0, data1
= 0, steer_ctrl
= 0;
959 enum vxge_hw_status status
;
963 status
= vxge_hw_vpath_fw_api(vpath
, action
,
964 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA
,
965 0, &data0
, &data1
, &steer_ctrl
);
966 if (status
!= VXGE_HW_OK
)
969 data0
= VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data0
);
970 data1
= VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK(
973 for (i
= ETH_ALEN
; i
> 0; i
--) {
974 macaddr
[i
- 1] = (u8
) (data0
& 0xFF);
977 macaddr_mask
[i
- 1] = (u8
) (data1
& 0xFF);
981 action
= VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY
;
982 data0
= 0, data1
= 0, steer_ctrl
= 0;
984 } while (!is_valid_ether_addr(macaddr
));
990 * vxge_hw_device_hw_info_get - Get the hw information
991 * Returns the vpath mask that has the bits set for each vpath allocated
992 * for the driver, FW version information, and the first mac address for
996 vxge_hw_device_hw_info_get(void __iomem
*bar0
,
997 struct vxge_hw_device_hw_info
*hw_info
)
1001 struct vxge_hw_toc_reg __iomem
*toc
;
1002 struct vxge_hw_mrpcim_reg __iomem
*mrpcim_reg
;
1003 struct vxge_hw_common_reg __iomem
*common_reg
;
1004 struct vxge_hw_vpmgmt_reg __iomem
*vpmgmt_reg
;
1005 enum vxge_hw_status status
;
1006 struct __vxge_hw_virtualpath vpath
;
1008 memset(hw_info
, 0, sizeof(struct vxge_hw_device_hw_info
));
1010 toc
= __vxge_hw_device_toc_get(bar0
);
1012 status
= VXGE_HW_ERR_CRITICAL
;
1016 val64
= readq(&toc
->toc_common_pointer
);
1017 common_reg
= bar0
+ val64
;
1019 status
= __vxge_hw_device_vpath_reset_in_prog_check(
1020 (u64 __iomem
*)&common_reg
->vpath_rst_in_prog
);
1021 if (status
!= VXGE_HW_OK
)
1024 hw_info
->vpath_mask
= readq(&common_reg
->vpath_assignments
);
1026 val64
= readq(&common_reg
->host_type_assignments
);
1028 hw_info
->host_type
=
1029 (u32
)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64
);
1031 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1032 if (!((hw_info
->vpath_mask
) & vxge_mBIT(i
)))
1035 val64
= readq(&toc
->toc_vpmgmt_pointer
[i
]);
1037 vpmgmt_reg
= bar0
+ val64
;
1039 hw_info
->func_id
= __vxge_hw_vpath_func_id_get(vpmgmt_reg
);
1040 if (__vxge_hw_device_access_rights_get(hw_info
->host_type
,
1042 VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
) {
1044 val64
= readq(&toc
->toc_mrpcim_pointer
);
1046 mrpcim_reg
= bar0
+ val64
;
1048 writeq(0, &mrpcim_reg
->xgmac_gen_fw_memo_mask
);
1052 val64
= readq(&toc
->toc_vpath_pointer
[i
]);
1054 spin_lock_init(&vpath
.lock
);
1055 vpath
.vp_reg
= bar0
+ val64
;
1056 vpath
.vp_open
= VXGE_HW_VP_NOT_OPEN
;
1058 status
= __vxge_hw_vpath_pci_func_mode_get(&vpath
, hw_info
);
1059 if (status
!= VXGE_HW_OK
)
1062 status
= __vxge_hw_vpath_fw_ver_get(&vpath
, hw_info
);
1063 if (status
!= VXGE_HW_OK
)
1066 status
= __vxge_hw_vpath_card_info_get(&vpath
, hw_info
);
1067 if (status
!= VXGE_HW_OK
)
1073 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1074 if (!((hw_info
->vpath_mask
) & vxge_mBIT(i
)))
1077 val64
= readq(&toc
->toc_vpath_pointer
[i
]);
1078 vpath
.vp_reg
= bar0
+ val64
;
1079 vpath
.vp_open
= VXGE_HW_VP_NOT_OPEN
;
1081 status
= __vxge_hw_vpath_addr_get(&vpath
,
1082 hw_info
->mac_addrs
[i
],
1083 hw_info
->mac_addr_masks
[i
]);
1084 if (status
!= VXGE_HW_OK
)
1092 * __vxge_hw_blockpool_destroy - Deallocates the block pool
1094 static void __vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool
*blockpool
)
1096 struct __vxge_hw_device
*hldev
;
1097 struct list_head
*p
, *n
;
1100 if (blockpool
== NULL
) {
1105 hldev
= blockpool
->hldev
;
1107 list_for_each_safe(p
, n
, &blockpool
->free_block_list
) {
1108 pci_unmap_single(hldev
->pdev
,
1109 ((struct __vxge_hw_blockpool_entry
*)p
)->dma_addr
,
1110 ((struct __vxge_hw_blockpool_entry
*)p
)->length
,
1111 PCI_DMA_BIDIRECTIONAL
);
1113 vxge_os_dma_free(hldev
->pdev
,
1114 ((struct __vxge_hw_blockpool_entry
*)p
)->memblock
,
1115 &((struct __vxge_hw_blockpool_entry
*)p
)->acc_handle
);
1117 list_del(&((struct __vxge_hw_blockpool_entry
*)p
)->item
);
1119 blockpool
->pool_size
--;
1122 list_for_each_safe(p
, n
, &blockpool
->free_entry_list
) {
1123 list_del(&((struct __vxge_hw_blockpool_entry
*)p
)->item
);
1132 * __vxge_hw_blockpool_create - Create block pool
1134 static enum vxge_hw_status
1135 __vxge_hw_blockpool_create(struct __vxge_hw_device
*hldev
,
1136 struct __vxge_hw_blockpool
*blockpool
,
1141 struct __vxge_hw_blockpool_entry
*entry
= NULL
;
1143 dma_addr_t dma_addr
;
1144 struct pci_dev
*dma_handle
;
1145 struct pci_dev
*acc_handle
;
1146 enum vxge_hw_status status
= VXGE_HW_OK
;
1148 if (blockpool
== NULL
) {
1149 status
= VXGE_HW_FAIL
;
1150 goto blockpool_create_exit
;
1153 blockpool
->hldev
= hldev
;
1154 blockpool
->block_size
= VXGE_HW_BLOCK_SIZE
;
1155 blockpool
->pool_size
= 0;
1156 blockpool
->pool_max
= pool_max
;
1157 blockpool
->req_out
= 0;
1159 INIT_LIST_HEAD(&blockpool
->free_block_list
);
1160 INIT_LIST_HEAD(&blockpool
->free_entry_list
);
1162 for (i
= 0; i
< pool_size
+ pool_max
; i
++) {
1163 entry
= kzalloc(sizeof(struct __vxge_hw_blockpool_entry
),
1165 if (entry
== NULL
) {
1166 __vxge_hw_blockpool_destroy(blockpool
);
1167 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1168 goto blockpool_create_exit
;
1170 list_add(&entry
->item
, &blockpool
->free_entry_list
);
1173 for (i
= 0; i
< pool_size
; i
++) {
1174 memblock
= vxge_os_dma_malloc(
1179 if (memblock
== NULL
) {
1180 __vxge_hw_blockpool_destroy(blockpool
);
1181 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1182 goto blockpool_create_exit
;
1185 dma_addr
= pci_map_single(hldev
->pdev
, memblock
,
1186 VXGE_HW_BLOCK_SIZE
, PCI_DMA_BIDIRECTIONAL
);
1187 if (unlikely(pci_dma_mapping_error(hldev
->pdev
,
1189 vxge_os_dma_free(hldev
->pdev
, memblock
, &acc_handle
);
1190 __vxge_hw_blockpool_destroy(blockpool
);
1191 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1192 goto blockpool_create_exit
;
1195 if (!list_empty(&blockpool
->free_entry_list
))
1196 entry
= (struct __vxge_hw_blockpool_entry
*)
1197 list_first_entry(&blockpool
->free_entry_list
,
1198 struct __vxge_hw_blockpool_entry
,
1203 kzalloc(sizeof(struct __vxge_hw_blockpool_entry
),
1205 if (entry
!= NULL
) {
1206 list_del(&entry
->item
);
1207 entry
->length
= VXGE_HW_BLOCK_SIZE
;
1208 entry
->memblock
= memblock
;
1209 entry
->dma_addr
= dma_addr
;
1210 entry
->acc_handle
= acc_handle
;
1211 entry
->dma_handle
= dma_handle
;
1212 list_add(&entry
->item
,
1213 &blockpool
->free_block_list
);
1214 blockpool
->pool_size
++;
1216 __vxge_hw_blockpool_destroy(blockpool
);
1217 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1218 goto blockpool_create_exit
;
1222 blockpool_create_exit
:
1227 * __vxge_hw_device_fifo_config_check - Check fifo configuration.
1228 * Check the fifo configuration
1230 static enum vxge_hw_status
1231 __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config
*fifo_config
)
1233 if ((fifo_config
->fifo_blocks
< VXGE_HW_MIN_FIFO_BLOCKS
) ||
1234 (fifo_config
->fifo_blocks
> VXGE_HW_MAX_FIFO_BLOCKS
))
1235 return VXGE_HW_BADCFG_FIFO_BLOCKS
;
1241 * __vxge_hw_device_vpath_config_check - Check vpath configuration.
1242 * Check the vpath configuration
1244 static enum vxge_hw_status
1245 __vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config
*vp_config
)
1247 enum vxge_hw_status status
;
1249 if ((vp_config
->min_bandwidth
< VXGE_HW_VPATH_BANDWIDTH_MIN
) ||
1250 (vp_config
->min_bandwidth
> VXGE_HW_VPATH_BANDWIDTH_MAX
))
1251 return VXGE_HW_BADCFG_VPATH_MIN_BANDWIDTH
;
1253 status
= __vxge_hw_device_fifo_config_check(&vp_config
->fifo
);
1254 if (status
!= VXGE_HW_OK
)
1257 if ((vp_config
->mtu
!= VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU
) &&
1258 ((vp_config
->mtu
< VXGE_HW_VPATH_MIN_INITIAL_MTU
) ||
1259 (vp_config
->mtu
> VXGE_HW_VPATH_MAX_INITIAL_MTU
)))
1260 return VXGE_HW_BADCFG_VPATH_MTU
;
1262 if ((vp_config
->rpa_strip_vlan_tag
!=
1263 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT
) &&
1264 (vp_config
->rpa_strip_vlan_tag
!=
1265 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
) &&
1266 (vp_config
->rpa_strip_vlan_tag
!=
1267 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_DISABLE
))
1268 return VXGE_HW_BADCFG_VPATH_RPA_STRIP_VLAN_TAG
;
1274 * __vxge_hw_device_config_check - Check device configuration.
1275 * Check the device configuration
1277 static enum vxge_hw_status
1278 __vxge_hw_device_config_check(struct vxge_hw_device_config
*new_config
)
1281 enum vxge_hw_status status
;
1283 if ((new_config
->intr_mode
!= VXGE_HW_INTR_MODE_IRQLINE
) &&
1284 (new_config
->intr_mode
!= VXGE_HW_INTR_MODE_MSIX
) &&
1285 (new_config
->intr_mode
!= VXGE_HW_INTR_MODE_MSIX_ONE_SHOT
) &&
1286 (new_config
->intr_mode
!= VXGE_HW_INTR_MODE_DEF
))
1287 return VXGE_HW_BADCFG_INTR_MODE
;
1289 if ((new_config
->rts_mac_en
!= VXGE_HW_RTS_MAC_DISABLE
) &&
1290 (new_config
->rts_mac_en
!= VXGE_HW_RTS_MAC_ENABLE
))
1291 return VXGE_HW_BADCFG_RTS_MAC_EN
;
1293 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1294 status
= __vxge_hw_device_vpath_config_check(
1295 &new_config
->vp_config
[i
]);
1296 if (status
!= VXGE_HW_OK
)
1304 * vxge_hw_device_initialize - Initialize Titan device.
1305 * Initialize Titan device. Note that all the arguments of this public API
1306 * are 'IN', including @hldev. Driver cooperates with
1307 * OS to find new Titan device, locate its PCI and memory spaces.
1309 * When done, the driver allocates sizeof(struct __vxge_hw_device) bytes for HW
1310 * to enable the latter to perform Titan hardware initialization.
1313 vxge_hw_device_initialize(
1314 struct __vxge_hw_device
**devh
,
1315 struct vxge_hw_device_attr
*attr
,
1316 struct vxge_hw_device_config
*device_config
)
1320 struct __vxge_hw_device
*hldev
= NULL
;
1321 enum vxge_hw_status status
= VXGE_HW_OK
;
1323 status
= __vxge_hw_device_config_check(device_config
);
1324 if (status
!= VXGE_HW_OK
)
1327 hldev
= vzalloc(sizeof(struct __vxge_hw_device
));
1328 if (hldev
== NULL
) {
1329 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1333 hldev
->magic
= VXGE_HW_DEVICE_MAGIC
;
1335 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_ALL
);
1338 memcpy(&hldev
->config
, device_config
,
1339 sizeof(struct vxge_hw_device_config
));
1341 hldev
->bar0
= attr
->bar0
;
1342 hldev
->pdev
= attr
->pdev
;
1344 hldev
->uld_callbacks
= attr
->uld_callbacks
;
1346 __vxge_hw_device_pci_e_init(hldev
);
1348 status
= __vxge_hw_device_reg_addr_get(hldev
);
1349 if (status
!= VXGE_HW_OK
) {
1354 __vxge_hw_device_host_info_get(hldev
);
1356 /* Incrementing for stats blocks */
1359 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1360 if (!(hldev
->vpath_assignments
& vxge_mBIT(i
)))
1363 if (device_config
->vp_config
[i
].ring
.enable
==
1364 VXGE_HW_RING_ENABLE
)
1365 nblocks
+= device_config
->vp_config
[i
].ring
.ring_blocks
;
1367 if (device_config
->vp_config
[i
].fifo
.enable
==
1368 VXGE_HW_FIFO_ENABLE
)
1369 nblocks
+= device_config
->vp_config
[i
].fifo
.fifo_blocks
;
1373 if (__vxge_hw_blockpool_create(hldev
,
1375 device_config
->dma_blockpool_initial
+ nblocks
,
1376 device_config
->dma_blockpool_max
+ nblocks
) != VXGE_HW_OK
) {
1378 vxge_hw_device_terminate(hldev
);
1379 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
1383 status
= __vxge_hw_device_initialize(hldev
);
1384 if (status
!= VXGE_HW_OK
) {
1385 vxge_hw_device_terminate(hldev
);
1395 * vxge_hw_device_terminate - Terminate Titan device.
1396 * Terminate HW device.
1399 vxge_hw_device_terminate(struct __vxge_hw_device
*hldev
)
1401 vxge_assert(hldev
->magic
== VXGE_HW_DEVICE_MAGIC
);
1403 hldev
->magic
= VXGE_HW_DEVICE_DEAD
;
1404 __vxge_hw_blockpool_destroy(&hldev
->block_pool
);
1409 * __vxge_hw_vpath_stats_access - Get the statistics from the given location
1410 * and offset and perform an operation
1412 static enum vxge_hw_status
1413 __vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath
*vpath
,
1414 u32 operation
, u32 offset
, u64
*stat
)
1417 enum vxge_hw_status status
= VXGE_HW_OK
;
1418 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
1420 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
1421 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
1422 goto vpath_stats_access_exit
;
1425 vp_reg
= vpath
->vp_reg
;
1427 val64
= VXGE_HW_XMAC_STATS_ACCESS_CMD_OP(operation
) |
1428 VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE
|
1429 VXGE_HW_XMAC_STATS_ACCESS_CMD_OFFSET_SEL(offset
);
1431 status
= __vxge_hw_pio_mem_write64(val64
,
1432 &vp_reg
->xmac_stats_access_cmd
,
1433 VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE
,
1434 vpath
->hldev
->config
.device_poll_millis
);
1435 if ((status
== VXGE_HW_OK
) && (operation
== VXGE_HW_STATS_OP_READ
))
1436 *stat
= readq(&vp_reg
->xmac_stats_access_data
);
1440 vpath_stats_access_exit
:
1445 * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath
1447 static enum vxge_hw_status
1448 __vxge_hw_vpath_xmac_tx_stats_get(struct __vxge_hw_virtualpath
*vpath
,
1449 struct vxge_hw_xmac_vpath_tx_stats
*vpath_tx_stats
)
1453 u32 offset
= VXGE_HW_STATS_VPATH_TX_OFFSET
;
1454 enum vxge_hw_status status
= VXGE_HW_OK
;
1456 val64
= (u64
*)vpath_tx_stats
;
1458 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
1459 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
1463 for (i
= 0; i
< sizeof(struct vxge_hw_xmac_vpath_tx_stats
) / 8; i
++) {
1464 status
= __vxge_hw_vpath_stats_access(vpath
,
1465 VXGE_HW_STATS_OP_READ
,
1467 if (status
!= VXGE_HW_OK
)
1477 * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath
1479 static enum vxge_hw_status
1480 __vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath
*vpath
,
1481 struct vxge_hw_xmac_vpath_rx_stats
*vpath_rx_stats
)
1484 enum vxge_hw_status status
= VXGE_HW_OK
;
1486 u32 offset
= VXGE_HW_STATS_VPATH_RX_OFFSET
;
1487 val64
= (u64
*) vpath_rx_stats
;
1489 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
1490 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
1493 for (i
= 0; i
< sizeof(struct vxge_hw_xmac_vpath_rx_stats
) / 8; i
++) {
1494 status
= __vxge_hw_vpath_stats_access(vpath
,
1495 VXGE_HW_STATS_OP_READ
,
1496 offset
>> 3, val64
);
1497 if (status
!= VXGE_HW_OK
)
1508 * __vxge_hw_vpath_stats_get - Get the vpath hw statistics.
1510 static enum vxge_hw_status
1511 __vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath
*vpath
,
1512 struct vxge_hw_vpath_stats_hw_info
*hw_stats
)
1515 enum vxge_hw_status status
= VXGE_HW_OK
;
1516 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
1518 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
1519 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
1522 vp_reg
= vpath
->vp_reg
;
1524 val64
= readq(&vp_reg
->vpath_debug_stats0
);
1525 hw_stats
->ini_num_mwr_sent
=
1526 (u32
)VXGE_HW_VPATH_DEBUG_STATS0_GET_INI_NUM_MWR_SENT(val64
);
1528 val64
= readq(&vp_reg
->vpath_debug_stats1
);
1529 hw_stats
->ini_num_mrd_sent
=
1530 (u32
)VXGE_HW_VPATH_DEBUG_STATS1_GET_INI_NUM_MRD_SENT(val64
);
1532 val64
= readq(&vp_reg
->vpath_debug_stats2
);
1533 hw_stats
->ini_num_cpl_rcvd
=
1534 (u32
)VXGE_HW_VPATH_DEBUG_STATS2_GET_INI_NUM_CPL_RCVD(val64
);
1536 val64
= readq(&vp_reg
->vpath_debug_stats3
);
1537 hw_stats
->ini_num_mwr_byte_sent
=
1538 VXGE_HW_VPATH_DEBUG_STATS3_GET_INI_NUM_MWR_BYTE_SENT(val64
);
1540 val64
= readq(&vp_reg
->vpath_debug_stats4
);
1541 hw_stats
->ini_num_cpl_byte_rcvd
=
1542 VXGE_HW_VPATH_DEBUG_STATS4_GET_INI_NUM_CPL_BYTE_RCVD(val64
);
1544 val64
= readq(&vp_reg
->vpath_debug_stats5
);
1545 hw_stats
->wrcrdtarb_xoff
=
1546 (u32
)VXGE_HW_VPATH_DEBUG_STATS5_GET_WRCRDTARB_XOFF(val64
);
1548 val64
= readq(&vp_reg
->vpath_debug_stats6
);
1549 hw_stats
->rdcrdtarb_xoff
=
1550 (u32
)VXGE_HW_VPATH_DEBUG_STATS6_GET_RDCRDTARB_XOFF(val64
);
1552 val64
= readq(&vp_reg
->vpath_genstats_count01
);
1553 hw_stats
->vpath_genstats_count0
=
1554 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT0(
1557 val64
= readq(&vp_reg
->vpath_genstats_count01
);
1558 hw_stats
->vpath_genstats_count1
=
1559 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT1(
1562 val64
= readq(&vp_reg
->vpath_genstats_count23
);
1563 hw_stats
->vpath_genstats_count2
=
1564 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT2(
1567 val64
= readq(&vp_reg
->vpath_genstats_count01
);
1568 hw_stats
->vpath_genstats_count3
=
1569 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT3(
1572 val64
= readq(&vp_reg
->vpath_genstats_count4
);
1573 hw_stats
->vpath_genstats_count4
=
1574 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT4_GET_PPIF_VPATH_GENSTATS_COUNT4(
1577 val64
= readq(&vp_reg
->vpath_genstats_count5
);
1578 hw_stats
->vpath_genstats_count5
=
1579 (u32
)VXGE_HW_VPATH_GENSTATS_COUNT5_GET_PPIF_VPATH_GENSTATS_COUNT5(
1582 status
= __vxge_hw_vpath_xmac_tx_stats_get(vpath
, &hw_stats
->tx_stats
);
1583 if (status
!= VXGE_HW_OK
)
1586 status
= __vxge_hw_vpath_xmac_rx_stats_get(vpath
, &hw_stats
->rx_stats
);
1587 if (status
!= VXGE_HW_OK
)
1590 VXGE_HW_VPATH_STATS_PIO_READ(
1591 VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM0_OFFSET
);
1593 hw_stats
->prog_event_vnum0
=
1594 (u32
)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM0(val64
);
1596 hw_stats
->prog_event_vnum1
=
1597 (u32
)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM1(val64
);
1599 VXGE_HW_VPATH_STATS_PIO_READ(
1600 VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM2_OFFSET
);
1602 hw_stats
->prog_event_vnum2
=
1603 (u32
)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM2(val64
);
1605 hw_stats
->prog_event_vnum3
=
1606 (u32
)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM3(val64
);
1608 val64
= readq(&vp_reg
->rx_multi_cast_stats
);
1609 hw_stats
->rx_multi_cast_frame_discard
=
1610 (u16
)VXGE_HW_RX_MULTI_CAST_STATS_GET_FRAME_DISCARD(val64
);
1612 val64
= readq(&vp_reg
->rx_frm_transferred
);
1613 hw_stats
->rx_frm_transferred
=
1614 (u32
)VXGE_HW_RX_FRM_TRANSFERRED_GET_RX_FRM_TRANSFERRED(val64
);
1616 val64
= readq(&vp_reg
->rxd_returned
);
1617 hw_stats
->rxd_returned
=
1618 (u16
)VXGE_HW_RXD_RETURNED_GET_RXD_RETURNED(val64
);
1620 val64
= readq(&vp_reg
->dbg_stats_rx_mpa
);
1621 hw_stats
->rx_mpa_len_fail_frms
=
1622 (u16
)VXGE_HW_DBG_STATS_GET_RX_MPA_LEN_FAIL_FRMS(val64
);
1623 hw_stats
->rx_mpa_mrk_fail_frms
=
1624 (u16
)VXGE_HW_DBG_STATS_GET_RX_MPA_MRK_FAIL_FRMS(val64
);
1625 hw_stats
->rx_mpa_crc_fail_frms
=
1626 (u16
)VXGE_HW_DBG_STATS_GET_RX_MPA_CRC_FAIL_FRMS(val64
);
1628 val64
= readq(&vp_reg
->dbg_stats_rx_fau
);
1629 hw_stats
->rx_permitted_frms
=
1630 (u16
)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_PERMITTED_FRMS(val64
);
1631 hw_stats
->rx_vp_reset_discarded_frms
=
1632 (u16
)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_VP_RESET_DISCARDED_FRMS(val64
);
1633 hw_stats
->rx_wol_frms
=
1634 (u16
)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_WOL_FRMS(val64
);
1636 val64
= readq(&vp_reg
->tx_vp_reset_discarded_frms
);
1637 hw_stats
->tx_vp_reset_discarded_frms
=
1638 (u16
)VXGE_HW_TX_VP_RESET_DISCARDED_FRMS_GET_TX_VP_RESET_DISCARDED_FRMS(
1645 * vxge_hw_device_stats_get - Get the device hw statistics.
1646 * Returns the vpath h/w stats for the device.
1649 vxge_hw_device_stats_get(struct __vxge_hw_device
*hldev
,
1650 struct vxge_hw_device_stats_hw_info
*hw_stats
)
1653 enum vxge_hw_status status
= VXGE_HW_OK
;
1655 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1656 if (!(hldev
->vpaths_deployed
& vxge_mBIT(i
)) ||
1657 (hldev
->virtual_paths
[i
].vp_open
==
1658 VXGE_HW_VP_NOT_OPEN
))
1661 memcpy(hldev
->virtual_paths
[i
].hw_stats_sav
,
1662 hldev
->virtual_paths
[i
].hw_stats
,
1663 sizeof(struct vxge_hw_vpath_stats_hw_info
));
1665 status
= __vxge_hw_vpath_stats_get(
1666 &hldev
->virtual_paths
[i
],
1667 hldev
->virtual_paths
[i
].hw_stats
);
1670 memcpy(hw_stats
, &hldev
->stats
.hw_dev_info_stats
,
1671 sizeof(struct vxge_hw_device_stats_hw_info
));
1677 * vxge_hw_driver_stats_get - Get the device sw statistics.
1678 * Returns the vpath s/w stats for the device.
1680 enum vxge_hw_status
vxge_hw_driver_stats_get(
1681 struct __vxge_hw_device
*hldev
,
1682 struct vxge_hw_device_stats_sw_info
*sw_stats
)
1684 memcpy(sw_stats
, &hldev
->stats
.sw_dev_info_stats
,
1685 sizeof(struct vxge_hw_device_stats_sw_info
));
1691 * vxge_hw_mrpcim_stats_access - Access the statistics from the given location
1692 * and offset and perform an operation
1693 * Get the statistics from the given location and offset.
1696 vxge_hw_mrpcim_stats_access(struct __vxge_hw_device
*hldev
,
1697 u32 operation
, u32 location
, u32 offset
, u64
*stat
)
1700 enum vxge_hw_status status
= VXGE_HW_OK
;
1702 status
= __vxge_hw_device_is_privilaged(hldev
->host_type
,
1704 if (status
!= VXGE_HW_OK
)
1707 val64
= VXGE_HW_XMAC_STATS_SYS_CMD_OP(operation
) |
1708 VXGE_HW_XMAC_STATS_SYS_CMD_STROBE
|
1709 VXGE_HW_XMAC_STATS_SYS_CMD_LOC_SEL(location
) |
1710 VXGE_HW_XMAC_STATS_SYS_CMD_OFFSET_SEL(offset
);
1712 status
= __vxge_hw_pio_mem_write64(val64
,
1713 &hldev
->mrpcim_reg
->xmac_stats_sys_cmd
,
1714 VXGE_HW_XMAC_STATS_SYS_CMD_STROBE
,
1715 hldev
->config
.device_poll_millis
);
1717 if ((status
== VXGE_HW_OK
) && (operation
== VXGE_HW_STATS_OP_READ
))
1718 *stat
= readq(&hldev
->mrpcim_reg
->xmac_stats_sys_data
);
1726 * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port
1727 * Get the Statistics on aggregate port
1729 static enum vxge_hw_status
1730 vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device
*hldev
, u32 port
,
1731 struct vxge_hw_xmac_aggr_stats
*aggr_stats
)
1735 u32 offset
= VXGE_HW_STATS_AGGRn_OFFSET
;
1736 enum vxge_hw_status status
= VXGE_HW_OK
;
1738 val64
= (u64
*)aggr_stats
;
1740 status
= __vxge_hw_device_is_privilaged(hldev
->host_type
,
1742 if (status
!= VXGE_HW_OK
)
1745 for (i
= 0; i
< sizeof(struct vxge_hw_xmac_aggr_stats
) / 8; i
++) {
1746 status
= vxge_hw_mrpcim_stats_access(hldev
,
1747 VXGE_HW_STATS_OP_READ
,
1748 VXGE_HW_STATS_LOC_AGGR
,
1749 ((offset
+ (104 * port
)) >> 3), val64
);
1750 if (status
!= VXGE_HW_OK
)
1761 * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port
1762 * Get the Statistics on port
1764 static enum vxge_hw_status
1765 vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device
*hldev
, u32 port
,
1766 struct vxge_hw_xmac_port_stats
*port_stats
)
1769 enum vxge_hw_status status
= VXGE_HW_OK
;
1772 val64
= (u64
*) port_stats
;
1774 status
= __vxge_hw_device_is_privilaged(hldev
->host_type
,
1776 if (status
!= VXGE_HW_OK
)
1779 for (i
= 0; i
< sizeof(struct vxge_hw_xmac_port_stats
) / 8; i
++) {
1780 status
= vxge_hw_mrpcim_stats_access(hldev
,
1781 VXGE_HW_STATS_OP_READ
,
1782 VXGE_HW_STATS_LOC_AGGR
,
1783 ((offset
+ (608 * port
)) >> 3), val64
);
1784 if (status
!= VXGE_HW_OK
)
1796 * vxge_hw_device_xmac_stats_get - Get the XMAC Statistics
1797 * Get the XMAC Statistics
1800 vxge_hw_device_xmac_stats_get(struct __vxge_hw_device
*hldev
,
1801 struct vxge_hw_xmac_stats
*xmac_stats
)
1803 enum vxge_hw_status status
= VXGE_HW_OK
;
1806 status
= vxge_hw_device_xmac_aggr_stats_get(hldev
,
1807 0, &xmac_stats
->aggr_stats
[0]);
1808 if (status
!= VXGE_HW_OK
)
1811 status
= vxge_hw_device_xmac_aggr_stats_get(hldev
,
1812 1, &xmac_stats
->aggr_stats
[1]);
1813 if (status
!= VXGE_HW_OK
)
1816 for (i
= 0; i
<= VXGE_HW_MAC_MAX_MAC_PORT_ID
; i
++) {
1818 status
= vxge_hw_device_xmac_port_stats_get(hldev
,
1819 i
, &xmac_stats
->port_stats
[i
]);
1820 if (status
!= VXGE_HW_OK
)
1824 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
1826 if (!(hldev
->vpaths_deployed
& vxge_mBIT(i
)))
1829 status
= __vxge_hw_vpath_xmac_tx_stats_get(
1830 &hldev
->virtual_paths
[i
],
1831 &xmac_stats
->vpath_tx_stats
[i
]);
1832 if (status
!= VXGE_HW_OK
)
1835 status
= __vxge_hw_vpath_xmac_rx_stats_get(
1836 &hldev
->virtual_paths
[i
],
1837 &xmac_stats
->vpath_rx_stats
[i
]);
1838 if (status
!= VXGE_HW_OK
)
1846 * vxge_hw_device_debug_set - Set the debug module, level and timestamp
1847 * This routine is used to dynamically change the debug output
1849 void vxge_hw_device_debug_set(struct __vxge_hw_device
*hldev
,
1850 enum vxge_debug_level level
, u32 mask
)
1855 #if defined(VXGE_DEBUG_TRACE_MASK) || \
1856 defined(VXGE_DEBUG_ERR_MASK)
1857 hldev
->debug_module_mask
= mask
;
1858 hldev
->debug_level
= level
;
1861 #if defined(VXGE_DEBUG_ERR_MASK)
1862 hldev
->level_err
= level
& VXGE_ERR
;
1865 #if defined(VXGE_DEBUG_TRACE_MASK)
1866 hldev
->level_trace
= level
& VXGE_TRACE
;
1871 * vxge_hw_device_error_level_get - Get the error level
1872 * This routine returns the current error level set
1874 u32
vxge_hw_device_error_level_get(struct __vxge_hw_device
*hldev
)
1876 #if defined(VXGE_DEBUG_ERR_MASK)
1880 return hldev
->level_err
;
1887 * vxge_hw_device_trace_level_get - Get the trace level
1888 * This routine returns the current trace level set
1890 u32
vxge_hw_device_trace_level_get(struct __vxge_hw_device
*hldev
)
1892 #if defined(VXGE_DEBUG_TRACE_MASK)
1896 return hldev
->level_trace
;
1903 * vxge_hw_getpause_data -Pause frame frame generation and reception.
1904 * Returns the Pause frame generation and reception capability of the NIC.
1906 enum vxge_hw_status
vxge_hw_device_getpause_data(struct __vxge_hw_device
*hldev
,
1907 u32 port
, u32
*tx
, u32
*rx
)
1910 enum vxge_hw_status status
= VXGE_HW_OK
;
1912 if ((hldev
== NULL
) || (hldev
->magic
!= VXGE_HW_DEVICE_MAGIC
)) {
1913 status
= VXGE_HW_ERR_INVALID_DEVICE
;
1917 if (port
> VXGE_HW_MAC_MAX_MAC_PORT_ID
) {
1918 status
= VXGE_HW_ERR_INVALID_PORT
;
1922 if (!(hldev
->access_rights
& VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
)) {
1923 status
= VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
1927 val64
= readq(&hldev
->mrpcim_reg
->rxmac_pause_cfg_port
[port
]);
1928 if (val64
& VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN
)
1930 if (val64
& VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN
)
1937 * vxge_hw_device_setpause_data - set/reset pause frame generation.
1938 * It can be used to set or reset Pause frame generation or reception
1939 * support of the NIC.
1941 enum vxge_hw_status
vxge_hw_device_setpause_data(struct __vxge_hw_device
*hldev
,
1942 u32 port
, u32 tx
, u32 rx
)
1945 enum vxge_hw_status status
= VXGE_HW_OK
;
1947 if ((hldev
== NULL
) || (hldev
->magic
!= VXGE_HW_DEVICE_MAGIC
)) {
1948 status
= VXGE_HW_ERR_INVALID_DEVICE
;
1952 if (port
> VXGE_HW_MAC_MAX_MAC_PORT_ID
) {
1953 status
= VXGE_HW_ERR_INVALID_PORT
;
1957 status
= __vxge_hw_device_is_privilaged(hldev
->host_type
,
1959 if (status
!= VXGE_HW_OK
)
1962 val64
= readq(&hldev
->mrpcim_reg
->rxmac_pause_cfg_port
[port
]);
1964 val64
|= VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN
;
1966 val64
&= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN
;
1968 val64
|= VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN
;
1970 val64
&= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN
;
1972 writeq(val64
, &hldev
->mrpcim_reg
->rxmac_pause_cfg_port
[port
]);
1977 u16
vxge_hw_device_link_width_get(struct __vxge_hw_device
*hldev
)
1979 struct pci_dev
*dev
= hldev
->pdev
;
1982 pcie_capability_read_word(dev
, PCI_EXP_LNKSTA
, &lnk
);
1983 return (lnk
& VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH
) >> 4;
1987 * __vxge_hw_ring_block_memblock_idx - Return the memblock index
1988 * This function returns the index of memory block
1991 __vxge_hw_ring_block_memblock_idx(u8
*block
)
1993 return (u32
)*((u64
*)(block
+ VXGE_HW_RING_MEMBLOCK_IDX_OFFSET
));
1997 * __vxge_hw_ring_block_memblock_idx_set - Sets the memblock index
1998 * This function sets index to a memory block
2001 __vxge_hw_ring_block_memblock_idx_set(u8
*block
, u32 memblock_idx
)
2003 *((u64
*)(block
+ VXGE_HW_RING_MEMBLOCK_IDX_OFFSET
)) = memblock_idx
;
2007 * __vxge_hw_ring_block_next_pointer_set - Sets the next block pointer
2009 * Sets the next block pointer in RxD block
2012 __vxge_hw_ring_block_next_pointer_set(u8
*block
, dma_addr_t dma_next
)
2014 *((u64
*)(block
+ VXGE_HW_RING_NEXT_BLOCK_POINTER_OFFSET
)) = dma_next
;
2018 * __vxge_hw_ring_first_block_address_get - Returns the dma address of the
2020 * Returns the dma address of the first RxD block
2022 static u64
__vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring
*ring
)
2024 struct vxge_hw_mempool_dma
*dma_object
;
2026 dma_object
= ring
->mempool
->memblocks_dma_arr
;
2027 vxge_assert(dma_object
!= NULL
);
2029 return dma_object
->addr
;
2033 * __vxge_hw_ring_item_dma_addr - Return the dma address of an item
2034 * This function returns the dma address of a given item
2036 static dma_addr_t
__vxge_hw_ring_item_dma_addr(struct vxge_hw_mempool
*mempoolh
,
2041 struct vxge_hw_mempool_dma
*memblock_dma_object
;
2042 ptrdiff_t dma_item_offset
;
2044 /* get owner memblock index */
2045 memblock_idx
= __vxge_hw_ring_block_memblock_idx(item
);
2047 /* get owner memblock by memblock index */
2048 memblock
= mempoolh
->memblocks_arr
[memblock_idx
];
2050 /* get memblock DMA object by memblock index */
2051 memblock_dma_object
= mempoolh
->memblocks_dma_arr
+ memblock_idx
;
2053 /* calculate offset in the memblock of this item */
2054 dma_item_offset
= (u8
*)item
- (u8
*)memblock
;
2056 return memblock_dma_object
->addr
+ dma_item_offset
;
2060 * __vxge_hw_ring_rxdblock_link - Link the RxD blocks
2061 * This function returns the dma address of a given item
2063 static void __vxge_hw_ring_rxdblock_link(struct vxge_hw_mempool
*mempoolh
,
2064 struct __vxge_hw_ring
*ring
, u32 from
,
2067 u8
*to_item
, *from_item
;
2070 /* get "from" RxD block */
2071 from_item
= mempoolh
->items_arr
[from
];
2072 vxge_assert(from_item
);
2074 /* get "to" RxD block */
2075 to_item
= mempoolh
->items_arr
[to
];
2076 vxge_assert(to_item
);
2078 /* return address of the beginning of previous RxD block */
2079 to_dma
= __vxge_hw_ring_item_dma_addr(mempoolh
, to_item
);
2081 /* set next pointer for this RxD block to point on
2082 * previous item's DMA start address */
2083 __vxge_hw_ring_block_next_pointer_set(from_item
, to_dma
);
2087 * __vxge_hw_ring_mempool_item_alloc - Allocate List blocks for RxD
2089 * This function is callback passed to __vxge_hw_mempool_create to create memory
2090 * pool for RxD block
2093 __vxge_hw_ring_mempool_item_alloc(struct vxge_hw_mempool
*mempoolh
,
2095 struct vxge_hw_mempool_dma
*dma_object
,
2096 u32 index
, u32 is_last
)
2099 void *item
= mempoolh
->items_arr
[index
];
2100 struct __vxge_hw_ring
*ring
=
2101 (struct __vxge_hw_ring
*)mempoolh
->userdata
;
2103 /* format rxds array */
2104 for (i
= 0; i
< ring
->rxds_per_block
; i
++) {
2105 void *rxdblock_priv
;
2107 struct vxge_hw_ring_rxd_1
*rxdp
;
2109 u32 reserve_index
= ring
->channel
.reserve_ptr
-
2110 (index
* ring
->rxds_per_block
+ i
+ 1);
2111 u32 memblock_item_idx
;
2113 ring
->channel
.reserve_arr
[reserve_index
] = ((u8
*)item
) +
2116 /* Note: memblock_item_idx is index of the item within
2117 * the memblock. For instance, in case of three RxD-blocks
2118 * per memblock this value can be 0, 1 or 2. */
2119 rxdblock_priv
= __vxge_hw_mempool_item_priv(mempoolh
,
2120 memblock_index
, item
,
2121 &memblock_item_idx
);
2123 rxdp
= ring
->channel
.reserve_arr
[reserve_index
];
2125 uld_priv
= ((u8
*)rxdblock_priv
+ ring
->rxd_priv_size
* i
);
2127 /* pre-format Host_Control */
2128 rxdp
->host_control
= (u64
)(size_t)uld_priv
;
2131 __vxge_hw_ring_block_memblock_idx_set(item
, memblock_index
);
2134 /* link last one with first one */
2135 __vxge_hw_ring_rxdblock_link(mempoolh
, ring
, index
, 0);
2139 /* link this RxD block with previous one */
2140 __vxge_hw_ring_rxdblock_link(mempoolh
, ring
, index
- 1, index
);
2145 * __vxge_hw_ring_replenish - Initial replenish of RxDs
2146 * This function replenishes the RxDs from reserve array to work array
2148 static enum vxge_hw_status
2149 vxge_hw_ring_replenish(struct __vxge_hw_ring
*ring
)
2152 struct __vxge_hw_channel
*channel
;
2153 enum vxge_hw_status status
= VXGE_HW_OK
;
2155 channel
= &ring
->channel
;
2157 while (vxge_hw_channel_dtr_count(channel
) > 0) {
2159 status
= vxge_hw_ring_rxd_reserve(ring
, &rxd
);
2161 vxge_assert(status
== VXGE_HW_OK
);
2163 if (ring
->rxd_init
) {
2164 status
= ring
->rxd_init(rxd
, channel
->userdata
);
2165 if (status
!= VXGE_HW_OK
) {
2166 vxge_hw_ring_rxd_free(ring
, rxd
);
2171 vxge_hw_ring_rxd_post(ring
, rxd
);
2173 status
= VXGE_HW_OK
;
2179 * __vxge_hw_channel_allocate - Allocate memory for channel
2180 * This function allocates required memory for the channel and various arrays
2183 static struct __vxge_hw_channel
*
2184 __vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle
*vph
,
2185 enum __vxge_hw_channel_type type
,
2186 u32 length
, u32 per_dtr_space
,
2189 struct __vxge_hw_channel
*channel
;
2190 struct __vxge_hw_device
*hldev
;
2194 hldev
= vph
->vpath
->hldev
;
2195 vp_id
= vph
->vpath
->vp_id
;
2198 case VXGE_HW_CHANNEL_TYPE_FIFO
:
2199 size
= sizeof(struct __vxge_hw_fifo
);
2201 case VXGE_HW_CHANNEL_TYPE_RING
:
2202 size
= sizeof(struct __vxge_hw_ring
);
2208 channel
= kzalloc(size
, GFP_KERNEL
);
2209 if (channel
== NULL
)
2211 INIT_LIST_HEAD(&channel
->item
);
2213 channel
->common_reg
= hldev
->common_reg
;
2214 channel
->first_vp_id
= hldev
->first_vp_id
;
2215 channel
->type
= type
;
2216 channel
->devh
= hldev
;
2218 channel
->userdata
= userdata
;
2219 channel
->per_dtr_space
= per_dtr_space
;
2220 channel
->length
= length
;
2221 channel
->vp_id
= vp_id
;
2223 channel
->work_arr
= kzalloc(sizeof(void *)*length
, GFP_KERNEL
);
2224 if (channel
->work_arr
== NULL
)
2227 channel
->free_arr
= kzalloc(sizeof(void *)*length
, GFP_KERNEL
);
2228 if (channel
->free_arr
== NULL
)
2230 channel
->free_ptr
= length
;
2232 channel
->reserve_arr
= kzalloc(sizeof(void *)*length
, GFP_KERNEL
);
2233 if (channel
->reserve_arr
== NULL
)
2235 channel
->reserve_ptr
= length
;
2236 channel
->reserve_top
= 0;
2238 channel
->orig_arr
= kzalloc(sizeof(void *)*length
, GFP_KERNEL
);
2239 if (channel
->orig_arr
== NULL
)
2244 __vxge_hw_channel_free(channel
);
2251 * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async
2252 * Adds a block to block pool
2254 static void vxge_hw_blockpool_block_add(struct __vxge_hw_device
*devh
,
2257 struct pci_dev
*dma_h
,
2258 struct pci_dev
*acc_handle
)
2260 struct __vxge_hw_blockpool
*blockpool
;
2261 struct __vxge_hw_blockpool_entry
*entry
= NULL
;
2262 dma_addr_t dma_addr
;
2263 enum vxge_hw_status status
= VXGE_HW_OK
;
2266 blockpool
= &devh
->block_pool
;
2268 if (block_addr
== NULL
) {
2269 blockpool
->req_out
--;
2270 status
= VXGE_HW_FAIL
;
2274 dma_addr
= pci_map_single(devh
->pdev
, block_addr
, length
,
2275 PCI_DMA_BIDIRECTIONAL
);
2277 if (unlikely(pci_dma_mapping_error(devh
->pdev
, dma_addr
))) {
2278 vxge_os_dma_free(devh
->pdev
, block_addr
, &acc_handle
);
2279 blockpool
->req_out
--;
2280 status
= VXGE_HW_FAIL
;
2284 if (!list_empty(&blockpool
->free_entry_list
))
2285 entry
= (struct __vxge_hw_blockpool_entry
*)
2286 list_first_entry(&blockpool
->free_entry_list
,
2287 struct __vxge_hw_blockpool_entry
,
2291 entry
= vmalloc(sizeof(struct __vxge_hw_blockpool_entry
));
2293 list_del(&entry
->item
);
2295 if (entry
!= NULL
) {
2296 entry
->length
= length
;
2297 entry
->memblock
= block_addr
;
2298 entry
->dma_addr
= dma_addr
;
2299 entry
->acc_handle
= acc_handle
;
2300 entry
->dma_handle
= dma_h
;
2301 list_add(&entry
->item
, &blockpool
->free_block_list
);
2302 blockpool
->pool_size
++;
2303 status
= VXGE_HW_OK
;
2305 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2307 blockpool
->req_out
--;
2309 req_out
= blockpool
->req_out
;
2315 vxge_os_dma_malloc_async(struct pci_dev
*pdev
, void *devh
, unsigned long size
)
2321 flags
= GFP_ATOMIC
| GFP_DMA
;
2323 flags
= GFP_KERNEL
| GFP_DMA
;
2325 vaddr
= kmalloc((size
), flags
);
2327 vxge_hw_blockpool_block_add(devh
, vaddr
, size
, pdev
, pdev
);
2331 * __vxge_hw_blockpool_blocks_add - Request additional blocks
2334 void __vxge_hw_blockpool_blocks_add(struct __vxge_hw_blockpool
*blockpool
)
2338 if ((blockpool
->pool_size
+ blockpool
->req_out
) <
2339 VXGE_HW_MIN_DMA_BLOCK_POOL_SIZE
) {
2340 nreq
= VXGE_HW_INCR_DMA_BLOCK_POOL_SIZE
;
2341 blockpool
->req_out
+= nreq
;
2344 for (i
= 0; i
< nreq
; i
++)
2345 vxge_os_dma_malloc_async(
2346 (blockpool
->hldev
)->pdev
,
2347 blockpool
->hldev
, VXGE_HW_BLOCK_SIZE
);
2351 * __vxge_hw_blockpool_malloc - Allocate a memory block from pool
2352 * Allocates a block of memory of given size, either from block pool
2353 * or by calling vxge_os_dma_malloc()
2355 static void *__vxge_hw_blockpool_malloc(struct __vxge_hw_device
*devh
, u32 size
,
2356 struct vxge_hw_mempool_dma
*dma_object
)
2358 struct __vxge_hw_blockpool_entry
*entry
= NULL
;
2359 struct __vxge_hw_blockpool
*blockpool
;
2360 void *memblock
= NULL
;
2361 enum vxge_hw_status status
= VXGE_HW_OK
;
2363 blockpool
= &devh
->block_pool
;
2365 if (size
!= blockpool
->block_size
) {
2367 memblock
= vxge_os_dma_malloc(devh
->pdev
, size
,
2368 &dma_object
->handle
,
2369 &dma_object
->acc_handle
);
2371 if (memblock
== NULL
) {
2372 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2376 dma_object
->addr
= pci_map_single(devh
->pdev
, memblock
, size
,
2377 PCI_DMA_BIDIRECTIONAL
);
2379 if (unlikely(pci_dma_mapping_error(devh
->pdev
,
2380 dma_object
->addr
))) {
2381 vxge_os_dma_free(devh
->pdev
, memblock
,
2382 &dma_object
->acc_handle
);
2383 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2389 if (!list_empty(&blockpool
->free_block_list
))
2390 entry
= (struct __vxge_hw_blockpool_entry
*)
2391 list_first_entry(&blockpool
->free_block_list
,
2392 struct __vxge_hw_blockpool_entry
,
2395 if (entry
!= NULL
) {
2396 list_del(&entry
->item
);
2397 dma_object
->addr
= entry
->dma_addr
;
2398 dma_object
->handle
= entry
->dma_handle
;
2399 dma_object
->acc_handle
= entry
->acc_handle
;
2400 memblock
= entry
->memblock
;
2402 list_add(&entry
->item
,
2403 &blockpool
->free_entry_list
);
2404 blockpool
->pool_size
--;
2407 if (memblock
!= NULL
)
2408 __vxge_hw_blockpool_blocks_add(blockpool
);
2415 * __vxge_hw_blockpool_blocks_remove - Free additional blocks
2418 __vxge_hw_blockpool_blocks_remove(struct __vxge_hw_blockpool
*blockpool
)
2420 struct list_head
*p
, *n
;
2422 list_for_each_safe(p
, n
, &blockpool
->free_block_list
) {
2424 if (blockpool
->pool_size
< blockpool
->pool_max
)
2428 (blockpool
->hldev
)->pdev
,
2429 ((struct __vxge_hw_blockpool_entry
*)p
)->dma_addr
,
2430 ((struct __vxge_hw_blockpool_entry
*)p
)->length
,
2431 PCI_DMA_BIDIRECTIONAL
);
2434 (blockpool
->hldev
)->pdev
,
2435 ((struct __vxge_hw_blockpool_entry
*)p
)->memblock
,
2436 &((struct __vxge_hw_blockpool_entry
*)p
)->acc_handle
);
2438 list_del(&((struct __vxge_hw_blockpool_entry
*)p
)->item
);
2440 list_add(p
, &blockpool
->free_entry_list
);
2442 blockpool
->pool_size
--;
2448 * __vxge_hw_blockpool_free - Frees the memory allcoated with
2449 * __vxge_hw_blockpool_malloc
2451 static void __vxge_hw_blockpool_free(struct __vxge_hw_device
*devh
,
2452 void *memblock
, u32 size
,
2453 struct vxge_hw_mempool_dma
*dma_object
)
2455 struct __vxge_hw_blockpool_entry
*entry
= NULL
;
2456 struct __vxge_hw_blockpool
*blockpool
;
2457 enum vxge_hw_status status
= VXGE_HW_OK
;
2459 blockpool
= &devh
->block_pool
;
2461 if (size
!= blockpool
->block_size
) {
2462 pci_unmap_single(devh
->pdev
, dma_object
->addr
, size
,
2463 PCI_DMA_BIDIRECTIONAL
);
2464 vxge_os_dma_free(devh
->pdev
, memblock
, &dma_object
->acc_handle
);
2467 if (!list_empty(&blockpool
->free_entry_list
))
2468 entry
= (struct __vxge_hw_blockpool_entry
*)
2469 list_first_entry(&blockpool
->free_entry_list
,
2470 struct __vxge_hw_blockpool_entry
,
2474 entry
= vmalloc(sizeof(
2475 struct __vxge_hw_blockpool_entry
));
2477 list_del(&entry
->item
);
2479 if (entry
!= NULL
) {
2480 entry
->length
= size
;
2481 entry
->memblock
= memblock
;
2482 entry
->dma_addr
= dma_object
->addr
;
2483 entry
->acc_handle
= dma_object
->acc_handle
;
2484 entry
->dma_handle
= dma_object
->handle
;
2485 list_add(&entry
->item
,
2486 &blockpool
->free_block_list
);
2487 blockpool
->pool_size
++;
2488 status
= VXGE_HW_OK
;
2490 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2492 if (status
== VXGE_HW_OK
)
2493 __vxge_hw_blockpool_blocks_remove(blockpool
);
2498 * vxge_hw_mempool_destroy
2500 static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool
*mempool
)
2503 struct __vxge_hw_device
*devh
= mempool
->devh
;
2505 for (i
= 0; i
< mempool
->memblocks_allocated
; i
++) {
2506 struct vxge_hw_mempool_dma
*dma_object
;
2508 vxge_assert(mempool
->memblocks_arr
[i
]);
2509 vxge_assert(mempool
->memblocks_dma_arr
+ i
);
2511 dma_object
= mempool
->memblocks_dma_arr
+ i
;
2513 for (j
= 0; j
< mempool
->items_per_memblock
; j
++) {
2514 u32 index
= i
* mempool
->items_per_memblock
+ j
;
2516 /* to skip last partially filled(if any) memblock */
2517 if (index
>= mempool
->items_current
)
2521 vfree(mempool
->memblocks_priv_arr
[i
]);
2523 __vxge_hw_blockpool_free(devh
, mempool
->memblocks_arr
[i
],
2524 mempool
->memblock_size
, dma_object
);
2527 vfree(mempool
->items_arr
);
2528 vfree(mempool
->memblocks_dma_arr
);
2529 vfree(mempool
->memblocks_priv_arr
);
2530 vfree(mempool
->memblocks_arr
);
2535 * __vxge_hw_mempool_grow
2536 * Will resize mempool up to %num_allocate value.
2538 static enum vxge_hw_status
2539 __vxge_hw_mempool_grow(struct vxge_hw_mempool
*mempool
, u32 num_allocate
,
2542 u32 i
, first_time
= mempool
->memblocks_allocated
== 0 ? 1 : 0;
2543 u32 n_items
= mempool
->items_per_memblock
;
2544 u32 start_block_idx
= mempool
->memblocks_allocated
;
2545 u32 end_block_idx
= mempool
->memblocks_allocated
+ num_allocate
;
2546 enum vxge_hw_status status
= VXGE_HW_OK
;
2550 if (end_block_idx
> mempool
->memblocks_max
) {
2551 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2555 for (i
= start_block_idx
; i
< end_block_idx
; i
++) {
2557 u32 is_last
= ((end_block_idx
- 1) == i
);
2558 struct vxge_hw_mempool_dma
*dma_object
=
2559 mempool
->memblocks_dma_arr
+ i
;
2562 /* allocate memblock's private part. Each DMA memblock
2563 * has a space allocated for item's private usage upon
2564 * mempool's user request. Each time mempool grows, it will
2565 * allocate new memblock and its private part at once.
2566 * This helps to minimize memory usage a lot. */
2567 mempool
->memblocks_priv_arr
[i
] =
2568 vzalloc(mempool
->items_priv_size
* n_items
);
2569 if (mempool
->memblocks_priv_arr
[i
] == NULL
) {
2570 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2574 /* allocate DMA-capable memblock */
2575 mempool
->memblocks_arr
[i
] =
2576 __vxge_hw_blockpool_malloc(mempool
->devh
,
2577 mempool
->memblock_size
, dma_object
);
2578 if (mempool
->memblocks_arr
[i
] == NULL
) {
2579 vfree(mempool
->memblocks_priv_arr
[i
]);
2580 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2585 mempool
->memblocks_allocated
++;
2587 memset(mempool
->memblocks_arr
[i
], 0, mempool
->memblock_size
);
2589 the_memblock
= mempool
->memblocks_arr
[i
];
2591 /* fill the items hash array */
2592 for (j
= 0; j
< n_items
; j
++) {
2593 u32 index
= i
* n_items
+ j
;
2595 if (first_time
&& index
>= mempool
->items_initial
)
2598 mempool
->items_arr
[index
] =
2599 ((char *)the_memblock
+ j
*mempool
->item_size
);
2601 /* let caller to do more job on each item */
2602 if (mempool
->item_func_alloc
!= NULL
)
2603 mempool
->item_func_alloc(mempool
, i
,
2604 dma_object
, index
, is_last
);
2606 mempool
->items_current
= index
+ 1;
2609 if (first_time
&& mempool
->items_current
==
2610 mempool
->items_initial
)
2618 * vxge_hw_mempool_create
2619 * This function will create memory pool object. Pool may grow but will
2620 * never shrink. Pool consists of number of dynamically allocated blocks
2621 * with size enough to hold %items_initial number of items. Memory is
2622 * DMA-able but client must map/unmap before interoperating with the device.
2624 static struct vxge_hw_mempool
*
2625 __vxge_hw_mempool_create(struct __vxge_hw_device
*devh
,
2628 u32 items_priv_size
,
2631 const struct vxge_hw_mempool_cbs
*mp_callback
,
2634 enum vxge_hw_status status
= VXGE_HW_OK
;
2635 u32 memblocks_to_allocate
;
2636 struct vxge_hw_mempool
*mempool
= NULL
;
2639 if (memblock_size
< item_size
) {
2640 status
= VXGE_HW_FAIL
;
2644 mempool
= vzalloc(sizeof(struct vxge_hw_mempool
));
2645 if (mempool
== NULL
) {
2646 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2650 mempool
->devh
= devh
;
2651 mempool
->memblock_size
= memblock_size
;
2652 mempool
->items_max
= items_max
;
2653 mempool
->items_initial
= items_initial
;
2654 mempool
->item_size
= item_size
;
2655 mempool
->items_priv_size
= items_priv_size
;
2656 mempool
->item_func_alloc
= mp_callback
->item_func_alloc
;
2657 mempool
->userdata
= userdata
;
2659 mempool
->memblocks_allocated
= 0;
2661 mempool
->items_per_memblock
= memblock_size
/ item_size
;
2663 mempool
->memblocks_max
= (items_max
+ mempool
->items_per_memblock
- 1) /
2664 mempool
->items_per_memblock
;
2666 /* allocate array of memblocks */
2667 mempool
->memblocks_arr
=
2668 vzalloc(sizeof(void *) * mempool
->memblocks_max
);
2669 if (mempool
->memblocks_arr
== NULL
) {
2670 __vxge_hw_mempool_destroy(mempool
);
2671 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2676 /* allocate array of private parts of items per memblocks */
2677 mempool
->memblocks_priv_arr
=
2678 vzalloc(sizeof(void *) * mempool
->memblocks_max
);
2679 if (mempool
->memblocks_priv_arr
== NULL
) {
2680 __vxge_hw_mempool_destroy(mempool
);
2681 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2686 /* allocate array of memblocks DMA objects */
2687 mempool
->memblocks_dma_arr
=
2688 vzalloc(sizeof(struct vxge_hw_mempool_dma
) *
2689 mempool
->memblocks_max
);
2690 if (mempool
->memblocks_dma_arr
== NULL
) {
2691 __vxge_hw_mempool_destroy(mempool
);
2692 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2697 /* allocate hash array of items */
2698 mempool
->items_arr
= vzalloc(sizeof(void *) * mempool
->items_max
);
2699 if (mempool
->items_arr
== NULL
) {
2700 __vxge_hw_mempool_destroy(mempool
);
2701 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2706 /* calculate initial number of memblocks */
2707 memblocks_to_allocate
= (mempool
->items_initial
+
2708 mempool
->items_per_memblock
- 1) /
2709 mempool
->items_per_memblock
;
2711 /* pre-allocate the mempool */
2712 status
= __vxge_hw_mempool_grow(mempool
, memblocks_to_allocate
,
2714 if (status
!= VXGE_HW_OK
) {
2715 __vxge_hw_mempool_destroy(mempool
);
2716 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2726 * __vxge_hw_ring_abort - Returns the RxD
2727 * This function terminates the RxDs of ring
2729 static enum vxge_hw_status
__vxge_hw_ring_abort(struct __vxge_hw_ring
*ring
)
2732 struct __vxge_hw_channel
*channel
;
2734 channel
= &ring
->channel
;
2737 vxge_hw_channel_dtr_try_complete(channel
, &rxdh
);
2742 vxge_hw_channel_dtr_complete(channel
);
2745 ring
->rxd_term(rxdh
, VXGE_HW_RXD_STATE_POSTED
,
2748 vxge_hw_channel_dtr_free(channel
, rxdh
);
2755 * __vxge_hw_ring_reset - Resets the ring
2756 * This function resets the ring during vpath reset operation
2758 static enum vxge_hw_status
__vxge_hw_ring_reset(struct __vxge_hw_ring
*ring
)
2760 enum vxge_hw_status status
= VXGE_HW_OK
;
2761 struct __vxge_hw_channel
*channel
;
2763 channel
= &ring
->channel
;
2765 __vxge_hw_ring_abort(ring
);
2767 status
= __vxge_hw_channel_reset(channel
);
2769 if (status
!= VXGE_HW_OK
)
2772 if (ring
->rxd_init
) {
2773 status
= vxge_hw_ring_replenish(ring
);
2774 if (status
!= VXGE_HW_OK
)
2782 * __vxge_hw_ring_delete - Removes the ring
2783 * This function freeup the memory pool and removes the ring
2785 static enum vxge_hw_status
2786 __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle
*vp
)
2788 struct __vxge_hw_ring
*ring
= vp
->vpath
->ringh
;
2790 __vxge_hw_ring_abort(ring
);
2793 __vxge_hw_mempool_destroy(ring
->mempool
);
2795 vp
->vpath
->ringh
= NULL
;
2796 __vxge_hw_channel_free(&ring
->channel
);
2802 * __vxge_hw_ring_create - Create a Ring
2803 * This function creates Ring and initializes it.
2805 static enum vxge_hw_status
2806 __vxge_hw_ring_create(struct __vxge_hw_vpath_handle
*vp
,
2807 struct vxge_hw_ring_attr
*attr
)
2809 enum vxge_hw_status status
= VXGE_HW_OK
;
2810 struct __vxge_hw_ring
*ring
;
2812 struct vxge_hw_ring_config
*config
;
2813 struct __vxge_hw_device
*hldev
;
2815 static const struct vxge_hw_mempool_cbs ring_mp_callback
= {
2816 .item_func_alloc
= __vxge_hw_ring_mempool_item_alloc
,
2819 if ((vp
== NULL
) || (attr
== NULL
)) {
2820 status
= VXGE_HW_FAIL
;
2824 hldev
= vp
->vpath
->hldev
;
2825 vp_id
= vp
->vpath
->vp_id
;
2827 config
= &hldev
->config
.vp_config
[vp_id
].ring
;
2829 ring_length
= config
->ring_blocks
*
2830 vxge_hw_ring_rxds_per_block_get(config
->buffer_mode
);
2832 ring
= (struct __vxge_hw_ring
*)__vxge_hw_channel_allocate(vp
,
2833 VXGE_HW_CHANNEL_TYPE_RING
,
2835 attr
->per_rxd_space
,
2838 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
2842 vp
->vpath
->ringh
= ring
;
2843 ring
->vp_id
= vp_id
;
2844 ring
->vp_reg
= vp
->vpath
->vp_reg
;
2845 ring
->common_reg
= hldev
->common_reg
;
2846 ring
->stats
= &vp
->vpath
->sw_stats
->ring_stats
;
2847 ring
->config
= config
;
2848 ring
->callback
= attr
->callback
;
2849 ring
->rxd_init
= attr
->rxd_init
;
2850 ring
->rxd_term
= attr
->rxd_term
;
2851 ring
->buffer_mode
= config
->buffer_mode
;
2852 ring
->tim_rti_cfg1_saved
= vp
->vpath
->tim_rti_cfg1_saved
;
2853 ring
->tim_rti_cfg3_saved
= vp
->vpath
->tim_rti_cfg3_saved
;
2854 ring
->rxds_limit
= config
->rxds_limit
;
2856 ring
->rxd_size
= vxge_hw_ring_rxd_size_get(config
->buffer_mode
);
2857 ring
->rxd_priv_size
=
2858 sizeof(struct __vxge_hw_ring_rxd_priv
) + attr
->per_rxd_space
;
2859 ring
->per_rxd_space
= attr
->per_rxd_space
;
2861 ring
->rxd_priv_size
=
2862 ((ring
->rxd_priv_size
+ VXGE_CACHE_LINE_SIZE
- 1) /
2863 VXGE_CACHE_LINE_SIZE
) * VXGE_CACHE_LINE_SIZE
;
2865 /* how many RxDs can fit into one block. Depends on configured
2867 ring
->rxds_per_block
=
2868 vxge_hw_ring_rxds_per_block_get(config
->buffer_mode
);
2870 /* calculate actual RxD block private size */
2871 ring
->rxdblock_priv_size
= ring
->rxd_priv_size
* ring
->rxds_per_block
;
2872 ring
->mempool
= __vxge_hw_mempool_create(hldev
,
2875 ring
->rxdblock_priv_size
,
2876 ring
->config
->ring_blocks
,
2877 ring
->config
->ring_blocks
,
2880 if (ring
->mempool
== NULL
) {
2881 __vxge_hw_ring_delete(vp
);
2882 return VXGE_HW_ERR_OUT_OF_MEMORY
;
2885 status
= __vxge_hw_channel_initialize(&ring
->channel
);
2886 if (status
!= VXGE_HW_OK
) {
2887 __vxge_hw_ring_delete(vp
);
2892 * Specifying rxd_init callback means two things:
2893 * 1) rxds need to be initialized by driver at channel-open time;
2894 * 2) rxds need to be posted at channel-open time
2895 * (that's what the initial_replenish() below does)
2896 * Currently we don't have a case when the 1) is done without the 2).
2898 if (ring
->rxd_init
) {
2899 status
= vxge_hw_ring_replenish(ring
);
2900 if (status
!= VXGE_HW_OK
) {
2901 __vxge_hw_ring_delete(vp
);
2906 /* initial replenish will increment the counter in its post() routine,
2907 * we have to reset it */
2908 ring
->stats
->common_stats
.usage_cnt
= 0;
2914 * vxge_hw_device_config_default_get - Initialize device config with defaults.
2915 * Initialize Titan device config with default values.
2918 vxge_hw_device_config_default_get(struct vxge_hw_device_config
*device_config
)
2922 device_config
->dma_blockpool_initial
=
2923 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
2924 device_config
->dma_blockpool_max
= VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
2925 device_config
->intr_mode
= VXGE_HW_INTR_MODE_DEF
;
2926 device_config
->rth_en
= VXGE_HW_RTH_DEFAULT
;
2927 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_DEFAULT
;
2928 device_config
->device_poll_millis
= VXGE_HW_DEF_DEVICE_POLL_MILLIS
;
2929 device_config
->rts_mac_en
= VXGE_HW_RTS_MAC_DEFAULT
;
2931 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
2932 device_config
->vp_config
[i
].vp_id
= i
;
2934 device_config
->vp_config
[i
].min_bandwidth
=
2935 VXGE_HW_VPATH_BANDWIDTH_DEFAULT
;
2937 device_config
->vp_config
[i
].ring
.enable
= VXGE_HW_RING_DEFAULT
;
2939 device_config
->vp_config
[i
].ring
.ring_blocks
=
2940 VXGE_HW_DEF_RING_BLOCKS
;
2942 device_config
->vp_config
[i
].ring
.buffer_mode
=
2943 VXGE_HW_RING_RXD_BUFFER_MODE_DEFAULT
;
2945 device_config
->vp_config
[i
].ring
.scatter_mode
=
2946 VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT
;
2948 device_config
->vp_config
[i
].ring
.rxds_limit
=
2949 VXGE_HW_DEF_RING_RXDS_LIMIT
;
2951 device_config
->vp_config
[i
].fifo
.enable
= VXGE_HW_FIFO_ENABLE
;
2953 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
2954 VXGE_HW_MIN_FIFO_BLOCKS
;
2956 device_config
->vp_config
[i
].fifo
.max_frags
=
2957 VXGE_HW_MAX_FIFO_FRAGS
;
2959 device_config
->vp_config
[i
].fifo
.memblock_size
=
2960 VXGE_HW_DEF_FIFO_MEMBLOCK_SIZE
;
2962 device_config
->vp_config
[i
].fifo
.alignment_size
=
2963 VXGE_HW_DEF_FIFO_ALIGNMENT_SIZE
;
2965 device_config
->vp_config
[i
].fifo
.intr
=
2966 VXGE_HW_FIFO_QUEUE_INTR_DEFAULT
;
2968 device_config
->vp_config
[i
].fifo
.no_snoop_bits
=
2969 VXGE_HW_FIFO_NO_SNOOP_DEFAULT
;
2970 device_config
->vp_config
[i
].tti
.intr_enable
=
2971 VXGE_HW_TIM_INTR_DEFAULT
;
2973 device_config
->vp_config
[i
].tti
.btimer_val
=
2974 VXGE_HW_USE_FLASH_DEFAULT
;
2976 device_config
->vp_config
[i
].tti
.timer_ac_en
=
2977 VXGE_HW_USE_FLASH_DEFAULT
;
2979 device_config
->vp_config
[i
].tti
.timer_ci_en
=
2980 VXGE_HW_USE_FLASH_DEFAULT
;
2982 device_config
->vp_config
[i
].tti
.timer_ri_en
=
2983 VXGE_HW_USE_FLASH_DEFAULT
;
2985 device_config
->vp_config
[i
].tti
.rtimer_val
=
2986 VXGE_HW_USE_FLASH_DEFAULT
;
2988 device_config
->vp_config
[i
].tti
.util_sel
=
2989 VXGE_HW_USE_FLASH_DEFAULT
;
2991 device_config
->vp_config
[i
].tti
.ltimer_val
=
2992 VXGE_HW_USE_FLASH_DEFAULT
;
2994 device_config
->vp_config
[i
].tti
.urange_a
=
2995 VXGE_HW_USE_FLASH_DEFAULT
;
2997 device_config
->vp_config
[i
].tti
.uec_a
=
2998 VXGE_HW_USE_FLASH_DEFAULT
;
3000 device_config
->vp_config
[i
].tti
.urange_b
=
3001 VXGE_HW_USE_FLASH_DEFAULT
;
3003 device_config
->vp_config
[i
].tti
.uec_b
=
3004 VXGE_HW_USE_FLASH_DEFAULT
;
3006 device_config
->vp_config
[i
].tti
.urange_c
=
3007 VXGE_HW_USE_FLASH_DEFAULT
;
3009 device_config
->vp_config
[i
].tti
.uec_c
=
3010 VXGE_HW_USE_FLASH_DEFAULT
;
3012 device_config
->vp_config
[i
].tti
.uec_d
=
3013 VXGE_HW_USE_FLASH_DEFAULT
;
3015 device_config
->vp_config
[i
].rti
.intr_enable
=
3016 VXGE_HW_TIM_INTR_DEFAULT
;
3018 device_config
->vp_config
[i
].rti
.btimer_val
=
3019 VXGE_HW_USE_FLASH_DEFAULT
;
3021 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3022 VXGE_HW_USE_FLASH_DEFAULT
;
3024 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3025 VXGE_HW_USE_FLASH_DEFAULT
;
3027 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3028 VXGE_HW_USE_FLASH_DEFAULT
;
3030 device_config
->vp_config
[i
].rti
.rtimer_val
=
3031 VXGE_HW_USE_FLASH_DEFAULT
;
3033 device_config
->vp_config
[i
].rti
.util_sel
=
3034 VXGE_HW_USE_FLASH_DEFAULT
;
3036 device_config
->vp_config
[i
].rti
.ltimer_val
=
3037 VXGE_HW_USE_FLASH_DEFAULT
;
3039 device_config
->vp_config
[i
].rti
.urange_a
=
3040 VXGE_HW_USE_FLASH_DEFAULT
;
3042 device_config
->vp_config
[i
].rti
.uec_a
=
3043 VXGE_HW_USE_FLASH_DEFAULT
;
3045 device_config
->vp_config
[i
].rti
.urange_b
=
3046 VXGE_HW_USE_FLASH_DEFAULT
;
3048 device_config
->vp_config
[i
].rti
.uec_b
=
3049 VXGE_HW_USE_FLASH_DEFAULT
;
3051 device_config
->vp_config
[i
].rti
.urange_c
=
3052 VXGE_HW_USE_FLASH_DEFAULT
;
3054 device_config
->vp_config
[i
].rti
.uec_c
=
3055 VXGE_HW_USE_FLASH_DEFAULT
;
3057 device_config
->vp_config
[i
].rti
.uec_d
=
3058 VXGE_HW_USE_FLASH_DEFAULT
;
3060 device_config
->vp_config
[i
].mtu
=
3061 VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU
;
3063 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3064 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT
;
3071 * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath.
3072 * Set the swapper bits appropriately for the vpath.
3074 static enum vxge_hw_status
3075 __vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem
*vpath_reg
)
3077 #ifndef __BIG_ENDIAN
3080 val64
= readq(&vpath_reg
->vpath_general_cfg1
);
3082 val64
|= VXGE_HW_VPATH_GENERAL_CFG1_CTL_BYTE_SWAPEN
;
3083 writeq(val64
, &vpath_reg
->vpath_general_cfg1
);
3090 * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc.
3091 * Set the swapper bits appropriately for the vpath.
3093 static enum vxge_hw_status
3094 __vxge_hw_kdfc_swapper_set(struct vxge_hw_legacy_reg __iomem
*legacy_reg
,
3095 struct vxge_hw_vpath_reg __iomem
*vpath_reg
)
3099 val64
= readq(&legacy_reg
->pifm_wr_swap_en
);
3101 if (val64
== VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE
) {
3102 val64
= readq(&vpath_reg
->kdfcctl_cfg0
);
3105 val64
|= VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO0
|
3106 VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO1
|
3107 VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO2
;
3109 writeq(val64
, &vpath_reg
->kdfcctl_cfg0
);
3117 * vxge_hw_mgmt_reg_read - Read Titan register.
3120 vxge_hw_mgmt_reg_read(struct __vxge_hw_device
*hldev
,
3121 enum vxge_hw_mgmt_reg_type type
,
3122 u32 index
, u32 offset
, u64
*value
)
3124 enum vxge_hw_status status
= VXGE_HW_OK
;
3126 if ((hldev
== NULL
) || (hldev
->magic
!= VXGE_HW_DEVICE_MAGIC
)) {
3127 status
= VXGE_HW_ERR_INVALID_DEVICE
;
3132 case vxge_hw_mgmt_reg_type_legacy
:
3133 if (offset
> sizeof(struct vxge_hw_legacy_reg
) - 8) {
3134 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3137 *value
= readq((void __iomem
*)hldev
->legacy_reg
+ offset
);
3139 case vxge_hw_mgmt_reg_type_toc
:
3140 if (offset
> sizeof(struct vxge_hw_toc_reg
) - 8) {
3141 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3144 *value
= readq((void __iomem
*)hldev
->toc_reg
+ offset
);
3146 case vxge_hw_mgmt_reg_type_common
:
3147 if (offset
> sizeof(struct vxge_hw_common_reg
) - 8) {
3148 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3151 *value
= readq((void __iomem
*)hldev
->common_reg
+ offset
);
3153 case vxge_hw_mgmt_reg_type_mrpcim
:
3154 if (!(hldev
->access_rights
&
3155 VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
)) {
3156 status
= VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
3159 if (offset
> sizeof(struct vxge_hw_mrpcim_reg
) - 8) {
3160 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3163 *value
= readq((void __iomem
*)hldev
->mrpcim_reg
+ offset
);
3165 case vxge_hw_mgmt_reg_type_srpcim
:
3166 if (!(hldev
->access_rights
&
3167 VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
)) {
3168 status
= VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
3171 if (index
> VXGE_HW_TITAN_SRPCIM_REG_SPACES
- 1) {
3172 status
= VXGE_HW_ERR_INVALID_INDEX
;
3175 if (offset
> sizeof(struct vxge_hw_srpcim_reg
) - 8) {
3176 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3179 *value
= readq((void __iomem
*)hldev
->srpcim_reg
[index
] +
3182 case vxge_hw_mgmt_reg_type_vpmgmt
:
3183 if ((index
> VXGE_HW_TITAN_VPMGMT_REG_SPACES
- 1) ||
3184 (!(hldev
->vpath_assignments
& vxge_mBIT(index
)))) {
3185 status
= VXGE_HW_ERR_INVALID_INDEX
;
3188 if (offset
> sizeof(struct vxge_hw_vpmgmt_reg
) - 8) {
3189 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3192 *value
= readq((void __iomem
*)hldev
->vpmgmt_reg
[index
] +
3195 case vxge_hw_mgmt_reg_type_vpath
:
3196 if ((index
> VXGE_HW_TITAN_VPATH_REG_SPACES
- 1) ||
3197 (!(hldev
->vpath_assignments
& vxge_mBIT(index
)))) {
3198 status
= VXGE_HW_ERR_INVALID_INDEX
;
3201 if (index
> VXGE_HW_TITAN_VPATH_REG_SPACES
- 1) {
3202 status
= VXGE_HW_ERR_INVALID_INDEX
;
3205 if (offset
> sizeof(struct vxge_hw_vpath_reg
) - 8) {
3206 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3209 *value
= readq((void __iomem
*)hldev
->vpath_reg
[index
] +
3213 status
= VXGE_HW_ERR_INVALID_TYPE
;
3222 * vxge_hw_vpath_strip_fcs_check - Check for FCS strip.
3225 vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device
*hldev
, u64 vpath_mask
)
3227 struct vxge_hw_vpmgmt_reg __iomem
*vpmgmt_reg
;
3230 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3231 if (!((vpath_mask
) & vxge_mBIT(i
)))
3233 vpmgmt_reg
= hldev
->vpmgmt_reg
[i
];
3234 for (j
= 0; j
< VXGE_HW_MAC_MAX_MAC_PORT_ID
; j
++) {
3235 if (readq(&vpmgmt_reg
->rxmac_cfg0_port_vpmgmt_clone
[j
])
3236 & VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_STRIP_FCS
)
3237 return VXGE_HW_FAIL
;
3243 * vxge_hw_mgmt_reg_Write - Write Titan register.
3246 vxge_hw_mgmt_reg_write(struct __vxge_hw_device
*hldev
,
3247 enum vxge_hw_mgmt_reg_type type
,
3248 u32 index
, u32 offset
, u64 value
)
3250 enum vxge_hw_status status
= VXGE_HW_OK
;
3252 if ((hldev
== NULL
) || (hldev
->magic
!= VXGE_HW_DEVICE_MAGIC
)) {
3253 status
= VXGE_HW_ERR_INVALID_DEVICE
;
3258 case vxge_hw_mgmt_reg_type_legacy
:
3259 if (offset
> sizeof(struct vxge_hw_legacy_reg
) - 8) {
3260 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3263 writeq(value
, (void __iomem
*)hldev
->legacy_reg
+ offset
);
3265 case vxge_hw_mgmt_reg_type_toc
:
3266 if (offset
> sizeof(struct vxge_hw_toc_reg
) - 8) {
3267 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3270 writeq(value
, (void __iomem
*)hldev
->toc_reg
+ offset
);
3272 case vxge_hw_mgmt_reg_type_common
:
3273 if (offset
> sizeof(struct vxge_hw_common_reg
) - 8) {
3274 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3277 writeq(value
, (void __iomem
*)hldev
->common_reg
+ offset
);
3279 case vxge_hw_mgmt_reg_type_mrpcim
:
3280 if (!(hldev
->access_rights
&
3281 VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM
)) {
3282 status
= VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
3285 if (offset
> sizeof(struct vxge_hw_mrpcim_reg
) - 8) {
3286 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3289 writeq(value
, (void __iomem
*)hldev
->mrpcim_reg
+ offset
);
3291 case vxge_hw_mgmt_reg_type_srpcim
:
3292 if (!(hldev
->access_rights
&
3293 VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM
)) {
3294 status
= VXGE_HW_ERR_PRIVILAGED_OPEARATION
;
3297 if (index
> VXGE_HW_TITAN_SRPCIM_REG_SPACES
- 1) {
3298 status
= VXGE_HW_ERR_INVALID_INDEX
;
3301 if (offset
> sizeof(struct vxge_hw_srpcim_reg
) - 8) {
3302 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3305 writeq(value
, (void __iomem
*)hldev
->srpcim_reg
[index
] +
3309 case vxge_hw_mgmt_reg_type_vpmgmt
:
3310 if ((index
> VXGE_HW_TITAN_VPMGMT_REG_SPACES
- 1) ||
3311 (!(hldev
->vpath_assignments
& vxge_mBIT(index
)))) {
3312 status
= VXGE_HW_ERR_INVALID_INDEX
;
3315 if (offset
> sizeof(struct vxge_hw_vpmgmt_reg
) - 8) {
3316 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3319 writeq(value
, (void __iomem
*)hldev
->vpmgmt_reg
[index
] +
3322 case vxge_hw_mgmt_reg_type_vpath
:
3323 if ((index
> VXGE_HW_TITAN_VPATH_REG_SPACES
-1) ||
3324 (!(hldev
->vpath_assignments
& vxge_mBIT(index
)))) {
3325 status
= VXGE_HW_ERR_INVALID_INDEX
;
3328 if (offset
> sizeof(struct vxge_hw_vpath_reg
) - 8) {
3329 status
= VXGE_HW_ERR_INVALID_OFFSET
;
3332 writeq(value
, (void __iomem
*)hldev
->vpath_reg
[index
] +
3336 status
= VXGE_HW_ERR_INVALID_TYPE
;
3344 * __vxge_hw_fifo_abort - Returns the TxD
3345 * This function terminates the TxDs of fifo
3347 static enum vxge_hw_status
__vxge_hw_fifo_abort(struct __vxge_hw_fifo
*fifo
)
3352 vxge_hw_channel_dtr_try_complete(&fifo
->channel
, &txdlh
);
3357 vxge_hw_channel_dtr_complete(&fifo
->channel
);
3359 if (fifo
->txdl_term
) {
3360 fifo
->txdl_term(txdlh
,
3361 VXGE_HW_TXDL_STATE_POSTED
,
3362 fifo
->channel
.userdata
);
3365 vxge_hw_channel_dtr_free(&fifo
->channel
, txdlh
);
3372 * __vxge_hw_fifo_reset - Resets the fifo
3373 * This function resets the fifo during vpath reset operation
3375 static enum vxge_hw_status
__vxge_hw_fifo_reset(struct __vxge_hw_fifo
*fifo
)
3377 enum vxge_hw_status status
= VXGE_HW_OK
;
3379 __vxge_hw_fifo_abort(fifo
);
3380 status
= __vxge_hw_channel_reset(&fifo
->channel
);
3386 * __vxge_hw_fifo_delete - Removes the FIFO
3387 * This function freeup the memory pool and removes the FIFO
3389 static enum vxge_hw_status
3390 __vxge_hw_fifo_delete(struct __vxge_hw_vpath_handle
*vp
)
3392 struct __vxge_hw_fifo
*fifo
= vp
->vpath
->fifoh
;
3394 __vxge_hw_fifo_abort(fifo
);
3397 __vxge_hw_mempool_destroy(fifo
->mempool
);
3399 vp
->vpath
->fifoh
= NULL
;
3401 __vxge_hw_channel_free(&fifo
->channel
);
3407 * __vxge_hw_fifo_mempool_item_alloc - Allocate List blocks for TxD
3409 * This function is callback passed to __vxge_hw_mempool_create to create memory
3413 __vxge_hw_fifo_mempool_item_alloc(
3414 struct vxge_hw_mempool
*mempoolh
,
3415 u32 memblock_index
, struct vxge_hw_mempool_dma
*dma_object
,
3416 u32 index
, u32 is_last
)
3418 u32 memblock_item_idx
;
3419 struct __vxge_hw_fifo_txdl_priv
*txdl_priv
;
3420 struct vxge_hw_fifo_txd
*txdp
=
3421 (struct vxge_hw_fifo_txd
*)mempoolh
->items_arr
[index
];
3422 struct __vxge_hw_fifo
*fifo
=
3423 (struct __vxge_hw_fifo
*)mempoolh
->userdata
;
3424 void *memblock
= mempoolh
->memblocks_arr
[memblock_index
];
3428 txdp
->host_control
= (u64
) (size_t)
3429 __vxge_hw_mempool_item_priv(mempoolh
, memblock_index
, txdp
,
3430 &memblock_item_idx
);
3432 txdl_priv
= __vxge_hw_fifo_txdl_priv(fifo
, txdp
);
3434 vxge_assert(txdl_priv
);
3436 fifo
->channel
.reserve_arr
[fifo
->channel
.reserve_ptr
- 1 - index
] = txdp
;
3438 /* pre-format HW's TxDL's private */
3439 txdl_priv
->dma_offset
= (char *)txdp
- (char *)memblock
;
3440 txdl_priv
->dma_addr
= dma_object
->addr
+ txdl_priv
->dma_offset
;
3441 txdl_priv
->dma_handle
= dma_object
->handle
;
3442 txdl_priv
->memblock
= memblock
;
3443 txdl_priv
->first_txdp
= txdp
;
3444 txdl_priv
->next_txdl_priv
= NULL
;
3445 txdl_priv
->alloc_frags
= 0;
3449 * __vxge_hw_fifo_create - Create a FIFO
3450 * This function creates FIFO and initializes it.
3452 static enum vxge_hw_status
3453 __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle
*vp
,
3454 struct vxge_hw_fifo_attr
*attr
)
3456 enum vxge_hw_status status
= VXGE_HW_OK
;
3457 struct __vxge_hw_fifo
*fifo
;
3458 struct vxge_hw_fifo_config
*config
;
3459 u32 txdl_size
, txdl_per_memblock
;
3460 struct vxge_hw_mempool_cbs fifo_mp_callback
;
3461 struct __vxge_hw_virtualpath
*vpath
;
3463 if ((vp
== NULL
) || (attr
== NULL
)) {
3464 status
= VXGE_HW_ERR_INVALID_HANDLE
;
3468 config
= &vpath
->hldev
->config
.vp_config
[vpath
->vp_id
].fifo
;
3470 txdl_size
= config
->max_frags
* sizeof(struct vxge_hw_fifo_txd
);
3472 txdl_per_memblock
= config
->memblock_size
/ txdl_size
;
3474 fifo
= (struct __vxge_hw_fifo
*)__vxge_hw_channel_allocate(vp
,
3475 VXGE_HW_CHANNEL_TYPE_FIFO
,
3476 config
->fifo_blocks
* txdl_per_memblock
,
3477 attr
->per_txdl_space
, attr
->userdata
);
3480 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
3484 vpath
->fifoh
= fifo
;
3485 fifo
->nofl_db
= vpath
->nofl_db
;
3487 fifo
->vp_id
= vpath
->vp_id
;
3488 fifo
->vp_reg
= vpath
->vp_reg
;
3489 fifo
->stats
= &vpath
->sw_stats
->fifo_stats
;
3491 fifo
->config
= config
;
3493 /* apply "interrupts per txdl" attribute */
3494 fifo
->interrupt_type
= VXGE_HW_FIFO_TXD_INT_TYPE_UTILZ
;
3495 fifo
->tim_tti_cfg1_saved
= vpath
->tim_tti_cfg1_saved
;
3496 fifo
->tim_tti_cfg3_saved
= vpath
->tim_tti_cfg3_saved
;
3498 if (fifo
->config
->intr
)
3499 fifo
->interrupt_type
= VXGE_HW_FIFO_TXD_INT_TYPE_PER_LIST
;
3501 fifo
->no_snoop_bits
= config
->no_snoop_bits
;
3504 * FIFO memory management strategy:
3506 * TxDL split into three independent parts:
3508 * - TxD HW private part
3509 * - driver private part
3511 * Adaptative memory allocation used. i.e. Memory allocated on
3512 * demand with the size which will fit into one memory block.
3513 * One memory block may contain more than one TxDL.
3515 * During "reserve" operations more memory can be allocated on demand
3516 * for example due to FIFO full condition.
3518 * Pool of memory memblocks never shrinks except in __vxge_hw_fifo_close
3519 * routine which will essentially stop the channel and free resources.
3522 /* TxDL common private size == TxDL private + driver private */
3524 sizeof(struct __vxge_hw_fifo_txdl_priv
) + attr
->per_txdl_space
;
3525 fifo
->priv_size
= ((fifo
->priv_size
+ VXGE_CACHE_LINE_SIZE
- 1) /
3526 VXGE_CACHE_LINE_SIZE
) * VXGE_CACHE_LINE_SIZE
;
3528 fifo
->per_txdl_space
= attr
->per_txdl_space
;
3530 /* recompute txdl size to be cacheline aligned */
3531 fifo
->txdl_size
= txdl_size
;
3532 fifo
->txdl_per_memblock
= txdl_per_memblock
;
3534 fifo
->txdl_term
= attr
->txdl_term
;
3535 fifo
->callback
= attr
->callback
;
3537 if (fifo
->txdl_per_memblock
== 0) {
3538 __vxge_hw_fifo_delete(vp
);
3539 status
= VXGE_HW_ERR_INVALID_BLOCK_SIZE
;
3543 fifo_mp_callback
.item_func_alloc
= __vxge_hw_fifo_mempool_item_alloc
;
3546 __vxge_hw_mempool_create(vpath
->hldev
,
3547 fifo
->config
->memblock_size
,
3550 (fifo
->config
->fifo_blocks
* fifo
->txdl_per_memblock
),
3551 (fifo
->config
->fifo_blocks
* fifo
->txdl_per_memblock
),
3555 if (fifo
->mempool
== NULL
) {
3556 __vxge_hw_fifo_delete(vp
);
3557 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
3561 status
= __vxge_hw_channel_initialize(&fifo
->channel
);
3562 if (status
!= VXGE_HW_OK
) {
3563 __vxge_hw_fifo_delete(vp
);
3567 vxge_assert(fifo
->channel
.reserve_ptr
);
3573 * __vxge_hw_vpath_pci_read - Read the content of given address
3574 * in pci config space.
3575 * Read from the vpath pci config space.
3577 static enum vxge_hw_status
3578 __vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath
*vpath
,
3579 u32 phy_func_0
, u32 offset
, u32
*val
)
3582 enum vxge_hw_status status
= VXGE_HW_OK
;
3583 struct vxge_hw_vpath_reg __iomem
*vp_reg
= vpath
->vp_reg
;
3585 val64
= VXGE_HW_PCI_CONFIG_ACCESS_CFG1_ADDRESS(offset
);
3588 val64
|= VXGE_HW_PCI_CONFIG_ACCESS_CFG1_SEL_FUNC0
;
3590 writeq(val64
, &vp_reg
->pci_config_access_cfg1
);
3592 writeq(VXGE_HW_PCI_CONFIG_ACCESS_CFG2_REQ
,
3593 &vp_reg
->pci_config_access_cfg2
);
3596 status
= __vxge_hw_device_register_poll(
3597 &vp_reg
->pci_config_access_cfg2
,
3598 VXGE_HW_INTR_MASK_ALL
, VXGE_HW_DEF_DEVICE_POLL_MILLIS
);
3600 if (status
!= VXGE_HW_OK
)
3603 val64
= readq(&vp_reg
->pci_config_access_status
);
3605 if (val64
& VXGE_HW_PCI_CONFIG_ACCESS_STATUS_ACCESS_ERR
) {
3606 status
= VXGE_HW_FAIL
;
3609 *val
= (u32
)vxge_bVALn(val64
, 32, 32);
3615 * vxge_hw_device_flick_link_led - Flick (blink) link LED.
3616 * @hldev: HW device.
3617 * @on_off: TRUE if flickering to be on, FALSE to be off
3619 * Flicker the link LED.
3622 vxge_hw_device_flick_link_led(struct __vxge_hw_device
*hldev
, u64 on_off
)
3624 struct __vxge_hw_virtualpath
*vpath
;
3625 u64 data0
, data1
= 0, steer_ctrl
= 0;
3626 enum vxge_hw_status status
;
3628 if (hldev
== NULL
) {
3629 status
= VXGE_HW_ERR_INVALID_DEVICE
;
3633 vpath
= &hldev
->virtual_paths
[hldev
->first_vp_id
];
3636 status
= vxge_hw_vpath_fw_api(vpath
,
3637 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LED_CONTROL
,
3638 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO
,
3639 0, &data0
, &data1
, &steer_ctrl
);
3645 * __vxge_hw_vpath_rts_table_get - Get the entries from RTS access tables
3648 __vxge_hw_vpath_rts_table_get(struct __vxge_hw_vpath_handle
*vp
,
3649 u32 action
, u32 rts_table
, u32 offset
,
3650 u64
*data0
, u64
*data1
)
3652 enum vxge_hw_status status
;
3656 status
= VXGE_HW_ERR_INVALID_HANDLE
;
3661 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT
) ||
3663 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT
) ||
3665 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MASK
) ||
3667 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_KEY
)) {
3668 steer_ctrl
= VXGE_HW_RTS_ACCESS_STEER_CTRL_TABLE_SEL
;
3671 status
= vxge_hw_vpath_fw_api(vp
->vpath
, action
, rts_table
, offset
,
3672 data0
, data1
, &steer_ctrl
);
3673 if (status
!= VXGE_HW_OK
)
3676 if ((rts_table
!= VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA
) &&
3678 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT
))
3685 * __vxge_hw_vpath_rts_table_set - Set the entries of RTS access tables
3688 __vxge_hw_vpath_rts_table_set(struct __vxge_hw_vpath_handle
*vp
, u32 action
,
3689 u32 rts_table
, u32 offset
, u64 steer_data0
,
3692 u64 data0
, data1
= 0, steer_ctrl
= 0;
3693 enum vxge_hw_status status
;
3696 status
= VXGE_HW_ERR_INVALID_HANDLE
;
3700 data0
= steer_data0
;
3702 if ((rts_table
== VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA
) ||
3704 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT
))
3705 data1
= steer_data1
;
3707 status
= vxge_hw_vpath_fw_api(vp
->vpath
, action
, rts_table
, offset
,
3708 &data0
, &data1
, &steer_ctrl
);
3714 * vxge_hw_vpath_rts_rth_set - Set/configure RTS hashing.
3716 enum vxge_hw_status
vxge_hw_vpath_rts_rth_set(
3717 struct __vxge_hw_vpath_handle
*vp
,
3718 enum vxge_hw_rth_algoritms algorithm
,
3719 struct vxge_hw_rth_hash_types
*hash_type
,
3723 enum vxge_hw_status status
= VXGE_HW_OK
;
3726 status
= VXGE_HW_ERR_INVALID_HANDLE
;
3730 status
= __vxge_hw_vpath_rts_table_get(vp
,
3731 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY
,
3732 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG
,
3734 if (status
!= VXGE_HW_OK
)
3737 data0
&= ~(VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(0xf) |
3738 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(0x3));
3740 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_EN
|
3741 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(bucket_size
) |
3742 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(algorithm
);
3744 if (hash_type
->hash_type_tcpipv4_en
)
3745 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV4_EN
;
3747 if (hash_type
->hash_type_ipv4_en
)
3748 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV4_EN
;
3750 if (hash_type
->hash_type_tcpipv6_en
)
3751 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EN
;
3753 if (hash_type
->hash_type_ipv6_en
)
3754 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EN
;
3756 if (hash_type
->hash_type_tcpipv6ex_en
)
3758 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EX_EN
;
3760 if (hash_type
->hash_type_ipv6ex_en
)
3761 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EX_EN
;
3763 if (VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_RTH_GEN_ACTIVE_TABLE(data0
))
3764 data0
&= ~VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE
;
3766 data0
|= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE
;
3768 status
= __vxge_hw_vpath_rts_table_set(vp
,
3769 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY
,
3770 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG
,
3777 vxge_hw_rts_rth_data0_data1_get(u32 j
, u64
*data0
, u64
*data1
,
3778 u16 flag
, u8
*itable
)
3782 *data0
= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_NUM(j
)|
3783 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_ENTRY_EN
|
3784 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_DATA(
3788 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_NUM(j
)|
3789 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_ENTRY_EN
|
3790 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_DATA(
3793 *data1
= VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_NUM(j
)|
3794 VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_ENTRY_EN
|
3795 VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_DATA(
3799 VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_NUM(j
)|
3800 VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_ENTRY_EN
|
3801 VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_DATA(
3808 * vxge_hw_vpath_rts_rth_itable_set - Set/configure indirection table (IT).
3810 enum vxge_hw_status
vxge_hw_vpath_rts_rth_itable_set(
3811 struct __vxge_hw_vpath_handle
**vpath_handles
,
3817 u32 i
, j
, action
, rts_table
;
3821 enum vxge_hw_status status
= VXGE_HW_OK
;
3822 struct __vxge_hw_vpath_handle
*vp
= vpath_handles
[0];
3825 status
= VXGE_HW_ERR_INVALID_HANDLE
;
3829 max_entries
= (((u32
)1) << itable_size
);
3831 if (vp
->vpath
->hldev
->config
.rth_it_type
3832 == VXGE_HW_RTH_IT_TYPE_SOLO_IT
) {
3833 action
= VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY
;
3835 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT
;
3837 for (j
= 0; j
< max_entries
; j
++) {
3842 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
3845 status
= __vxge_hw_vpath_rts_table_set(vpath_handles
[0],
3846 action
, rts_table
, j
, data0
, data1
);
3848 if (status
!= VXGE_HW_OK
)
3852 for (j
= 0; j
< max_entries
; j
++) {
3857 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_ENTRY_EN
|
3858 VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
3861 status
= __vxge_hw_vpath_rts_table_set(
3862 vpath_handles
[mtable
[itable
[j
]]], action
,
3863 rts_table
, j
, data0
, data1
);
3865 if (status
!= VXGE_HW_OK
)
3869 action
= VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY
;
3871 VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT
;
3872 for (i
= 0; i
< vpath_count
; i
++) {
3874 for (j
= 0; j
< max_entries
;) {
3879 while (j
< max_entries
) {
3880 if (mtable
[itable
[j
]] != i
) {
3884 vxge_hw_rts_rth_data0_data1_get(j
,
3885 &data0
, &data1
, 1, itable
);
3890 while (j
< max_entries
) {
3891 if (mtable
[itable
[j
]] != i
) {
3895 vxge_hw_rts_rth_data0_data1_get(j
,
3896 &data0
, &data1
, 2, itable
);
3901 while (j
< max_entries
) {
3902 if (mtable
[itable
[j
]] != i
) {
3906 vxge_hw_rts_rth_data0_data1_get(j
,
3907 &data0
, &data1
, 3, itable
);
3912 while (j
< max_entries
) {
3913 if (mtable
[itable
[j
]] != i
) {
3917 vxge_hw_rts_rth_data0_data1_get(j
,
3918 &data0
, &data1
, 4, itable
);
3924 status
= __vxge_hw_vpath_rts_table_set(
3929 if (status
!= VXGE_HW_OK
)
3940 * vxge_hw_vpath_check_leak - Check for memory leak
3941 * @ringh: Handle to the ring object used for receive
3943 * If PRC_RXD_DOORBELL_VPn.NEW_QW_CNT is larger or equal to
3944 * PRC_CFG6_VPn.RXD_SPAT then a leak has occurred.
3945 * Returns: VXGE_HW_FAIL, if leak has occurred.
3949 vxge_hw_vpath_check_leak(struct __vxge_hw_ring
*ring
)
3951 enum vxge_hw_status status
= VXGE_HW_OK
;
3952 u64 rxd_new_count
, rxd_spat
;
3957 rxd_new_count
= readl(&ring
->vp_reg
->prc_rxd_doorbell
);
3958 rxd_spat
= readq(&ring
->vp_reg
->prc_cfg6
);
3959 rxd_spat
= VXGE_HW_PRC_CFG6_RXD_SPAT(rxd_spat
);
3961 if (rxd_new_count
>= rxd_spat
)
3962 status
= VXGE_HW_FAIL
;
3968 * __vxge_hw_vpath_mgmt_read
3969 * This routine reads the vpath_mgmt registers
3971 static enum vxge_hw_status
3972 __vxge_hw_vpath_mgmt_read(
3973 struct __vxge_hw_device
*hldev
,
3974 struct __vxge_hw_virtualpath
*vpath
)
3976 u32 i
, mtu
= 0, max_pyld
= 0;
3979 for (i
= 0; i
< VXGE_HW_MAC_MAX_MAC_PORT_ID
; i
++) {
3981 val64
= readq(&vpath
->vpmgmt_reg
->
3982 rxmac_cfg0_port_vpmgmt_clone
[i
]);
3985 VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_GET_MAX_PYLD_LEN
3991 vpath
->max_mtu
= mtu
+ VXGE_HW_MAC_HEADER_MAX_SIZE
;
3993 val64
= readq(&vpath
->vpmgmt_reg
->xmac_vsport_choices_vp
);
3995 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3996 if (val64
& vxge_mBIT(i
))
3997 vpath
->vsport_number
= i
;
4000 val64
= readq(&vpath
->vpmgmt_reg
->xgmac_gen_status_vpmgmt_clone
);
4002 if (val64
& VXGE_HW_XGMAC_GEN_STATUS_VPMGMT_CLONE_XMACJ_NTWK_OK
)
4003 VXGE_HW_DEVICE_LINK_STATE_SET(vpath
->hldev
, VXGE_HW_LINK_UP
);
4005 VXGE_HW_DEVICE_LINK_STATE_SET(vpath
->hldev
, VXGE_HW_LINK_DOWN
);
4011 * __vxge_hw_vpath_reset_check - Check if resetting the vpath completed
4012 * This routine checks the vpath_rst_in_prog register to see if
4013 * adapter completed the reset process for the vpath
4015 static enum vxge_hw_status
4016 __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath
*vpath
)
4018 enum vxge_hw_status status
;
4020 status
= __vxge_hw_device_register_poll(
4021 &vpath
->hldev
->common_reg
->vpath_rst_in_prog
,
4022 VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(
4023 1 << (16 - vpath
->vp_id
)),
4024 vpath
->hldev
->config
.device_poll_millis
);
4030 * __vxge_hw_vpath_reset
4031 * This routine resets the vpath on the device
4033 static enum vxge_hw_status
4034 __vxge_hw_vpath_reset(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4038 val64
= VXGE_HW_CMN_RSTHDLR_CFG0_SW_RESET_VPATH(1 << (16 - vp_id
));
4040 __vxge_hw_pio_mem_write32_upper((u32
)vxge_bVALn(val64
, 0, 32),
4041 &hldev
->common_reg
->cmn_rsthdlr_cfg0
);
4047 * __vxge_hw_vpath_sw_reset
4048 * This routine resets the vpath structures
4050 static enum vxge_hw_status
4051 __vxge_hw_vpath_sw_reset(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4053 enum vxge_hw_status status
= VXGE_HW_OK
;
4054 struct __vxge_hw_virtualpath
*vpath
;
4056 vpath
= &hldev
->virtual_paths
[vp_id
];
4059 status
= __vxge_hw_ring_reset(vpath
->ringh
);
4060 if (status
!= VXGE_HW_OK
)
4065 status
= __vxge_hw_fifo_reset(vpath
->fifoh
);
4071 * __vxge_hw_vpath_prc_configure
4072 * This routine configures the prc registers of virtual path using the config
4076 __vxge_hw_vpath_prc_configure(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4079 struct __vxge_hw_virtualpath
*vpath
;
4080 struct vxge_hw_vp_config
*vp_config
;
4081 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
4083 vpath
= &hldev
->virtual_paths
[vp_id
];
4084 vp_reg
= vpath
->vp_reg
;
4085 vp_config
= vpath
->vp_config
;
4087 if (vp_config
->ring
.enable
== VXGE_HW_RING_DISABLE
)
4090 val64
= readq(&vp_reg
->prc_cfg1
);
4091 val64
|= VXGE_HW_PRC_CFG1_RTI_TINT_DISABLE
;
4092 writeq(val64
, &vp_reg
->prc_cfg1
);
4094 val64
= readq(&vpath
->vp_reg
->prc_cfg6
);
4095 val64
|= VXGE_HW_PRC_CFG6_DOORBELL_MODE_EN
;
4096 writeq(val64
, &vpath
->vp_reg
->prc_cfg6
);
4098 val64
= readq(&vp_reg
->prc_cfg7
);
4100 if (vpath
->vp_config
->ring
.scatter_mode
!=
4101 VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT
) {
4103 val64
&= ~VXGE_HW_PRC_CFG7_SCATTER_MODE(0x3);
4105 switch (vpath
->vp_config
->ring
.scatter_mode
) {
4106 case VXGE_HW_RING_SCATTER_MODE_A
:
4107 val64
|= VXGE_HW_PRC_CFG7_SCATTER_MODE(
4108 VXGE_HW_PRC_CFG7_SCATTER_MODE_A
);
4110 case VXGE_HW_RING_SCATTER_MODE_B
:
4111 val64
|= VXGE_HW_PRC_CFG7_SCATTER_MODE(
4112 VXGE_HW_PRC_CFG7_SCATTER_MODE_B
);
4114 case VXGE_HW_RING_SCATTER_MODE_C
:
4115 val64
|= VXGE_HW_PRC_CFG7_SCATTER_MODE(
4116 VXGE_HW_PRC_CFG7_SCATTER_MODE_C
);
4121 writeq(val64
, &vp_reg
->prc_cfg7
);
4123 writeq(VXGE_HW_PRC_CFG5_RXD0_ADD(
4124 __vxge_hw_ring_first_block_address_get(
4125 vpath
->ringh
) >> 3), &vp_reg
->prc_cfg5
);
4127 val64
= readq(&vp_reg
->prc_cfg4
);
4128 val64
|= VXGE_HW_PRC_CFG4_IN_SVC
;
4129 val64
&= ~VXGE_HW_PRC_CFG4_RING_MODE(0x3);
4131 val64
|= VXGE_HW_PRC_CFG4_RING_MODE(
4132 VXGE_HW_PRC_CFG4_RING_MODE_ONE_BUFFER
);
4134 if (hldev
->config
.rth_en
== VXGE_HW_RTH_DISABLE
)
4135 val64
|= VXGE_HW_PRC_CFG4_RTH_DISABLE
;
4137 val64
&= ~VXGE_HW_PRC_CFG4_RTH_DISABLE
;
4139 writeq(val64
, &vp_reg
->prc_cfg4
);
4143 * __vxge_hw_vpath_kdfc_configure
4144 * This routine configures the kdfc registers of virtual path using the
4147 static enum vxge_hw_status
4148 __vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4152 enum vxge_hw_status status
= VXGE_HW_OK
;
4153 struct __vxge_hw_virtualpath
*vpath
;
4154 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
4156 vpath
= &hldev
->virtual_paths
[vp_id
];
4157 vp_reg
= vpath
->vp_reg
;
4158 status
= __vxge_hw_kdfc_swapper_set(hldev
->legacy_reg
, vp_reg
);
4160 if (status
!= VXGE_HW_OK
)
4163 val64
= readq(&vp_reg
->kdfc_drbl_triplet_total
);
4165 vpath
->max_kdfc_db
=
4166 (u32
)VXGE_HW_KDFC_DRBL_TRIPLET_TOTAL_GET_KDFC_MAX_SIZE(
4169 if (vpath
->vp_config
->fifo
.enable
== VXGE_HW_FIFO_ENABLE
) {
4171 vpath
->max_nofl_db
= vpath
->max_kdfc_db
;
4173 if (vpath
->max_nofl_db
<
4174 ((vpath
->vp_config
->fifo
.memblock_size
/
4175 (vpath
->vp_config
->fifo
.max_frags
*
4176 sizeof(struct vxge_hw_fifo_txd
))) *
4177 vpath
->vp_config
->fifo
.fifo_blocks
)) {
4179 return VXGE_HW_BADCFG_FIFO_BLOCKS
;
4181 val64
= VXGE_HW_KDFC_FIFO_TRPL_PARTITION_LENGTH_0(
4182 (vpath
->max_nofl_db
*2)-1);
4185 writeq(val64
, &vp_reg
->kdfc_fifo_trpl_partition
);
4187 writeq(VXGE_HW_KDFC_FIFO_TRPL_CTRL_TRIPLET_ENABLE
,
4188 &vp_reg
->kdfc_fifo_trpl_ctrl
);
4190 val64
= readq(&vp_reg
->kdfc_trpl_fifo_0_ctrl
);
4192 val64
&= ~(VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(0x3) |
4193 VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0xFF));
4195 val64
|= VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(
4196 VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE_NON_OFFLOAD_ONLY
) |
4197 #ifndef __BIG_ENDIAN
4198 VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SWAP_EN
|
4200 VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0);
4202 writeq(val64
, &vp_reg
->kdfc_trpl_fifo_0_ctrl
);
4203 writeq((u64
)0, &vp_reg
->kdfc_trpl_fifo_0_wb_address
);
4205 vpath_stride
= readq(&hldev
->toc_reg
->toc_kdfc_vpath_stride
);
4208 (struct __vxge_hw_non_offload_db_wrapper __iomem
*)
4209 (hldev
->kdfc
+ (vp_id
*
4210 VXGE_HW_TOC_KDFC_VPATH_STRIDE_GET_TOC_KDFC_VPATH_STRIDE(
4217 * __vxge_hw_vpath_mac_configure
4218 * This routine configures the mac of virtual path using the config passed
4220 static enum vxge_hw_status
4221 __vxge_hw_vpath_mac_configure(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4224 struct __vxge_hw_virtualpath
*vpath
;
4225 struct vxge_hw_vp_config
*vp_config
;
4226 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
4228 vpath
= &hldev
->virtual_paths
[vp_id
];
4229 vp_reg
= vpath
->vp_reg
;
4230 vp_config
= vpath
->vp_config
;
4232 writeq(VXGE_HW_XMAC_VSPORT_CHOICE_VSPORT_NUMBER(
4233 vpath
->vsport_number
), &vp_reg
->xmac_vsport_choice
);
4235 if (vp_config
->ring
.enable
== VXGE_HW_RING_ENABLE
) {
4237 val64
= readq(&vp_reg
->xmac_rpa_vcfg
);
4239 if (vp_config
->rpa_strip_vlan_tag
!=
4240 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT
) {
4241 if (vp_config
->rpa_strip_vlan_tag
)
4242 val64
|= VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG
;
4244 val64
&= ~VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG
;
4247 writeq(val64
, &vp_reg
->xmac_rpa_vcfg
);
4248 val64
= readq(&vp_reg
->rxmac_vcfg0
);
4250 if (vp_config
->mtu
!=
4251 VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU
) {
4252 val64
&= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
4253 if ((vp_config
->mtu
+
4254 VXGE_HW_MAC_HEADER_MAX_SIZE
) < vpath
->max_mtu
)
4255 val64
|= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
4257 VXGE_HW_MAC_HEADER_MAX_SIZE
);
4259 val64
|= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
4263 writeq(val64
, &vp_reg
->rxmac_vcfg0
);
4265 val64
= readq(&vp_reg
->rxmac_vcfg1
);
4267 val64
&= ~(VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(0x3) |
4268 VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE
);
4270 if (hldev
->config
.rth_it_type
==
4271 VXGE_HW_RTH_IT_TYPE_MULTI_IT
) {
4272 val64
|= VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(
4274 VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE
;
4277 writeq(val64
, &vp_reg
->rxmac_vcfg1
);
4283 * __vxge_hw_vpath_tim_configure
4284 * This routine configures the tim registers of virtual path using the config
4287 static enum vxge_hw_status
4288 __vxge_hw_vpath_tim_configure(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4291 struct __vxge_hw_virtualpath
*vpath
;
4292 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
4293 struct vxge_hw_vp_config
*config
;
4295 vpath
= &hldev
->virtual_paths
[vp_id
];
4296 vp_reg
= vpath
->vp_reg
;
4297 config
= vpath
->vp_config
;
4299 writeq(0, &vp_reg
->tim_dest_addr
);
4300 writeq(0, &vp_reg
->tim_vpath_map
);
4301 writeq(0, &vp_reg
->tim_bitmap
);
4302 writeq(0, &vp_reg
->tim_remap
);
4304 if (config
->ring
.enable
== VXGE_HW_RING_ENABLE
)
4305 writeq(VXGE_HW_TIM_RING_ASSN_INT_NUM(
4306 (vp_id
* VXGE_HW_MAX_INTR_PER_VP
) +
4307 VXGE_HW_VPATH_INTR_RX
), &vp_reg
->tim_ring_assn
);
4309 val64
= readq(&vp_reg
->tim_pci_cfg
);
4310 val64
|= VXGE_HW_TIM_PCI_CFG_ADD_PAD
;
4311 writeq(val64
, &vp_reg
->tim_pci_cfg
);
4313 if (config
->fifo
.enable
== VXGE_HW_FIFO_ENABLE
) {
4315 val64
= readq(&vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4317 if (config
->tti
.btimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4318 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
4320 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
4321 config
->tti
.btimer_val
);
4324 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN
;
4326 if (config
->tti
.timer_ac_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4327 if (config
->tti
.timer_ac_en
)
4328 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC
;
4330 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC
;
4333 if (config
->tti
.timer_ci_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4334 if (config
->tti
.timer_ci_en
)
4335 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI
;
4337 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI
;
4340 if (config
->tti
.urange_a
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4341 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
4342 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
4343 config
->tti
.urange_a
);
4346 if (config
->tti
.urange_b
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4347 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
4348 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
4349 config
->tti
.urange_b
);
4352 if (config
->tti
.urange_c
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4353 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
4354 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
4355 config
->tti
.urange_c
);
4358 writeq(val64
, &vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4359 vpath
->tim_tti_cfg1_saved
= val64
;
4361 val64
= readq(&vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4363 if (config
->tti
.uec_a
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4364 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
4365 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
4369 if (config
->tti
.uec_b
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4370 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
4371 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
4375 if (config
->tti
.uec_c
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4376 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
4377 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
4381 if (config
->tti
.uec_d
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4382 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
4383 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
4387 writeq(val64
, &vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4388 val64
= readq(&vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4390 if (config
->tti
.timer_ri_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4391 if (config
->tti
.timer_ri_en
)
4392 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI
;
4394 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI
;
4397 if (config
->tti
.rtimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4398 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
4400 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
4401 config
->tti
.rtimer_val
);
4404 if (config
->tti
.util_sel
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4405 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
4406 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id
);
4409 if (config
->tti
.ltimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4410 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
4412 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
4413 config
->tti
.ltimer_val
);
4416 writeq(val64
, &vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_TX
]);
4417 vpath
->tim_tti_cfg3_saved
= val64
;
4420 if (config
->ring
.enable
== VXGE_HW_RING_ENABLE
) {
4422 val64
= readq(&vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4424 if (config
->rti
.btimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4425 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
4427 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
4428 config
->rti
.btimer_val
);
4431 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN
;
4433 if (config
->rti
.timer_ac_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4434 if (config
->rti
.timer_ac_en
)
4435 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC
;
4437 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC
;
4440 if (config
->rti
.timer_ci_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4441 if (config
->rti
.timer_ci_en
)
4442 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI
;
4444 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI
;
4447 if (config
->rti
.urange_a
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4448 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
4449 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
4450 config
->rti
.urange_a
);
4453 if (config
->rti
.urange_b
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4454 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
4455 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
4456 config
->rti
.urange_b
);
4459 if (config
->rti
.urange_c
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4460 val64
&= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
4461 val64
|= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
4462 config
->rti
.urange_c
);
4465 writeq(val64
, &vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4466 vpath
->tim_rti_cfg1_saved
= val64
;
4468 val64
= readq(&vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4470 if (config
->rti
.uec_a
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4471 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
4472 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
4476 if (config
->rti
.uec_b
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4477 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
4478 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
4482 if (config
->rti
.uec_c
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4483 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
4484 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
4488 if (config
->rti
.uec_d
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4489 val64
&= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
4490 val64
|= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
4494 writeq(val64
, &vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4495 val64
= readq(&vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4497 if (config
->rti
.timer_ri_en
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4498 if (config
->rti
.timer_ri_en
)
4499 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI
;
4501 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI
;
4504 if (config
->rti
.rtimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4505 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
4507 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
4508 config
->rti
.rtimer_val
);
4511 if (config
->rti
.util_sel
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4512 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
4513 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id
);
4516 if (config
->rti
.ltimer_val
!= VXGE_HW_USE_FLASH_DEFAULT
) {
4517 val64
&= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
4519 val64
|= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
4520 config
->rti
.ltimer_val
);
4523 writeq(val64
, &vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_RX
]);
4524 vpath
->tim_rti_cfg3_saved
= val64
;
4528 writeq(val64
, &vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_EINTA
]);
4529 writeq(val64
, &vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_EINTA
]);
4530 writeq(val64
, &vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_EINTA
]);
4531 writeq(val64
, &vp_reg
->tim_cfg1_int_num
[VXGE_HW_VPATH_INTR_BMAP
]);
4532 writeq(val64
, &vp_reg
->tim_cfg2_int_num
[VXGE_HW_VPATH_INTR_BMAP
]);
4533 writeq(val64
, &vp_reg
->tim_cfg3_int_num
[VXGE_HW_VPATH_INTR_BMAP
]);
4535 val64
= VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_PRD(150);
4536 val64
|= VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_DIV(0);
4537 val64
|= VXGE_HW_TIM_WRKLD_CLC_CNT_RX_TX(3);
4538 writeq(val64
, &vp_reg
->tim_wrkld_clc
);
4544 * __vxge_hw_vpath_initialize
4545 * This routine is the final phase of init which initializes the
4546 * registers of the vpath using the configuration passed.
4548 static enum vxge_hw_status
4549 __vxge_hw_vpath_initialize(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4553 enum vxge_hw_status status
= VXGE_HW_OK
;
4554 struct __vxge_hw_virtualpath
*vpath
;
4555 struct vxge_hw_vpath_reg __iomem
*vp_reg
;
4557 vpath
= &hldev
->virtual_paths
[vp_id
];
4559 if (!(hldev
->vpath_assignments
& vxge_mBIT(vp_id
))) {
4560 status
= VXGE_HW_ERR_VPATH_NOT_AVAILABLE
;
4563 vp_reg
= vpath
->vp_reg
;
4565 status
= __vxge_hw_vpath_swapper_set(vpath
->vp_reg
);
4566 if (status
!= VXGE_HW_OK
)
4569 status
= __vxge_hw_vpath_mac_configure(hldev
, vp_id
);
4570 if (status
!= VXGE_HW_OK
)
4573 status
= __vxge_hw_vpath_kdfc_configure(hldev
, vp_id
);
4574 if (status
!= VXGE_HW_OK
)
4577 status
= __vxge_hw_vpath_tim_configure(hldev
, vp_id
);
4578 if (status
!= VXGE_HW_OK
)
4581 val64
= readq(&vp_reg
->rtdma_rd_optimization_ctrl
);
4583 /* Get MRRS value from device control */
4584 status
= __vxge_hw_vpath_pci_read(vpath
, 1, 0x78, &val32
);
4585 if (status
== VXGE_HW_OK
) {
4586 val32
= (val32
& VXGE_HW_PCI_EXP_DEVCTL_READRQ
) >> 12;
4588 ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(7));
4590 VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(val32
);
4592 val64
|= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_WAIT_FOR_SPACE
;
4595 val64
&= ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(7));
4597 VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(
4598 VXGE_HW_MAX_PAYLOAD_SIZE_512
);
4600 val64
|= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY_EN
;
4601 writeq(val64
, &vp_reg
->rtdma_rd_optimization_ctrl
);
4608 * __vxge_hw_vp_terminate - Terminate Virtual Path structure
4609 * This routine closes all channels it opened and freeup memory
4611 static void __vxge_hw_vp_terminate(struct __vxge_hw_device
*hldev
, u32 vp_id
)
4613 struct __vxge_hw_virtualpath
*vpath
;
4615 vpath
= &hldev
->virtual_paths
[vp_id
];
4617 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
)
4620 VXGE_HW_DEVICE_TIM_INT_MASK_RESET(vpath
->hldev
->tim_int_mask0
,
4621 vpath
->hldev
->tim_int_mask1
, vpath
->vp_id
);
4622 hldev
->stats
.hw_dev_info_stats
.vpath_info
[vpath
->vp_id
] = NULL
;
4624 /* If the whole struct __vxge_hw_virtualpath is zeroed, nothing will
4625 * work after the interface is brought down.
4627 spin_lock(&vpath
->lock
);
4628 vpath
->vp_open
= VXGE_HW_VP_NOT_OPEN
;
4629 spin_unlock(&vpath
->lock
);
4631 vpath
->vpmgmt_reg
= NULL
;
4632 vpath
->nofl_db
= NULL
;
4634 vpath
->vsport_number
= 0;
4635 vpath
->max_kdfc_db
= 0;
4636 vpath
->max_nofl_db
= 0;
4637 vpath
->ringh
= NULL
;
4638 vpath
->fifoh
= NULL
;
4639 memset(&vpath
->vpath_handles
, 0, sizeof(struct list_head
));
4640 vpath
->stats_block
= NULL
;
4641 vpath
->hw_stats
= NULL
;
4642 vpath
->hw_stats_sav
= NULL
;
4643 vpath
->sw_stats
= NULL
;
4650 * __vxge_hw_vp_initialize - Initialize Virtual Path structure
4651 * This routine is the initial phase of init which resets the vpath and
4652 * initializes the software support structures.
4654 static enum vxge_hw_status
4655 __vxge_hw_vp_initialize(struct __vxge_hw_device
*hldev
, u32 vp_id
,
4656 struct vxge_hw_vp_config
*config
)
4658 struct __vxge_hw_virtualpath
*vpath
;
4659 enum vxge_hw_status status
= VXGE_HW_OK
;
4661 if (!(hldev
->vpath_assignments
& vxge_mBIT(vp_id
))) {
4662 status
= VXGE_HW_ERR_VPATH_NOT_AVAILABLE
;
4666 vpath
= &hldev
->virtual_paths
[vp_id
];
4668 spin_lock_init(&vpath
->lock
);
4669 vpath
->vp_id
= vp_id
;
4670 vpath
->vp_open
= VXGE_HW_VP_OPEN
;
4671 vpath
->hldev
= hldev
;
4672 vpath
->vp_config
= config
;
4673 vpath
->vp_reg
= hldev
->vpath_reg
[vp_id
];
4674 vpath
->vpmgmt_reg
= hldev
->vpmgmt_reg
[vp_id
];
4676 __vxge_hw_vpath_reset(hldev
, vp_id
);
4678 status
= __vxge_hw_vpath_reset_check(vpath
);
4679 if (status
!= VXGE_HW_OK
) {
4680 memset(vpath
, 0, sizeof(struct __vxge_hw_virtualpath
));
4684 status
= __vxge_hw_vpath_mgmt_read(hldev
, vpath
);
4685 if (status
!= VXGE_HW_OK
) {
4686 memset(vpath
, 0, sizeof(struct __vxge_hw_virtualpath
));
4690 INIT_LIST_HEAD(&vpath
->vpath_handles
);
4692 vpath
->sw_stats
= &hldev
->stats
.sw_dev_info_stats
.vpath_info
[vp_id
];
4694 VXGE_HW_DEVICE_TIM_INT_MASK_SET(hldev
->tim_int_mask0
,
4695 hldev
->tim_int_mask1
, vp_id
);
4697 status
= __vxge_hw_vpath_initialize(hldev
, vp_id
);
4698 if (status
!= VXGE_HW_OK
)
4699 __vxge_hw_vp_terminate(hldev
, vp_id
);
4705 * vxge_hw_vpath_mtu_set - Set MTU.
4706 * Set new MTU value. Example, to use jumbo frames:
4707 * vxge_hw_vpath_mtu_set(my_device, 9600);
4710 vxge_hw_vpath_mtu_set(struct __vxge_hw_vpath_handle
*vp
, u32 new_mtu
)
4713 enum vxge_hw_status status
= VXGE_HW_OK
;
4714 struct __vxge_hw_virtualpath
*vpath
;
4717 status
= VXGE_HW_ERR_INVALID_HANDLE
;
4722 new_mtu
+= VXGE_HW_MAC_HEADER_MAX_SIZE
;
4724 if ((new_mtu
< VXGE_HW_MIN_MTU
) || (new_mtu
> vpath
->max_mtu
))
4725 status
= VXGE_HW_ERR_INVALID_MTU_SIZE
;
4727 val64
= readq(&vpath
->vp_reg
->rxmac_vcfg0
);
4729 val64
&= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
4730 val64
|= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(new_mtu
);
4732 writeq(val64
, &vpath
->vp_reg
->rxmac_vcfg0
);
4734 vpath
->vp_config
->mtu
= new_mtu
- VXGE_HW_MAC_HEADER_MAX_SIZE
;
4741 * vxge_hw_vpath_stats_enable - Enable vpath h/wstatistics.
4742 * Enable the DMA vpath statistics. The function is to be called to re-enable
4743 * the adapter to update stats into the host memory
4745 static enum vxge_hw_status
4746 vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle
*vp
)
4748 enum vxge_hw_status status
= VXGE_HW_OK
;
4749 struct __vxge_hw_virtualpath
*vpath
;
4753 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
4754 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
4758 memcpy(vpath
->hw_stats_sav
, vpath
->hw_stats
,
4759 sizeof(struct vxge_hw_vpath_stats_hw_info
));
4761 status
= __vxge_hw_vpath_stats_get(vpath
, vpath
->hw_stats
);
4767 * __vxge_hw_blockpool_block_allocate - Allocates a block from block pool
4768 * This function allocates a block from block pool or from the system
4770 static struct __vxge_hw_blockpool_entry
*
4771 __vxge_hw_blockpool_block_allocate(struct __vxge_hw_device
*devh
, u32 size
)
4773 struct __vxge_hw_blockpool_entry
*entry
= NULL
;
4774 struct __vxge_hw_blockpool
*blockpool
;
4776 blockpool
= &devh
->block_pool
;
4778 if (size
== blockpool
->block_size
) {
4780 if (!list_empty(&blockpool
->free_block_list
))
4781 entry
= (struct __vxge_hw_blockpool_entry
*)
4782 list_first_entry(&blockpool
->free_block_list
,
4783 struct __vxge_hw_blockpool_entry
,
4786 if (entry
!= NULL
) {
4787 list_del(&entry
->item
);
4788 blockpool
->pool_size
--;
4793 __vxge_hw_blockpool_blocks_add(blockpool
);
4799 * vxge_hw_vpath_open - Open a virtual path on a given adapter
4800 * This function is used to open access to virtual path of an
4801 * adapter for offload, GRO operations. This function returns
4805 vxge_hw_vpath_open(struct __vxge_hw_device
*hldev
,
4806 struct vxge_hw_vpath_attr
*attr
,
4807 struct __vxge_hw_vpath_handle
**vpath_handle
)
4809 struct __vxge_hw_virtualpath
*vpath
;
4810 struct __vxge_hw_vpath_handle
*vp
;
4811 enum vxge_hw_status status
;
4813 vpath
= &hldev
->virtual_paths
[attr
->vp_id
];
4815 if (vpath
->vp_open
== VXGE_HW_VP_OPEN
) {
4816 status
= VXGE_HW_ERR_INVALID_STATE
;
4817 goto vpath_open_exit1
;
4820 status
= __vxge_hw_vp_initialize(hldev
, attr
->vp_id
,
4821 &hldev
->config
.vp_config
[attr
->vp_id
]);
4822 if (status
!= VXGE_HW_OK
)
4823 goto vpath_open_exit1
;
4825 vp
= vzalloc(sizeof(struct __vxge_hw_vpath_handle
));
4827 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
4828 goto vpath_open_exit2
;
4833 if (vpath
->vp_config
->fifo
.enable
== VXGE_HW_FIFO_ENABLE
) {
4834 status
= __vxge_hw_fifo_create(vp
, &attr
->fifo_attr
);
4835 if (status
!= VXGE_HW_OK
)
4836 goto vpath_open_exit6
;
4839 if (vpath
->vp_config
->ring
.enable
== VXGE_HW_RING_ENABLE
) {
4840 status
= __vxge_hw_ring_create(vp
, &attr
->ring_attr
);
4841 if (status
!= VXGE_HW_OK
)
4842 goto vpath_open_exit7
;
4844 __vxge_hw_vpath_prc_configure(hldev
, attr
->vp_id
);
4847 vpath
->fifoh
->tx_intr_num
=
4848 (attr
->vp_id
* VXGE_HW_MAX_INTR_PER_VP
) +
4849 VXGE_HW_VPATH_INTR_TX
;
4851 vpath
->stats_block
= __vxge_hw_blockpool_block_allocate(hldev
,
4852 VXGE_HW_BLOCK_SIZE
);
4853 if (vpath
->stats_block
== NULL
) {
4854 status
= VXGE_HW_ERR_OUT_OF_MEMORY
;
4855 goto vpath_open_exit8
;
4858 vpath
->hw_stats
= vpath
->stats_block
->memblock
;
4859 memset(vpath
->hw_stats
, 0,
4860 sizeof(struct vxge_hw_vpath_stats_hw_info
));
4862 hldev
->stats
.hw_dev_info_stats
.vpath_info
[attr
->vp_id
] =
4865 vpath
->hw_stats_sav
=
4866 &hldev
->stats
.hw_dev_info_stats
.vpath_info_sav
[attr
->vp_id
];
4867 memset(vpath
->hw_stats_sav
, 0,
4868 sizeof(struct vxge_hw_vpath_stats_hw_info
));
4870 writeq(vpath
->stats_block
->dma_addr
, &vpath
->vp_reg
->stats_cfg
);
4872 status
= vxge_hw_vpath_stats_enable(vp
);
4873 if (status
!= VXGE_HW_OK
)
4874 goto vpath_open_exit8
;
4876 list_add(&vp
->item
, &vpath
->vpath_handles
);
4878 hldev
->vpaths_deployed
|= vxge_mBIT(vpath
->vp_id
);
4882 attr
->fifo_attr
.userdata
= vpath
->fifoh
;
4883 attr
->ring_attr
.userdata
= vpath
->ringh
;
4888 if (vpath
->ringh
!= NULL
)
4889 __vxge_hw_ring_delete(vp
);
4891 if (vpath
->fifoh
!= NULL
)
4892 __vxge_hw_fifo_delete(vp
);
4896 __vxge_hw_vp_terminate(hldev
, attr
->vp_id
);
4903 * vxge_hw_vpath_rx_doorbell_post - Close the handle got from previous vpath
4905 * @vp: Handle got from previous vpath open
4907 * This function is used to close access to virtual path opened
4910 void vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle
*vp
)
4912 struct __vxge_hw_virtualpath
*vpath
= vp
->vpath
;
4913 struct __vxge_hw_ring
*ring
= vpath
->ringh
;
4914 struct vxgedev
*vdev
= netdev_priv(vpath
->hldev
->ndev
);
4915 u64 new_count
, val64
, val164
;
4918 new_count
= readq(&vpath
->vp_reg
->rxdmem_size
);
4919 new_count
&= 0x1fff;
4921 new_count
= ring
->config
->ring_blocks
* VXGE_HW_BLOCK_SIZE
/ 8;
4923 val164
= VXGE_HW_RXDMEM_SIZE_PRC_RXDMEM_SIZE(new_count
);
4925 writeq(VXGE_HW_PRC_RXD_DOORBELL_NEW_QW_CNT(val164
),
4926 &vpath
->vp_reg
->prc_rxd_doorbell
);
4927 readl(&vpath
->vp_reg
->prc_rxd_doorbell
);
4930 val64
= readq(&vpath
->vp_reg
->prc_cfg6
);
4931 val64
= VXGE_HW_PRC_CFG6_RXD_SPAT(val64
);
4935 * Each RxD is of 4 qwords
4937 new_count
-= (val64
+ 1);
4938 val64
= min(val164
, new_count
) / 4;
4940 ring
->rxds_limit
= min(ring
->rxds_limit
, val64
);
4941 if (ring
->rxds_limit
< 4)
4942 ring
->rxds_limit
= 4;
4946 * __vxge_hw_blockpool_block_free - Frees a block from block pool
4948 * @entry: Entry of block to be freed
4950 * This function frees a block from block pool
4953 __vxge_hw_blockpool_block_free(struct __vxge_hw_device
*devh
,
4954 struct __vxge_hw_blockpool_entry
*entry
)
4956 struct __vxge_hw_blockpool
*blockpool
;
4958 blockpool
= &devh
->block_pool
;
4960 if (entry
->length
== blockpool
->block_size
) {
4961 list_add(&entry
->item
, &blockpool
->free_block_list
);
4962 blockpool
->pool_size
++;
4965 __vxge_hw_blockpool_blocks_remove(blockpool
);
4969 * vxge_hw_vpath_close - Close the handle got from previous vpath (vpath) open
4970 * This function is used to close access to virtual path opened
4973 enum vxge_hw_status
vxge_hw_vpath_close(struct __vxge_hw_vpath_handle
*vp
)
4975 struct __vxge_hw_virtualpath
*vpath
= NULL
;
4976 struct __vxge_hw_device
*devh
= NULL
;
4977 u32 vp_id
= vp
->vpath
->vp_id
;
4978 u32 is_empty
= TRUE
;
4979 enum vxge_hw_status status
= VXGE_HW_OK
;
4982 devh
= vpath
->hldev
;
4984 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
4985 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
4986 goto vpath_close_exit
;
4989 list_del(&vp
->item
);
4991 if (!list_empty(&vpath
->vpath_handles
)) {
4992 list_add(&vp
->item
, &vpath
->vpath_handles
);
4997 status
= VXGE_HW_FAIL
;
4998 goto vpath_close_exit
;
5001 devh
->vpaths_deployed
&= ~vxge_mBIT(vp_id
);
5003 if (vpath
->ringh
!= NULL
)
5004 __vxge_hw_ring_delete(vp
);
5006 if (vpath
->fifoh
!= NULL
)
5007 __vxge_hw_fifo_delete(vp
);
5009 if (vpath
->stats_block
!= NULL
)
5010 __vxge_hw_blockpool_block_free(devh
, vpath
->stats_block
);
5014 __vxge_hw_vp_terminate(devh
, vp_id
);
5021 * vxge_hw_vpath_reset - Resets vpath
5022 * This function is used to request a reset of vpath
5024 enum vxge_hw_status
vxge_hw_vpath_reset(struct __vxge_hw_vpath_handle
*vp
)
5026 enum vxge_hw_status status
;
5028 struct __vxge_hw_virtualpath
*vpath
= vp
->vpath
;
5030 vp_id
= vpath
->vp_id
;
5032 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
5033 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
5037 status
= __vxge_hw_vpath_reset(vpath
->hldev
, vp_id
);
5038 if (status
== VXGE_HW_OK
)
5039 vpath
->sw_stats
->soft_reset_cnt
++;
5045 * vxge_hw_vpath_recover_from_reset - Poll for reset complete and re-initialize.
5046 * This function poll's for the vpath reset completion and re initializes
5050 vxge_hw_vpath_recover_from_reset(struct __vxge_hw_vpath_handle
*vp
)
5052 struct __vxge_hw_virtualpath
*vpath
= NULL
;
5053 enum vxge_hw_status status
;
5054 struct __vxge_hw_device
*hldev
;
5057 vp_id
= vp
->vpath
->vp_id
;
5059 hldev
= vpath
->hldev
;
5061 if (vpath
->vp_open
== VXGE_HW_VP_NOT_OPEN
) {
5062 status
= VXGE_HW_ERR_VPATH_NOT_OPEN
;
5066 status
= __vxge_hw_vpath_reset_check(vpath
);
5067 if (status
!= VXGE_HW_OK
)
5070 status
= __vxge_hw_vpath_sw_reset(hldev
, vp_id
);
5071 if (status
!= VXGE_HW_OK
)
5074 status
= __vxge_hw_vpath_initialize(hldev
, vp_id
);
5075 if (status
!= VXGE_HW_OK
)
5078 if (vpath
->ringh
!= NULL
)
5079 __vxge_hw_vpath_prc_configure(hldev
, vp_id
);
5081 memset(vpath
->hw_stats
, 0,
5082 sizeof(struct vxge_hw_vpath_stats_hw_info
));
5084 memset(vpath
->hw_stats_sav
, 0,
5085 sizeof(struct vxge_hw_vpath_stats_hw_info
));
5087 writeq(vpath
->stats_block
->dma_addr
,
5088 &vpath
->vp_reg
->stats_cfg
);
5090 status
= vxge_hw_vpath_stats_enable(vp
);
5097 * vxge_hw_vpath_enable - Enable vpath.
5098 * This routine clears the vpath reset thereby enabling a vpath
5099 * to start forwarding frames and generating interrupts.
5102 vxge_hw_vpath_enable(struct __vxge_hw_vpath_handle
*vp
)
5104 struct __vxge_hw_device
*hldev
;
5107 hldev
= vp
->vpath
->hldev
;
5109 val64
= VXGE_HW_CMN_RSTHDLR_CFG1_CLR_VPATH_RESET(
5110 1 << (16 - vp
->vpath
->vp_id
));
5112 __vxge_hw_pio_mem_write32_upper((u32
)vxge_bVALn(val64
, 0, 32),
5113 &hldev
->common_reg
->cmn_rsthdlr_cfg1
);