5ff76b1447faeb72a6c91662c262d4dc9be4c2a1
[dpdk.git] / lib / librte_pmd_enic / vnic / vnic_rss.c
1 /*
2  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ident "$Id$"
35
36 #include "enic_compat.h"
37 #include "vnic_rss.h"
38
39 void vnic_set_rss_key(union vnic_rss_key *rss_key, u8 *key)
40 {
41         u32 i;
42         u32 *p;
43         u16 *q;
44
45         for (i = 0; i < 4; ++i) {
46                 p = (u32 *)(key + (10 * i));
47                 iowrite32(*p++, &rss_key->key[i].b[0]);
48                 iowrite32(*p++, &rss_key->key[i].b[4]);
49                 q = (u16 *)p;
50                 iowrite32(*q, &rss_key->key[i].b[8]);
51         }
52 }
53
54 void vnic_set_rss_cpu(union vnic_rss_cpu *rss_cpu, u8 *cpu)
55 {
56         u32 i;
57         u32 *p = (u32 *)cpu;
58
59         for (i = 0; i < 32; ++i)
60                 iowrite32(*p++, &rss_cpu->cpu[i].b[0]);
61 }
62
63 void vnic_get_rss_key(union vnic_rss_key *rss_key, u8 *key)
64 {
65         u32 i;
66         u32 *p;
67         u16 *q;
68
69         for (i = 0; i < 4; ++i) {
70                 p = (u32 *)(key + (10 * i));
71                 *p++ = ioread32(&rss_key->key[i].b[0]);
72                 *p++ = ioread32(&rss_key->key[i].b[4]);
73                 q = (u16 *)p;
74                 *q = (u16)ioread32(&rss_key->key[i].b[8]);
75         }
76 }
77
78 void vnic_get_rss_cpu(union vnic_rss_cpu *rss_cpu, u8 *cpu)
79 {
80         u32 i;
81         u32 *p = (u32 *)cpu;
82
83         for (i = 0; i < 32; ++i)
84                 *p++ = ioread32(&rss_cpu->cpu[i].b[0]);
85 }