xref: /freebsd-src/sys/dev/liquidio/lio_rss.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1*f173c2b7SSean Bruno /*
2*f173c2b7SSean Bruno  *   BSD LICENSE
3*f173c2b7SSean Bruno  *
4*f173c2b7SSean Bruno  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5*f173c2b7SSean Bruno  *   All rights reserved.
6*f173c2b7SSean Bruno  *
7*f173c2b7SSean Bruno  *   Redistribution and use in source and binary forms, with or without
8*f173c2b7SSean Bruno  *   modification, are permitted provided that the following conditions
9*f173c2b7SSean Bruno  *   are met:
10*f173c2b7SSean Bruno  *
11*f173c2b7SSean Bruno  *     * Redistributions of source code must retain the above copyright
12*f173c2b7SSean Bruno  *       notice, this list of conditions and the following disclaimer.
13*f173c2b7SSean Bruno  *     * Redistributions in binary form must reproduce the above copyright
14*f173c2b7SSean Bruno  *       notice, this list of conditions and the following disclaimer in
15*f173c2b7SSean Bruno  *       the documentation and/or other materials provided with the
16*f173c2b7SSean Bruno  *       distribution.
17*f173c2b7SSean Bruno  *     * Neither the name of Cavium, Inc. nor the names of its
18*f173c2b7SSean Bruno  *       contributors may be used to endorse or promote products derived
19*f173c2b7SSean Bruno  *       from this software without specific prior written permission.
20*f173c2b7SSean Bruno  *
21*f173c2b7SSean Bruno  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*f173c2b7SSean Bruno  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*f173c2b7SSean Bruno  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24*f173c2b7SSean Bruno  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25*f173c2b7SSean Bruno  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26*f173c2b7SSean Bruno  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27*f173c2b7SSean Bruno  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*f173c2b7SSean Bruno  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*f173c2b7SSean Bruno  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*f173c2b7SSean Bruno  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*f173c2b7SSean Bruno  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*f173c2b7SSean Bruno  */
33*f173c2b7SSean Bruno 
34*f173c2b7SSean Bruno #ifdef RSS
35*f173c2b7SSean Bruno 
36*f173c2b7SSean Bruno #include "lio_bsd.h"
37*f173c2b7SSean Bruno #include "lio_common.h"
38*f173c2b7SSean Bruno #include "lio_droq.h"
39*f173c2b7SSean Bruno #include "lio_iq.h"
40*f173c2b7SSean Bruno #include "lio_response_manager.h"
41*f173c2b7SSean Bruno #include "lio_device.h"
42*f173c2b7SSean Bruno #include "lio_ctrl.h"
43*f173c2b7SSean Bruno #include "lio_main.h"
44*f173c2b7SSean Bruno #include "lio_network.h"
45*f173c2b7SSean Bruno #include "lio_rss.h"
46*f173c2b7SSean Bruno 
47*f173c2b7SSean Bruno int	lio_send_rss_param(struct lio *lio);
48*f173c2b7SSean Bruno 
49*f173c2b7SSean Bruno static void
lio_set_rss_callback(struct octeon_device * oct,uint32_t status,void * arg)50*f173c2b7SSean Bruno lio_set_rss_callback(struct octeon_device *oct, uint32_t status, void *arg)
51*f173c2b7SSean Bruno {
52*f173c2b7SSean Bruno 	struct lio_soft_command	*sc = (struct lio_soft_command *)arg;
53*f173c2b7SSean Bruno 
54*f173c2b7SSean Bruno 	if (status)
55*f173c2b7SSean Bruno 		lio_dev_err(oct, "Failed to SET RSS params\n");
56*f173c2b7SSean Bruno 	else
57*f173c2b7SSean Bruno 		lio_dev_info(oct, "SET RSS params\n");
58*f173c2b7SSean Bruno 
59*f173c2b7SSean Bruno 	lio_free_soft_command(oct, sc);
60*f173c2b7SSean Bruno }
61*f173c2b7SSean Bruno 
62*f173c2b7SSean Bruno static void
lio_set_rss_info(struct lio * lio)63*f173c2b7SSean Bruno lio_set_rss_info(struct lio *lio)
64*f173c2b7SSean Bruno {
65*f173c2b7SSean Bruno 	struct octeon_device		*oct = lio->oct_dev;
66*f173c2b7SSean Bruno 	struct lio_rss_params_set	*rss_set = &lio->rss_set;
67*f173c2b7SSean Bruno 	uint32_t	rss_hash_config;
68*f173c2b7SSean Bruno 	int		i;
69*f173c2b7SSean Bruno 	uint8_t		queue_id;
70*f173c2b7SSean Bruno 
71*f173c2b7SSean Bruno 	for (i = 0; i < LIO_RSS_TABLE_SZ; i++) {
72*f173c2b7SSean Bruno 		queue_id = rss_get_indirection_to_bucket(i);
73*f173c2b7SSean Bruno 		queue_id = queue_id % oct->num_oqs;
74*f173c2b7SSean Bruno 		rss_set->fw_itable[i] = queue_id;
75*f173c2b7SSean Bruno 	}
76*f173c2b7SSean Bruno 
77*f173c2b7SSean Bruno 	rss_hash_config = rss_gethashconfig();
78*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_IPV4)
79*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_IPV4;
80*f173c2b7SSean Bruno 
81*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV4)
82*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_TCP_IPV4;
83*f173c2b7SSean Bruno 
84*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6)
85*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_IPV6;
86*f173c2b7SSean Bruno 
87*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6)
88*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_TCP_IPV6;
89*f173c2b7SSean Bruno 
90*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6_EX)
91*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_IPV6_EX;
92*f173c2b7SSean Bruno 
93*f173c2b7SSean Bruno 	if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6_EX)
94*f173c2b7SSean Bruno 		rss_set->hashinfo |= LIO_RSS_HASH_TCP_IPV6_EX;
95*f173c2b7SSean Bruno }
96*f173c2b7SSean Bruno 
97*f173c2b7SSean Bruno int
lio_send_rss_param(struct lio * lio)98*f173c2b7SSean Bruno lio_send_rss_param(struct lio *lio)
99*f173c2b7SSean Bruno {
100*f173c2b7SSean Bruno 	struct octeon_device	*oct = lio->oct_dev;
101*f173c2b7SSean Bruno 	struct lio_soft_command	*sc = NULL;
102*f173c2b7SSean Bruno 	union	octeon_cmd *cmd = NULL;
103*f173c2b7SSean Bruno 	struct lio_rss_params	*rss_param;
104*f173c2b7SSean Bruno 	int	i, retval;
105*f173c2b7SSean Bruno 
106*f173c2b7SSean Bruno 	sc = lio_alloc_soft_command(oct,
107*f173c2b7SSean Bruno 			OCTEON_CMD_SIZE + sizeof(struct lio_rss_params), 0, 0);
108*f173c2b7SSean Bruno 
109*f173c2b7SSean Bruno 	if (sc == NULL) {
110*f173c2b7SSean Bruno 		lio_dev_err(oct, "%s: Soft command allocation failed\n",
111*f173c2b7SSean Bruno 			    __func__);
112*f173c2b7SSean Bruno 		return (ENOMEM);
113*f173c2b7SSean Bruno 	}
114*f173c2b7SSean Bruno 
115*f173c2b7SSean Bruno 	sc->iq_no = lio->linfo.txpciq[0].s.q_no;
116*f173c2b7SSean Bruno 
117*f173c2b7SSean Bruno 	lio_prepare_soft_command(oct, sc, LIO_OPCODE_NIC, LIO_OPCODE_NIC_CMD, 0,
118*f173c2b7SSean Bruno 				 0, 0);
119*f173c2b7SSean Bruno 
120*f173c2b7SSean Bruno 	sc->callback = lio_set_rss_callback;
121*f173c2b7SSean Bruno 	sc->callback_arg = sc;
122*f173c2b7SSean Bruno 	sc->wait_time = 1000;
123*f173c2b7SSean Bruno 
124*f173c2b7SSean Bruno 	cmd = (union octeon_cmd *)sc->virtdptr;
125*f173c2b7SSean Bruno 	cmd->cmd64 = 0;
126*f173c2b7SSean Bruno 	cmd->s.cmd = LIO_CMD_SET_RSS;
127*f173c2b7SSean Bruno 
128*f173c2b7SSean Bruno 	rss_param = (struct lio_rss_params *)(cmd + 1);
129*f173c2b7SSean Bruno 	rss_param->param.flags = 0;
130*f173c2b7SSean Bruno 	rss_param->param.itablesize = LIO_RSS_TABLE_SZ;
131*f173c2b7SSean Bruno 	rss_param->param.hashkeysize = LIO_RSS_KEY_SZ;
132*f173c2b7SSean Bruno 
133*f173c2b7SSean Bruno 	lio_set_rss_info(lio);
134*f173c2b7SSean Bruno 	rss_param->param.hashinfo = lio->rss_set.hashinfo;
135*f173c2b7SSean Bruno 	memcpy(rss_param->itable, (void *)lio->rss_set.fw_itable,
136*f173c2b7SSean Bruno 	       (size_t)rss_param->param.itablesize);
137*f173c2b7SSean Bruno 
138*f173c2b7SSean Bruno 	lio_dev_info(oct, "RSS itable: Size %u\n", rss_param->param.itablesize);
139*f173c2b7SSean Bruno 	for (i = 0; i < rss_param->param.itablesize; i += 8) {
140*f173c2b7SSean Bruno 		lio_dev_dbg(oct, "   %03u:%2u, %03u:%2u, %03u:%2u, %03u:%2u, %03u:%2u, %03u:%2u, %03u:%2u, %03u:%2u\n",
141*f173c2b7SSean Bruno 			    i + 0, rss_param->itable[i + 0],
142*f173c2b7SSean Bruno 			    i + 1, rss_param->itable[i + 1],
143*f173c2b7SSean Bruno 			    i + 2, rss_param->itable[i + 2],
144*f173c2b7SSean Bruno 			    i + 3, rss_param->itable[i + 3],
145*f173c2b7SSean Bruno 			    i + 4, rss_param->itable[i + 4],
146*f173c2b7SSean Bruno 			    i + 5, rss_param->itable[i + 5],
147*f173c2b7SSean Bruno 			    i + 6, rss_param->itable[i + 6],
148*f173c2b7SSean Bruno 			    i + 7, rss_param->itable[i + 7]);
149*f173c2b7SSean Bruno 	}
150*f173c2b7SSean Bruno 
151*f173c2b7SSean Bruno 	rss_getkey(lio->rss_set.key);
152*f173c2b7SSean Bruno 
153*f173c2b7SSean Bruno 	memcpy(rss_param->key, (void *)lio->rss_set.key,
154*f173c2b7SSean Bruno 	       (size_t)rss_param->param.hashkeysize);
155*f173c2b7SSean Bruno 
156*f173c2b7SSean Bruno 	/* swap cmd and rss params */
157*f173c2b7SSean Bruno 	lio_swap_8B_data((uint64_t *)cmd,
158*f173c2b7SSean Bruno 			 ((OCTEON_CMD_SIZE + LIO_RSS_PARAM_SIZE) >> 3));
159*f173c2b7SSean Bruno 
160*f173c2b7SSean Bruno 	retval = lio_send_soft_command(oct, sc);
161*f173c2b7SSean Bruno 	if (retval == LIO_IQ_SEND_FAILED) {
162*f173c2b7SSean Bruno 		lio_dev_err(oct,
163*f173c2b7SSean Bruno 			    "%s: Sending soft command failed, status: %x\n",
164*f173c2b7SSean Bruno 			    __func__, retval);
165*f173c2b7SSean Bruno 		lio_free_soft_command(oct, sc);
166*f173c2b7SSean Bruno 		return (-1);
167*f173c2b7SSean Bruno 	}
168*f173c2b7SSean Bruno 
169*f173c2b7SSean Bruno 	return (0);
170*f173c2b7SSean Bruno }
171*f173c2b7SSean Bruno 
172*f173c2b7SSean Bruno #endif	/* RSS */
173