net/bnxt: modify TRUFLOW HWRM messages
[dpdk.git] / drivers / net / bnxt / tf_core / tf_msg.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #include <assert.h>
7 #include <inttypes.h>
8 #include <stdbool.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include "tf_em_common.h"
13 #include "tf_msg_common.h"
14 #include "tf_device.h"
15 #include "tf_msg.h"
16 #include "tf_util.h"
17 #include "tf_common.h"
18 #include "tf_session.h"
19 #include "tfp.h"
20 #include "tf_em.h"
21
22 /* Specific msg size defines as we cannot use defines in tf.yaml. This
23  * means we have to manually sync hwrm with these defines if the
24  * tf.yaml changes.
25  */
26 #define TF_MSG_SET_GLOBAL_CFG_DATA_SIZE  16
27 #define TF_MSG_EM_INSERT_KEY_SIZE        64
28 #define TF_MSG_EM_INSERT_RECORD_SIZE     80
29 #define TF_MSG_TBL_TYPE_SET_DATA_SIZE    88
30
31 /* Compile check - Catch any msg changes that we depend on, like the
32  * defines listed above for array size checking.
33  *
34  * Checking array size is dangerous in that the type could change and
35  * we wouldn't be able to catch it. Thus we check if the complete msg
36  * changed instead. Best we can do.
37  *
38  * If failure is observed then both msg size (defines below) and the
39  * array size (define above) should be checked and compared.
40  */
41 #define TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET 56
42 static_assert(sizeof(struct hwrm_tf_global_cfg_set_input) ==
43               TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET,
44               "HWRM message size changed: hwrm_tf_global_cfg_set_input");
45
46 #define TF_MSG_SIZE_HWRM_TF_EM_INSERT      104
47 static_assert(sizeof(struct hwrm_tf_em_insert_input) ==
48               TF_MSG_SIZE_HWRM_TF_EM_INSERT,
49               "HWRM message size changed: hwrm_tf_em_insert_input");
50
51 #define TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET   128
52 static_assert(sizeof(struct hwrm_tf_tbl_type_set_input) ==
53               TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET,
54               "HWRM message size changed: hwrm_tf_tbl_type_set_input");
55
56 /**
57  * This is the MAX data we can transport across regular HWRM
58  */
59 #define TF_PCI_BUF_SIZE_MAX 88
60
61 /**
62  * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
63  */
64 struct tf_msg_dma_buf {
65         void *va_addr;
66         uint64_t pa_addr;
67 };
68
69 /**
70  * Allocates a DMA buffer that can be used for message transfer.
71  *
72  * [in] buf
73  *   Pointer to DMA buffer structure
74  *
75  * [in] size
76  *   Requested size of the buffer in bytes
77  *
78  * Returns:
79  *    0      - Success
80  *   -ENOMEM - Unable to allocate buffer, no memory
81  */
82 static int
83 tf_msg_alloc_dma_buf(struct tf_msg_dma_buf *buf, int size)
84 {
85         struct tfp_calloc_parms alloc_parms;
86         int rc;
87
88         /* Allocate session */
89         alloc_parms.nitems = 1;
90         alloc_parms.size = size;
91         alloc_parms.alignment = 4096;
92         rc = tfp_calloc(&alloc_parms);
93         if (rc)
94                 return -ENOMEM;
95
96         buf->pa_addr = (uintptr_t)alloc_parms.mem_pa;
97         buf->va_addr = alloc_parms.mem_va;
98
99         return 0;
100 }
101
102 /**
103  * Free's a previous allocated DMA buffer.
104  *
105  * [in] buf
106  *   Pointer to DMA buffer structure
107  */
108 static void
109 tf_msg_free_dma_buf(struct tf_msg_dma_buf *buf)
110 {
111         tfp_free(buf->va_addr);
112 }
113
114 /* HWRM Direct messages */
115
116 int
117 tf_msg_session_open(struct tf *tfp,
118                     char *ctrl_chan_name,
119                     uint8_t *fw_session_id,
120                     uint8_t *fw_session_client_id,
121                     struct tf_dev_info *dev)
122 {
123         int rc;
124         struct hwrm_tf_session_open_input req = { 0 };
125         struct hwrm_tf_session_open_output resp = { 0 };
126         struct tfp_send_msg_parms parms = { 0 };
127
128         /* Populate the request */
129         tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
130
131         parms.tf_type = HWRM_TF_SESSION_OPEN;
132         parms.req_data = (uint32_t *)&req;
133         parms.req_size = sizeof(req);
134         parms.resp_data = (uint32_t *)&resp;
135         parms.resp_size = sizeof(resp);
136         parms.mailbox = dev->ops->tf_dev_get_mailbox();
137
138         rc = tfp_send_msg_direct(tfp,
139                                  &parms);
140         if (rc)
141                 return rc;
142
143         *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
144         *fw_session_client_id =
145                 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
146
147         return rc;
148 }
149
150 int
151 tf_msg_session_attach(struct tf *tfp __rte_unused,
152                       char *ctrl_chan_name __rte_unused,
153                       uint8_t tf_fw_session_id __rte_unused)
154 {
155         return -1;
156 }
157
158 int
159 tf_msg_session_client_register(struct tf *tfp,
160                                struct tf_session *tfs,
161                                char *ctrl_channel_name,
162                                uint8_t *fw_session_client_id)
163 {
164         int rc;
165         struct hwrm_tf_session_register_input req = { 0 };
166         struct hwrm_tf_session_register_output resp = { 0 };
167         struct tfp_send_msg_parms parms = { 0 };
168         uint8_t fw_session_id;
169         struct tf_dev_info *dev;
170
171         /* Retrieve the device information */
172         rc = tf_session_get_device(tfs, &dev);
173         if (rc) {
174                 TFP_DRV_LOG(ERR,
175                             "Failed to lookup device, rc:%s\n",
176                             strerror(-rc));
177                 return rc;
178         }
179
180         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
181         if (rc) {
182                 TFP_DRV_LOG(ERR,
183                             "Unable to lookup FW id, rc:%s\n",
184                             strerror(-rc));
185                 return rc;
186         }
187
188         /* Populate the request */
189         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
190         tfp_memcpy(&req.session_client_name,
191                    ctrl_channel_name,
192                    TF_SESSION_NAME_MAX);
193
194         parms.tf_type = HWRM_TF_SESSION_REGISTER;
195         parms.req_data = (uint32_t *)&req;
196         parms.req_size = sizeof(req);
197         parms.resp_data = (uint32_t *)&resp;
198         parms.resp_size = sizeof(resp);
199         parms.mailbox = dev->ops->tf_dev_get_mailbox();
200
201         rc = tfp_send_msg_direct(tfp,
202                                  &parms);
203         if (rc)
204                 return rc;
205
206         *fw_session_client_id =
207                 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
208
209         return rc;
210 }
211
212 int
213 tf_msg_session_client_unregister(struct tf *tfp,
214                                  struct tf_session *tfs,
215                                  uint8_t fw_session_client_id)
216 {
217         int rc;
218         struct hwrm_tf_session_unregister_input req = { 0 };
219         struct hwrm_tf_session_unregister_output resp = { 0 };
220         struct tfp_send_msg_parms parms = { 0 };
221         uint8_t fw_session_id;
222         struct tf_dev_info *dev;
223
224         /* Retrieve the device information */
225         rc = tf_session_get_device(tfs, &dev);
226         if (rc) {
227                 TFP_DRV_LOG(ERR,
228                             "Failed to lookup device, rc:%s\n",
229                             strerror(-rc));
230                 return rc;
231         }
232
233         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
234         if (rc) {
235                 TFP_DRV_LOG(ERR,
236                             "Unable to lookup FW id, rc:%s\n",
237                             strerror(-rc));
238                 return rc;
239         }
240
241         /* Populate the request */
242         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
243         req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
244
245         parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
246         parms.req_data = (uint32_t *)&req;
247         parms.req_size = sizeof(req);
248         parms.resp_data = (uint32_t *)&resp;
249         parms.resp_size = sizeof(resp);
250         parms.mailbox = dev->ops->tf_dev_get_mailbox();
251
252         rc = tfp_send_msg_direct(tfp,
253                                  &parms);
254
255         return rc;
256 }
257
258 int
259 tf_msg_session_close(struct tf *tfp,
260                      struct tf_session *tfs)
261 {
262         int rc;
263         struct hwrm_tf_session_close_input req = { 0 };
264         struct hwrm_tf_session_close_output resp = { 0 };
265         struct tfp_send_msg_parms parms = { 0 };
266         uint8_t fw_session_id;
267         struct tf_dev_info *dev;
268
269         /* Retrieve the device information */
270         rc = tf_session_get_device(tfs, &dev);
271         if (rc) {
272                 TFP_DRV_LOG(ERR,
273                             "Failed to lookup device, rc:%s\n",
274                             strerror(-rc));
275                 return rc;
276         }
277
278         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
279         if (rc) {
280                 TFP_DRV_LOG(ERR,
281                             "Unable to lookup FW id, rc:%s\n",
282                             strerror(-rc));
283                 return rc;
284         }
285
286         /* Populate the request */
287         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
288
289         parms.tf_type = HWRM_TF_SESSION_CLOSE;
290         parms.req_data = (uint32_t *)&req;
291         parms.req_size = sizeof(req);
292         parms.resp_data = (uint32_t *)&resp;
293         parms.resp_size = sizeof(resp);
294         parms.mailbox = dev->ops->tf_dev_get_mailbox();
295
296         rc = tfp_send_msg_direct(tfp,
297                                  &parms);
298         return rc;
299 }
300
301 int
302 tf_msg_session_qcfg(struct tf *tfp)
303 {
304         int rc;
305         struct hwrm_tf_session_qcfg_input req = { 0 };
306         struct hwrm_tf_session_qcfg_output resp = { 0 };
307         struct tfp_send_msg_parms parms = { 0 };
308         uint8_t fw_session_id;
309         struct tf_dev_info *dev;
310         struct tf_session *tfs;
311
312         /* Retrieve the session information */
313         rc = tf_session_get_session_internal(tfp, &tfs);
314         if (rc) {
315                 TFP_DRV_LOG(ERR,
316                             "Failed to lookup session, rc:%s\n",
317                             strerror(-rc));
318                 return rc;
319         }
320
321         /* Retrieve the device information */
322         rc = tf_session_get_device(tfs, &dev);
323         if (rc) {
324                 TFP_DRV_LOG(ERR,
325                             "Failed to lookup device, rc:%s\n",
326                             strerror(-rc));
327                 return rc;
328         }
329
330         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
331         if (rc) {
332                 TFP_DRV_LOG(ERR,
333                             "Unable to lookup FW id, rc:%s\n",
334                             strerror(-rc));
335                 return rc;
336         }
337
338         /* Populate the request */
339         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
340
341         parms.tf_type = HWRM_TF_SESSION_QCFG,
342         parms.req_data = (uint32_t *)&req;
343         parms.req_size = sizeof(req);
344         parms.resp_data = (uint32_t *)&resp;
345         parms.resp_size = sizeof(resp);
346         parms.mailbox = dev->ops->tf_dev_get_mailbox();
347
348         rc = tfp_send_msg_direct(tfp,
349                                  &parms);
350         return rc;
351 }
352
353 int
354 tf_msg_session_resc_qcaps(struct tf *tfp,
355                           struct tf_dev_info *dev,
356                           enum tf_dir dir,
357                           uint16_t size,
358                           struct tf_rm_resc_req_entry *query,
359                           enum tf_rm_resc_resv_strategy *resv_strategy)
360 {
361         int rc;
362         int i;
363         struct tfp_send_msg_parms parms = { 0 };
364         struct hwrm_tf_session_resc_qcaps_input req = { 0 };
365         struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
366         uint8_t fw_session_id;
367         struct tf_msg_dma_buf qcaps_buf = { 0 };
368         struct tf_rm_resc_req_entry *data;
369         int dma_size;
370
371         TF_CHECK_PARMS3(tfp, query, resv_strategy);
372
373         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
374         if (rc) {
375                 TFP_DRV_LOG(ERR,
376                             "%s: Unable to lookup FW id, rc:%s\n",
377                             tf_dir_2_str(dir),
378                             strerror(-rc));
379                 return rc;
380         }
381
382         /* Prepare DMA buffer */
383         dma_size = size * sizeof(struct tf_rm_resc_req_entry);
384         rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
385         if (rc)
386                 return rc;
387
388         /* Populate the request */
389         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
390         req.flags = tfp_cpu_to_le_16(dir);
391         req.qcaps_size = size;
392         req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
393
394         parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
395         parms.req_data = (uint32_t *)&req;
396         parms.req_size = sizeof(req);
397         parms.resp_data = (uint32_t *)&resp;
398         parms.resp_size = sizeof(resp);
399         parms.mailbox = dev->ops->tf_dev_get_mailbox();
400
401         rc = tfp_send_msg_direct(tfp, &parms);
402         if (rc)
403                 goto cleanup;
404
405         /* Process the response
406          * Should always get expected number of entries
407          */
408         if (tfp_le_to_cpu_32(resp.size) != size) {
409                 TFP_DRV_LOG(ERR,
410                             "%s: QCAPS message size error, rc:%s\n",
411                             tf_dir_2_str(dir),
412                             strerror(EINVAL));
413                 rc = -EINVAL;
414                 goto cleanup;
415         }
416
417         /* Post process the response */
418         data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
419         for (i = 0; i < size; i++) {
420                 query[i].type = tfp_le_to_cpu_32(data[i].type);
421                 query[i].min = tfp_le_to_cpu_16(data[i].min);
422                 query[i].max = tfp_le_to_cpu_16(data[i].max);
423         }
424
425         *resv_strategy = resp.flags &
426               HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
427
428 cleanup:
429         tf_msg_free_dma_buf(&qcaps_buf);
430
431         return rc;
432 }
433
434 int
435 tf_msg_session_resc_alloc(struct tf *tfp,
436                           struct tf_dev_info *dev,
437                           enum tf_dir dir,
438                           uint16_t size,
439                           struct tf_rm_resc_req_entry *request,
440                           struct tf_rm_resc_entry *resv)
441 {
442         int rc;
443         int i;
444         struct tfp_send_msg_parms parms = { 0 };
445         struct hwrm_tf_session_resc_alloc_input req = { 0 };
446         struct hwrm_tf_session_resc_alloc_output resp = { 0 };
447         uint8_t fw_session_id;
448         struct tf_msg_dma_buf req_buf = { 0 };
449         struct tf_msg_dma_buf resv_buf = { 0 };
450         struct tf_rm_resc_req_entry *req_data;
451         struct tf_rm_resc_entry *resv_data;
452         int dma_size;
453
454         TF_CHECK_PARMS3(tfp, request, resv);
455
456         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
457         if (rc) {
458                 TFP_DRV_LOG(ERR,
459                             "%s: Unable to lookup FW id, rc:%s\n",
460                             tf_dir_2_str(dir),
461                             strerror(-rc));
462                 return rc;
463         }
464
465         /* Prepare DMA buffers */
466         dma_size = size * sizeof(struct tf_rm_resc_req_entry);
467         rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
468         if (rc)
469                 return rc;
470
471         dma_size = size * sizeof(struct tf_rm_resc_entry);
472         rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
473         if (rc) {
474                 tf_msg_free_dma_buf(&req_buf);
475                 return rc;
476         }
477
478         /* Populate the request */
479         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
480         req.flags = tfp_cpu_to_le_16(dir);
481         req.req_size = size;
482
483         req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
484         for (i = 0; i < size; i++) {
485                 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
486                 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
487                 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
488         }
489
490         req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
491         req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
492
493         parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
494         parms.req_data = (uint32_t *)&req;
495         parms.req_size = sizeof(req);
496         parms.resp_data = (uint32_t *)&resp;
497         parms.resp_size = sizeof(resp);
498         parms.mailbox = dev->ops->tf_dev_get_mailbox();
499
500         rc = tfp_send_msg_direct(tfp, &parms);
501         if (rc)
502                 goto cleanup;
503
504         /* Process the response
505          * Should always get expected number of entries
506          */
507         if (tfp_le_to_cpu_32(resp.size) != size) {
508                 TFP_DRV_LOG(ERR,
509                             "%s: Alloc message size error, rc:%s\n",
510                             tf_dir_2_str(dir),
511                             strerror(EINVAL));
512                 rc = -EINVAL;
513                 goto cleanup;
514         }
515
516         /* Post process the response */
517         resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
518         for (i = 0; i < size; i++) {
519                 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
520                 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
521                 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
522         }
523
524 cleanup:
525         tf_msg_free_dma_buf(&req_buf);
526         tf_msg_free_dma_buf(&resv_buf);
527
528         return rc;
529 }
530
531 int
532 tf_msg_session_resc_flush(struct tf *tfp,
533                           enum tf_dir dir,
534                           uint16_t size,
535                           struct tf_rm_resc_entry *resv)
536 {
537         int rc;
538         int i;
539         struct tfp_send_msg_parms parms = { 0 };
540         struct hwrm_tf_session_resc_flush_input req = { 0 };
541         struct hwrm_tf_session_resc_flush_output resp = { 0 };
542         uint8_t fw_session_id;
543         struct tf_msg_dma_buf resv_buf = { 0 };
544         struct tf_rm_resc_entry *resv_data;
545         int dma_size;
546         struct tf_dev_info *dev;
547         struct tf_session *tfs;
548
549         TF_CHECK_PARMS2(tfp, resv);
550
551         /* Retrieve the session information */
552         rc = tf_session_get_session_internal(tfp, &tfs);
553         if (rc) {
554                 TFP_DRV_LOG(ERR,
555                             "%s: Failed to lookup session, rc:%s\n",
556                             tf_dir_2_str(dir),
557                             strerror(-rc));
558                 return rc;
559         }
560
561         /* Retrieve the device information */
562         rc = tf_session_get_device(tfs, &dev);
563         if (rc) {
564                 TFP_DRV_LOG(ERR,
565                             "%s: Failed to lookup device, rc:%s\n",
566                             tf_dir_2_str(dir),
567                             strerror(-rc));
568                 return rc;
569         }
570
571         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
572         if (rc) {
573                 TFP_DRV_LOG(ERR,
574                             "%s: Unable to lookup FW id, rc:%s\n",
575                             tf_dir_2_str(dir),
576                             strerror(-rc));
577                 return rc;
578         }
579
580         /* Prepare DMA buffers */
581         dma_size = size * sizeof(struct tf_rm_resc_entry);
582         rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
583         if (rc)
584                 return rc;
585
586         /* Populate the request */
587         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
588         req.flags = tfp_cpu_to_le_16(dir);
589         req.flush_size = size;
590
591         resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
592         for (i = 0; i < size; i++) {
593                 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
594                 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
595                 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
596         }
597
598         req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
599
600         parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
601         parms.req_data = (uint32_t *)&req;
602         parms.req_size = sizeof(req);
603         parms.resp_data = (uint32_t *)&resp;
604         parms.resp_size = sizeof(resp);
605         parms.mailbox = dev->ops->tf_dev_get_mailbox();
606
607         rc = tfp_send_msg_direct(tfp, &parms);
608
609         tf_msg_free_dma_buf(&resv_buf);
610
611         return rc;
612 }
613
614 int
615 tf_msg_insert_em_internal_entry(struct tf *tfp,
616                                 struct tf_insert_em_entry_parms *em_parms,
617                                 uint16_t *rptr_index,
618                                 uint8_t *rptr_entry,
619                                 uint8_t *num_of_entries)
620 {
621         int rc;
622         struct tfp_send_msg_parms parms = { 0 };
623         struct hwrm_tf_em_insert_input req = { 0 };
624         struct hwrm_tf_em_insert_output resp = { 0 };
625         struct tf_em_64b_entry *em_result =
626                 (struct tf_em_64b_entry *)em_parms->em_record;
627         uint16_t flags;
628         uint8_t fw_session_id;
629         uint8_t msg_key_size;
630         struct tf_dev_info *dev;
631         struct tf_session *tfs;
632
633         RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
634                          TF_MSG_SIZE_HWRM_TF_EM_INSERT);
635
636         /* Retrieve the session information */
637         rc = tf_session_get_session_internal(tfp, &tfs);
638         if (rc) {
639                 TFP_DRV_LOG(ERR,
640                             "%s: Failed to lookup session, rc:%s\n",
641                             tf_dir_2_str(em_parms->dir),
642                             strerror(-rc));
643                 return rc;
644         }
645
646         /* Retrieve the device information */
647         rc = tf_session_get_device(tfs, &dev);
648         if (rc) {
649                 TFP_DRV_LOG(ERR,
650                             "%s: Failed to lookup device, rc:%s\n",
651                             tf_dir_2_str(em_parms->dir),
652                             strerror(-rc));
653                 return rc;
654         }
655
656         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
657         if (rc) {
658                 TFP_DRV_LOG(ERR,
659                             "%s: Unable to lookup FW id, rc:%s\n",
660                             tf_dir_2_str(em_parms->dir),
661                             strerror(-rc));
662                 return rc;
663         }
664
665         /* Populate the request */
666         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
667
668         /* Check for key size conformity */
669         msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
670         if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
671                 rc = -EINVAL;
672                 TFP_DRV_LOG(ERR,
673                             "%s: Invalid parameters for msg type, rc:%s\n",
674                             tf_dir_2_str(em_parms->dir),
675                             strerror(-rc));
676                 return rc;
677         }
678
679         tfp_memcpy(req.em_key,
680                    em_parms->key,
681                    msg_key_size);
682
683         flags = (em_parms->dir == TF_DIR_TX ?
684                  HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
685                  HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
686         req.flags = tfp_cpu_to_le_16(flags);
687         req.strength = (em_result->hdr.word1 &
688                         CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
689                         CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
690         req.em_key_bitlen = em_parms->key_sz_in_bits;
691         req.action_ptr = em_result->hdr.pointer;
692         req.em_record_idx = *rptr_index;
693
694         parms.tf_type = HWRM_TF_EM_INSERT;
695         parms.req_data = (uint32_t *)&req;
696         parms.req_size = sizeof(req);
697         parms.resp_data = (uint32_t *)&resp;
698         parms.resp_size = sizeof(resp);
699         parms.mailbox = dev->ops->tf_dev_get_mailbox();
700
701         rc = tfp_send_msg_direct(tfp,
702                                  &parms);
703         if (rc)
704                 return rc;
705
706         *rptr_entry = resp.rptr_entry;
707         *rptr_index = resp.rptr_index;
708         *num_of_entries = resp.num_of_entries;
709
710         return 0;
711 }
712
713 int
714 tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
715                                      struct tf_insert_em_entry_parms *em_parms,
716                                      uint32_t key0_hash,
717                                      uint32_t key1_hash,
718                                      uint16_t *rptr_index,
719                                      uint8_t *rptr_entry,
720                                      uint8_t *num_of_entries)
721 {
722         int rc;
723         struct tfp_send_msg_parms parms = { 0 };
724         struct hwrm_tf_em_hash_insert_input req = { 0 };
725         struct hwrm_tf_em_hash_insert_output resp = { 0 };
726         uint16_t flags;
727         uint8_t fw_session_id;
728         uint8_t msg_record_size;
729         struct tf_dev_info *dev;
730         struct tf_session *tfs;
731
732         /* Retrieve the session information */
733         rc = tf_session_get_session_internal(tfp, &tfs);
734         if (rc) {
735                 TFP_DRV_LOG(ERR,
736                             "%s: Failed to lookup session, rc:%s\n",
737                             tf_dir_2_str(em_parms->dir),
738                             strerror(-rc));
739                 return rc;
740         }
741
742         /* Retrieve the device information */
743         rc = tf_session_get_device(tfs, &dev);
744         if (rc) {
745                 TFP_DRV_LOG(ERR,
746                             "%s: Failed to lookup device, rc:%s\n",
747                             tf_dir_2_str(em_parms->dir),
748                             strerror(-rc));
749                 return rc;
750         }
751
752         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
753         if (rc) {
754                 TFP_DRV_LOG(ERR,
755                             "%s: Unable to lookup FW id, rc:%s\n",
756                             tf_dir_2_str(em_parms->dir),
757                             strerror(-rc));
758                 return rc;
759         }
760
761         /* Populate the request */
762         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
763
764         /* Check for key size conformity */
765         msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
766
767         if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
768                 rc = -EINVAL;
769                 TFP_DRV_LOG(ERR,
770                             "%s: Record size to large, rc:%s\n",
771                             tf_dir_2_str(em_parms->dir),
772                             strerror(-rc));
773                 return rc;
774         }
775
776         tfp_memcpy((char *)req.em_record,
777                    em_parms->em_record,
778                    msg_record_size);
779
780         flags = (em_parms->dir == TF_DIR_TX ?
781                  HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
782                  HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
783         req.flags = tfp_cpu_to_le_16(flags);
784         req.em_record_size_bits = em_parms->em_record_sz_in_bits;
785         req.em_record_idx = *rptr_index;
786         req.key0_hash = key0_hash;
787         req.key1_hash = key1_hash;
788
789         parms.tf_type = HWRM_TF_EM_HASH_INSERT;
790         parms.req_data = (uint32_t *)&req;
791         parms.req_size = sizeof(req);
792         parms.resp_data = (uint32_t *)&resp;
793         parms.resp_size = sizeof(resp);
794         parms.mailbox = dev->ops->tf_dev_get_mailbox();
795
796         rc = tfp_send_msg_direct(tfp,
797                                  &parms);
798         if (rc)
799                 return rc;
800
801         *rptr_entry = resp.rptr_entry;
802         *rptr_index = resp.rptr_index;
803         *num_of_entries = resp.num_of_entries;
804
805         return 0;
806 }
807
808 int
809 tf_msg_delete_em_entry(struct tf *tfp,
810                        struct tf_delete_em_entry_parms *em_parms)
811 {
812         int rc;
813         struct tfp_send_msg_parms parms = { 0 };
814         struct hwrm_tf_em_delete_input req = { 0 };
815         struct hwrm_tf_em_delete_output resp = { 0 };
816         uint16_t flags;
817         uint8_t fw_session_id;
818         struct tf_dev_info *dev;
819         struct tf_session *tfs;
820
821         /* Retrieve the session information */
822         rc = tf_session_get_session_internal(tfp, &tfs);
823         if (rc) {
824                 TFP_DRV_LOG(ERR,
825                             "%s: Failed to lookup session, rc:%s\n",
826                             tf_dir_2_str(em_parms->dir),
827                             strerror(-rc));
828                 return rc;
829         }
830
831         /* Retrieve the device information */
832         rc = tf_session_get_device(tfs, &dev);
833         if (rc) {
834                 TFP_DRV_LOG(ERR,
835                             "%s: Failed to lookup device, rc:%s\n",
836                             tf_dir_2_str(em_parms->dir),
837                             strerror(-rc));
838                 return rc;
839         }
840
841         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
842         if (rc) {
843                 TFP_DRV_LOG(ERR,
844                             "%s: Unable to lookup FW id, rc:%s\n",
845                             tf_dir_2_str(em_parms->dir),
846                             strerror(-rc));
847                 return rc;
848         }
849
850         /* Populate the request */
851         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
852
853         flags = (em_parms->dir == TF_DIR_TX ?
854                  HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
855                  HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
856         req.flags = tfp_cpu_to_le_16(flags);
857         req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
858
859         parms.tf_type = HWRM_TF_EM_DELETE;
860         parms.req_data = (uint32_t *)&req;
861         parms.req_size = sizeof(req);
862         parms.resp_data = (uint32_t *)&resp;
863         parms.resp_size = sizeof(resp);
864         parms.mailbox = dev->ops->tf_dev_get_mailbox();
865
866         rc = tfp_send_msg_direct(tfp,
867                                  &parms);
868         if (rc)
869                 return rc;
870
871         em_parms->index = tfp_le_to_cpu_16(resp.em_index);
872
873         return 0;
874 }
875
876 int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
877                                 struct hcapi_cfa_em_table *tbl,
878                                 uint64_t *dma_addr,
879                                 uint32_t *page_lvl,
880                                 uint32_t *page_size)
881 {
882         struct tfp_send_msg_parms parms = { 0 };
883         struct hwrm_tf_ctxt_mem_alloc_input req = {0};
884         struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
885         uint32_t mem_size_k;
886         int rc = 0;
887         struct tf_dev_info *dev;
888         struct tf_session *tfs;
889         uint32_t fw_se_id;
890
891         /* Retrieve the session information */
892         rc = tf_session_get_session_internal(tfp, &tfs);
893         if (rc) {
894                 TFP_DRV_LOG(ERR,
895                             "Failed to lookup session, rc:%s\n",
896                             strerror(-rc));
897                 return rc;
898         }
899
900         /* Retrieve the device information */
901         rc = tf_session_get_device(tfs, &dev);
902         if (rc) {
903                 TFP_DRV_LOG(ERR,
904                             "Failed to lookup device, rc:%s\n",
905                             strerror(-rc));
906                 return rc;
907         }
908         /* Retrieve the session information */
909         fw_se_id = tfs->session_id.internal.fw_session_id;
910
911         if (tbl->num_entries && tbl->entry_size) {
912                 /* unit: kbytes */
913                 mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
914                 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
915                 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
916                 parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
917                 parms.req_data = (uint32_t *)&req;
918                 parms.req_size = sizeof(req);
919                 parms.resp_data = (uint32_t *)&resp;
920                 parms.resp_size = sizeof(resp);
921                 parms.mailbox = dev->ops->tf_dev_get_mailbox();
922                 rc = tfp_send_msg_direct(tfp, &parms);
923                 if (rc) {
924                         TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
925                                 strerror(-rc));
926                         return rc;
927                 }
928
929                 *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
930                 *page_lvl = resp.page_level;
931                 *page_size = resp.page_size;
932         }
933
934         return rc;
935 }
936
937 int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
938                                 uint32_t mem_size_k,
939                                 uint64_t dma_addr,
940                                 uint8_t page_level,
941                                 uint8_t page_size)
942 {
943         struct tfp_send_msg_parms parms = { 0 };
944         struct hwrm_tf_ctxt_mem_free_input req = {0};
945         struct hwrm_tf_ctxt_mem_free_output resp = {0};
946         int rc = 0;
947         struct tf_dev_info *dev;
948         struct tf_session *tfs;
949         uint32_t fw_se_id;
950
951         /* Retrieve the session information */
952         rc = tf_session_get_session_internal(tfp, &tfs);
953         if (rc) {
954                 TFP_DRV_LOG(ERR,
955                             "Failed to lookup session, rc:%s\n",
956                             strerror(-rc));
957                 return rc;
958         }
959
960         /* Retrieve the device information */
961         rc = tf_session_get_device(tfs, &dev);
962         if (rc) {
963                 TFP_DRV_LOG(ERR,
964                             "Failed to lookup device, rc:%s\n",
965                             strerror(-rc));
966                 return rc;
967         }
968         /* Retrieve the session information */
969         fw_se_id = tfs->session_id.internal.fw_session_id;
970
971         req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
972         req.mem_size = tfp_cpu_to_le_32(mem_size_k);
973         req.page_dir = tfp_cpu_to_le_64(dma_addr);
974         req.page_level = page_level;
975         req.page_size = page_size;
976         parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
977         parms.req_data = (uint32_t *)&req;
978         parms.req_size = sizeof(req);
979         parms.resp_data = (uint32_t *)&resp;
980         parms.resp_size = sizeof(resp);
981         parms.mailbox = dev->ops->tf_dev_get_mailbox();
982         rc = tfp_send_msg_direct(tfp, &parms);
983
984         return rc;
985 }
986
987 int
988 tf_msg_em_mem_rgtr(struct tf *tfp,
989                    int page_lvl,
990                    int page_size,
991                    uint64_t dma_addr,
992                    uint16_t *ctx_id)
993 {
994         int rc;
995         struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
996         struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
997         struct tfp_send_msg_parms parms = { 0 };
998         struct tf_dev_info *dev;
999         struct tf_session *tfs;
1000         uint32_t fw_se_id;
1001
1002         /* Retrieve the session information */
1003         rc = tf_session_get_session_internal(tfp, &tfs);
1004         if (rc) {
1005                 TFP_DRV_LOG(ERR,
1006                             "Failed to lookup session, rc:%s\n",
1007                             strerror(-rc));
1008                 return rc;
1009         }
1010
1011         /* Retrieve the device information */
1012         rc = tf_session_get_device(tfs, &dev);
1013         if (rc) {
1014                 TFP_DRV_LOG(ERR,
1015                             "Failed to lookup device, rc:%s\n",
1016                             strerror(-rc));
1017                 return rc;
1018         }
1019         fw_se_id = tfs->session_id.internal.fw_session_id;
1020
1021         req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1022         req.page_level = page_lvl;
1023         req.page_size = page_size;
1024         req.page_dir = tfp_cpu_to_le_64(dma_addr);
1025
1026         parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1027         parms.req_data = (uint32_t *)&req;
1028         parms.req_size = sizeof(req);
1029         parms.resp_data = (uint32_t *)&resp;
1030         parms.resp_size = sizeof(resp);
1031         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1032
1033         rc = tfp_send_msg_direct(tfp,
1034                                  &parms);
1035         if (rc)
1036                 return rc;
1037
1038         *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1039
1040         return rc;
1041 }
1042
1043 int
1044 tf_msg_em_mem_unrgtr(struct tf *tfp,
1045                      uint16_t *ctx_id)
1046 {
1047         int rc;
1048         struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1049         struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1050         struct tfp_send_msg_parms parms = { 0 };
1051         struct tf_dev_info *dev;
1052         struct tf_session *tfs;
1053         uint32_t fw_se_id;
1054
1055         /* Retrieve the session information */
1056         rc = tf_session_get_session_internal(tfp, &tfs);
1057         if (rc) {
1058                 TFP_DRV_LOG(ERR,
1059                             "Failed to lookup session, rc:%s\n",
1060                             strerror(-rc));
1061                 return rc;
1062         }
1063
1064         /* Retrieve the device information */
1065         rc = tf_session_get_device(tfs, &dev);
1066         if (rc) {
1067                 TFP_DRV_LOG(ERR,
1068                             "Failed to lookup device, rc:%s\n",
1069                             strerror(-rc));
1070                 return rc;
1071         }
1072
1073         fw_se_id = tfs->session_id.internal.fw_session_id;
1074         req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1075
1076         req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1077
1078         parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1079         parms.req_data = (uint32_t *)&req;
1080         parms.req_size = sizeof(req);
1081         parms.resp_data = (uint32_t *)&resp;
1082         parms.resp_size = sizeof(resp);
1083         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1084
1085         rc = tfp_send_msg_direct(tfp,
1086                                  &parms);
1087         return rc;
1088 }
1089
1090 int
1091 tf_msg_em_qcaps(struct tf *tfp,
1092                 int dir,
1093                 struct tf_em_caps *em_caps)
1094 {
1095         int rc;
1096         struct hwrm_tf_ext_em_qcaps_input  req = {0};
1097         struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1098         uint32_t             flags;
1099         struct tfp_send_msg_parms parms = { 0 };
1100         struct tf_dev_info *dev;
1101         struct tf_session *tfs;
1102         uint32_t fw_se_id;
1103
1104         /* Retrieve the session information */
1105         rc = tf_session_get_session_internal(tfp, &tfs);
1106         if (rc) {
1107                 TFP_DRV_LOG(ERR,
1108                             "%s: Failed to lookup session, rc:%s\n",
1109                             tf_dir_2_str(dir),
1110                             strerror(-rc));
1111                 return rc;
1112         }
1113         fw_se_id = tfs->session_id.internal.fw_session_id;
1114
1115         /* Retrieve the device information */
1116         rc = tf_session_get_device(tfs, &dev);
1117         if (rc) {
1118                 TFP_DRV_LOG(ERR,
1119                             "%s: Failed to lookup device, rc:%s\n",
1120                             tf_dir_2_str(dir),
1121                             strerror(-rc));
1122                 return rc;
1123         }
1124
1125         flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1126                  HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1127         req.flags = tfp_cpu_to_le_32(flags);
1128
1129         parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1130         req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1131         parms.req_data = (uint32_t *)&req;
1132         parms.req_size = sizeof(req);
1133         parms.resp_data = (uint32_t *)&resp;
1134         parms.resp_size = sizeof(resp);
1135         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1136
1137         rc = tfp_send_msg_direct(tfp,
1138                                  &parms);
1139         if (rc)
1140                 return rc;
1141
1142         em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1143         em_caps->max_entries_supported =
1144                 tfp_le_to_cpu_32(resp.max_entries_supported);
1145         em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1146         em_caps->record_entry_size =
1147                 tfp_le_to_cpu_16(resp.record_entry_size);
1148         em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1149
1150         return rc;
1151 }
1152
1153 int
1154 tf_msg_em_cfg(struct tf *tfp,
1155               uint32_t num_entries,
1156               uint16_t key0_ctx_id,
1157               uint16_t key1_ctx_id,
1158               uint16_t record_ctx_id,
1159               uint16_t efc_ctx_id,
1160               uint8_t flush_interval,
1161               int dir)
1162 {
1163         int rc;
1164         struct hwrm_tf_ext_em_cfg_input  req = {0};
1165         struct hwrm_tf_ext_em_cfg_output resp = {0};
1166         uint32_t flags;
1167         struct tfp_send_msg_parms parms = { 0 };
1168         struct tf_dev_info *dev;
1169         struct tf_session *tfs;
1170
1171         /* Retrieve the session information */
1172         rc = tf_session_get_session_internal(tfp, &tfs);
1173         if (rc) {
1174                 TFP_DRV_LOG(ERR,
1175                             "%s: Failed to lookup session, rc:%s\n",
1176                             tf_dir_2_str(dir),
1177                             strerror(-rc));
1178                 return rc;
1179         }
1180
1181         /* Retrieve the device information */
1182         rc = tf_session_get_device(tfs, &dev);
1183         if (rc) {
1184                 TFP_DRV_LOG(ERR,
1185                             "%s: Failed to lookup device, rc:%s\n",
1186                             tf_dir_2_str(dir),
1187                             strerror(-rc));
1188                 return rc;
1189         }
1190
1191         flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1192                  HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1193         flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1194
1195         req.flags = tfp_cpu_to_le_32(flags);
1196         req.num_entries = tfp_cpu_to_le_32(num_entries);
1197
1198         req.flush_interval = flush_interval;
1199
1200         req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1201         req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1202         req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1203         req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1204
1205         parms.tf_type = HWRM_TF_EXT_EM_CFG;
1206         parms.req_data = (uint32_t *)&req;
1207         parms.req_size = sizeof(req);
1208         parms.resp_data = (uint32_t *)&resp;
1209         parms.resp_size = sizeof(resp);
1210         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1211
1212         rc = tfp_send_msg_direct(tfp,
1213                                  &parms);
1214         return rc;
1215 }
1216
1217 int
1218 tf_msg_ext_em_cfg(struct tf *tfp,
1219                   struct tf_tbl_scope_cb *tbl_scope_cb,
1220                   uint32_t st_buckets,
1221                   uint8_t flush_interval,
1222                   enum tf_dir dir)
1223 {
1224         struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1225         struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1226         struct hwrm_tf_ext_em_cfg_input  req = {0};
1227         struct hwrm_tf_ext_em_cfg_output resp = {0};
1228         struct tfp_send_msg_parms parms = { 0 };
1229         uint32_t flags;
1230         struct tf_dev_info *dev;
1231         struct tf_session *tfs;
1232         uint32_t fw_se_id;
1233         int rc;
1234
1235         /* Retrieve the session information */
1236         rc = tf_session_get_session_internal(tfp, &tfs);
1237         if (rc) {
1238                 TFP_DRV_LOG(ERR,
1239                             "%s: Failed to lookup session, rc:%s\n",
1240                             tf_dir_2_str(dir),
1241                             strerror(-rc));
1242                 return rc;
1243         }
1244
1245         /* Retrieve the device information */
1246         rc = tf_session_get_device(tfs, &dev);
1247         if (rc) {
1248                 TFP_DRV_LOG(ERR,
1249                             "%s: Failed to lookup device, rc:%s\n",
1250                             tf_dir_2_str(dir),
1251                             strerror(-rc));
1252                 return rc;
1253         }
1254         fw_se_id = tfs->session_id.internal.fw_session_id;
1255
1256         lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1257         act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1258         flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1259                  HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1260         flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1261
1262         req.flags = tfp_cpu_to_le_32(flags);
1263         req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1264         req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1265         req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1266         req.flush_interval = flush_interval;
1267         req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1268         req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1269         req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1270         req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1271
1272         req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1273                        HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1274                        HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1275                        HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1276                        HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1277                        HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1278
1279         parms.tf_type = HWRM_TF_EXT_EM_CFG;
1280         parms.req_data = (uint32_t *)&req;
1281         parms.req_size = sizeof(req);
1282         parms.resp_data = (uint32_t *)&resp;
1283         parms.resp_size = sizeof(resp);
1284         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1285
1286         rc = tfp_send_msg_direct(tfp,
1287                                  &parms);
1288         return rc;
1289 }
1290
1291 int
1292 tf_msg_em_op(struct tf *tfp,
1293              int dir,
1294              uint16_t op)
1295 {
1296         int rc;
1297         struct hwrm_tf_ext_em_op_input req = {0};
1298         struct hwrm_tf_ext_em_op_output resp = {0};
1299         uint32_t flags;
1300         struct tfp_send_msg_parms parms = { 0 };
1301         struct tf_dev_info *dev;
1302         struct tf_session *tfs;
1303
1304         /* Retrieve the session information */
1305         rc = tf_session_get_session_internal(tfp, &tfs);
1306         if (rc) {
1307                 TFP_DRV_LOG(ERR,
1308                             "%s: Failed to lookup session, rc:%s\n",
1309                             tf_dir_2_str(dir),
1310                             strerror(-rc));
1311                 return rc;
1312         }
1313
1314         /* Retrieve the device information */
1315         rc = tf_session_get_device(tfs, &dev);
1316         if (rc) {
1317                 TFP_DRV_LOG(ERR,
1318                             "%s: Failed to lookup device, rc:%s\n",
1319                             tf_dir_2_str(dir),
1320                             strerror(-rc));
1321                 return rc;
1322         }
1323
1324         flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1325                  HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1326         req.flags = tfp_cpu_to_le_32(flags);
1327         req.op = tfp_cpu_to_le_16(op);
1328
1329         parms.tf_type = HWRM_TF_EXT_EM_OP;
1330         parms.req_data = (uint32_t *)&req;
1331         parms.req_size = sizeof(req);
1332         parms.resp_data = (uint32_t *)&resp;
1333         parms.resp_size = sizeof(resp);
1334         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1335
1336         rc = tfp_send_msg_direct(tfp,
1337                                  &parms);
1338         return rc;
1339 }
1340
1341 int
1342 tf_msg_tcam_entry_set(struct tf *tfp,
1343                       struct tf_dev_info *dev,
1344                       struct tf_tcam_set_parms *parms)
1345 {
1346         int rc;
1347         struct tfp_send_msg_parms mparms = { 0 };
1348         struct hwrm_tf_tcam_set_input req = { 0 };
1349         struct hwrm_tf_tcam_set_output resp = { 0 };
1350         struct tf_msg_dma_buf buf = { 0 };
1351         uint8_t *data = NULL;
1352         int data_size = 0;
1353         uint8_t fw_session_id;
1354
1355         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1356         if (rc) {
1357                 TFP_DRV_LOG(ERR,
1358                             "%s: Unable to lookup FW id, rc:%s\n",
1359                             tf_dir_2_str(parms->dir),
1360                             strerror(-rc));
1361                 return rc;
1362         }
1363
1364         /* Populate the request */
1365         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1366         req.type = parms->hcapi_type;
1367         req.idx = tfp_cpu_to_le_16(parms->idx);
1368         if (parms->dir == TF_DIR_TX)
1369                 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1370
1371         req.key_size = parms->key_size;
1372         req.mask_offset = parms->key_size;
1373         /* Result follows after key and mask, thus multiply by 2 */
1374         req.result_offset = 2 * parms->key_size;
1375         req.result_size = parms->result_size;
1376         data_size = 2 * req.key_size + req.result_size;
1377
1378         if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1379                 /* use pci buffer */
1380                 data = &req.dev_data[0];
1381         } else {
1382                 /* use dma buffer */
1383                 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1384                 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1385                 if (rc)
1386                         goto cleanup;
1387                 data = buf.va_addr;
1388                 tfp_memcpy(&req.dev_data[0],
1389                            &buf.pa_addr,
1390                            sizeof(buf.pa_addr));
1391         }
1392
1393         tfp_memcpy(&data[0], parms->key, parms->key_size);
1394         tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1395         tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1396
1397         mparms.tf_type = HWRM_TF_TCAM_SET;
1398         mparms.req_data = (uint32_t *)&req;
1399         mparms.req_size = sizeof(req);
1400         mparms.resp_data = (uint32_t *)&resp;
1401         mparms.resp_size = sizeof(resp);
1402         mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1403
1404         rc = tfp_send_msg_direct(tfp,
1405                                  &mparms);
1406
1407 cleanup:
1408         tf_msg_free_dma_buf(&buf);
1409
1410         return rc;
1411 }
1412
1413 int
1414 tf_msg_tcam_entry_get(struct tf *tfp,
1415                       struct tf_dev_info *dev,
1416                       struct tf_tcam_get_parms *parms)
1417 {
1418         int rc;
1419         struct tfp_send_msg_parms mparms = { 0 };
1420         struct hwrm_tf_tcam_get_input req = { 0 };
1421         struct hwrm_tf_tcam_get_output resp = { 0 };
1422         uint8_t fw_session_id;
1423
1424         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1425         if (rc) {
1426                 TFP_DRV_LOG(ERR,
1427                             "%s: Unable to lookup FW id, rc:%s\n",
1428                             tf_dir_2_str(parms->dir),
1429                             strerror(-rc));
1430                 return rc;
1431         }
1432
1433         /* Populate the request */
1434         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1435         req.type = parms->hcapi_type;
1436         req.idx = tfp_cpu_to_le_16(parms->idx);
1437         if (parms->dir == TF_DIR_TX)
1438                 req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1439
1440         mparms.tf_type = HWRM_TF_TCAM_GET;
1441         mparms.req_data = (uint32_t *)&req;
1442         mparms.req_size = sizeof(req);
1443         mparms.resp_data = (uint32_t *)&resp;
1444         mparms.resp_size = sizeof(resp);
1445         mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1446
1447         rc = tfp_send_msg_direct(tfp,
1448                                  &mparms);
1449
1450         if (rc != 0)
1451                 return rc;
1452
1453         if (parms->key_size < resp.key_size ||
1454             parms->result_size < resp.result_size) {
1455                 rc = -EINVAL;
1456                 TFP_DRV_LOG(ERR,
1457                             "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1458                             tf_dir_2_str(parms->dir),
1459                             parms->key_size,
1460                             resp.key_size,
1461                             strerror(-rc));
1462                 return rc;
1463         }
1464         parms->key_size = resp.key_size;
1465         parms->result_size = resp.result_size;
1466         tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1467         tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1468         tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1469
1470         return 0;
1471 }
1472
1473 int
1474 tf_msg_tcam_entry_free(struct tf *tfp,
1475                        struct tf_dev_info *dev,
1476                        struct tf_tcam_free_parms *in_parms)
1477 {
1478         int rc;
1479         struct hwrm_tf_tcam_free_input req =  { 0 };
1480         struct hwrm_tf_tcam_free_output resp = { 0 };
1481         struct tfp_send_msg_parms parms = { 0 };
1482         uint8_t fw_session_id;
1483
1484         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1485         if (rc) {
1486                 TFP_DRV_LOG(ERR,
1487                             "%s: Unable to lookup FW id, rc:%s\n",
1488                             tf_dir_2_str(in_parms->dir),
1489                             strerror(-rc));
1490                 return rc;
1491         }
1492
1493         /* Populate the request */
1494         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1495         req.type = in_parms->hcapi_type;
1496         req.count = 1;
1497         req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1498         if (in_parms->dir == TF_DIR_TX)
1499                 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1500
1501         parms.tf_type = HWRM_TF_TCAM_FREE;
1502         parms.req_data = (uint32_t *)&req;
1503         parms.req_size = sizeof(req);
1504         parms.resp_data = (uint32_t *)&resp;
1505         parms.resp_size = sizeof(resp);
1506         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1507
1508         rc = tfp_send_msg_direct(tfp,
1509                                  &parms);
1510         return rc;
1511 }
1512
1513 int
1514 tf_msg_set_tbl_entry(struct tf *tfp,
1515                      enum tf_dir dir,
1516                      uint16_t hcapi_type,
1517                      uint16_t size,
1518                      uint8_t *data,
1519                      uint32_t index)
1520 {
1521         int rc;
1522         struct hwrm_tf_tbl_type_set_input req = { 0 };
1523         struct hwrm_tf_tbl_type_set_output resp = { 0 };
1524         struct tfp_send_msg_parms parms = { 0 };
1525         uint8_t fw_session_id;
1526         struct tf_dev_info *dev;
1527         struct tf_session *tfs;
1528
1529         RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1530                          TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1531
1532         /* Retrieve the session information */
1533         rc = tf_session_get_session_internal(tfp, &tfs);
1534         if (rc) {
1535                 TFP_DRV_LOG(ERR,
1536                             "%s: Failed to lookup session, rc:%s\n",
1537                             tf_dir_2_str(dir),
1538                             strerror(-rc));
1539                 return rc;
1540         }
1541
1542         /* Retrieve the device information */
1543         rc = tf_session_get_device(tfs, &dev);
1544         if (rc) {
1545                 TFP_DRV_LOG(ERR,
1546                             "%s: Failed to lookup device, rc:%s\n",
1547                             tf_dir_2_str(dir),
1548                             strerror(-rc));
1549                 return rc;
1550         }
1551
1552         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1553         if (rc) {
1554                 TFP_DRV_LOG(ERR,
1555                             "%s: Unable to lookup FW id, rc:%s\n",
1556                             tf_dir_2_str(dir),
1557                             strerror(-rc));
1558                 return rc;
1559         }
1560
1561         /* Populate the request */
1562         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1563         req.flags = tfp_cpu_to_le_16(dir);
1564         req.type = tfp_cpu_to_le_32(hcapi_type);
1565         req.size = tfp_cpu_to_le_16(size);
1566         req.index = tfp_cpu_to_le_32(index);
1567
1568         /* Check for data size conformity */
1569         if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1570                 rc = -EINVAL;
1571                 TFP_DRV_LOG(ERR,
1572                             "%s: Invalid parameters for msg type, rc:%s\n",
1573                             tf_dir_2_str(dir),
1574                             strerror(-rc));
1575                 return rc;
1576         }
1577
1578         tfp_memcpy(&req.data,
1579                    data,
1580                    size);
1581
1582         parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1583         parms.req_data = (uint32_t *)&req;
1584         parms.req_size = sizeof(req);
1585         parms.resp_data = (uint32_t *)&resp;
1586         parms.resp_size = sizeof(resp);
1587         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1588
1589         rc = tfp_send_msg_direct(tfp,
1590                                  &parms);
1591         if (rc)
1592                 return rc;
1593
1594         return 0;
1595 }
1596
1597 int
1598 tf_msg_get_tbl_entry(struct tf *tfp,
1599                      enum tf_dir dir,
1600                      uint16_t hcapi_type,
1601                      uint16_t size,
1602                      uint8_t *data,
1603                      uint32_t index)
1604 {
1605         int rc;
1606         struct hwrm_tf_tbl_type_get_input req = { 0 };
1607         struct hwrm_tf_tbl_type_get_output resp = { 0 };
1608         struct tfp_send_msg_parms parms = { 0 };
1609         uint8_t fw_session_id;
1610         struct tf_dev_info *dev;
1611         struct tf_session *tfs;
1612
1613         /* Retrieve the session information */
1614         rc = tf_session_get_session_internal(tfp, &tfs);
1615         if (rc) {
1616                 TFP_DRV_LOG(ERR,
1617                             "%s: Failed to lookup session, rc:%s\n",
1618                             tf_dir_2_str(dir),
1619                             strerror(-rc));
1620                 return rc;
1621         }
1622
1623         /* Retrieve the device information */
1624         rc = tf_session_get_device(tfs, &dev);
1625         if (rc) {
1626                 TFP_DRV_LOG(ERR,
1627                             "%s: Failed to lookup device, rc:%s\n",
1628                             tf_dir_2_str(dir),
1629                             strerror(-rc));
1630                 return rc;
1631         }
1632
1633         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1634         if (rc) {
1635                 TFP_DRV_LOG(ERR,
1636                             "%s: Unable to lookup FW id, rc:%s\n",
1637                             tf_dir_2_str(dir),
1638                             strerror(-rc));
1639                 return rc;
1640         }
1641
1642         /* Populate the request */
1643         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1644         req.flags = tfp_cpu_to_le_16(dir);
1645         req.type = tfp_cpu_to_le_32(hcapi_type);
1646         req.index = tfp_cpu_to_le_32(index);
1647
1648         parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1649         parms.req_data = (uint32_t *)&req;
1650         parms.req_size = sizeof(req);
1651         parms.resp_data = (uint32_t *)&resp;
1652         parms.resp_size = sizeof(resp);
1653         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1654
1655         rc = tfp_send_msg_direct(tfp,
1656                                  &parms);
1657         if (rc)
1658                 return rc;
1659
1660         /*
1661          * The response will be 64 bytes long, the response size will
1662          * be in words (16). All we can test for is that the response
1663          * size is < to the requested size.
1664          */
1665         if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1666                 return -EINVAL;
1667
1668         /*
1669          * Copy the requested number of bytes
1670          */
1671         tfp_memcpy(data,
1672                    &resp.data,
1673                    size);
1674
1675         return 0;
1676 }
1677
1678 /* HWRM Tunneled messages */
1679
1680 int
1681 tf_msg_get_global_cfg(struct tf *tfp,
1682                       struct tf_global_cfg_parms *params)
1683 {
1684         int rc = 0;
1685         struct tfp_send_msg_parms parms = { 0 };
1686         struct hwrm_tf_global_cfg_get_input req = { 0 };
1687         struct hwrm_tf_global_cfg_get_output resp = { 0 };
1688         uint32_t flags = 0;
1689         uint8_t fw_session_id;
1690         uint16_t resp_size = 0;
1691         struct tf_dev_info *dev;
1692         struct tf_session *tfs;
1693
1694         /* Retrieve the session information */
1695         rc = tf_session_get_session_internal(tfp, &tfs);
1696         if (rc) {
1697                 TFP_DRV_LOG(ERR,
1698                             "%s: Failed to lookup session, rc:%s\n",
1699                             tf_dir_2_str(params->dir),
1700                             strerror(-rc));
1701                 return rc;
1702         }
1703
1704         /* Retrieve the device information */
1705         rc = tf_session_get_device(tfs, &dev);
1706         if (rc) {
1707                 TFP_DRV_LOG(ERR,
1708                             "%s: Failed to lookup device, rc:%s\n",
1709                             tf_dir_2_str(params->dir),
1710                             strerror(-rc));
1711                 return rc;
1712         }
1713
1714         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1715         if (rc) {
1716                 TFP_DRV_LOG(ERR,
1717                             "%s: Unable to lookup FW id, rc:%s\n",
1718                             tf_dir_2_str(params->dir),
1719                             strerror(-rc));
1720                 return rc;
1721         }
1722
1723         flags = (params->dir == TF_DIR_TX ?
1724                  HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1725                  HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1726
1727         /* Populate the request */
1728         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1729         req.flags = tfp_cpu_to_le_32(flags);
1730         req.type = tfp_cpu_to_le_32(params->type);
1731         req.offset = tfp_cpu_to_le_32(params->offset);
1732         req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1733
1734         parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1735         parms.req_data = (uint32_t *)&req;
1736         parms.req_size = sizeof(req);
1737         parms.resp_data = (uint32_t *)&resp;
1738         parms.resp_size = sizeof(resp);
1739         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1740
1741         rc = tfp_send_msg_direct(tfp, &parms);
1742         if (rc != 0)
1743                 return rc;
1744
1745         /* Verify that we got enough buffer to return the requested data */
1746         resp_size = tfp_le_to_cpu_16(resp.size);
1747         if (resp_size < params->config_sz_in_bytes)
1748                 return -EINVAL;
1749
1750         if (params->config)
1751                 tfp_memcpy(params->config,
1752                            resp.data,
1753                            resp_size);
1754         else
1755                 return -EFAULT;
1756
1757         return 0;
1758 }
1759
1760 int
1761 tf_msg_set_global_cfg(struct tf *tfp,
1762                       struct tf_global_cfg_parms *params)
1763 {
1764         int rc = 0;
1765         struct tfp_send_msg_parms parms = { 0 };
1766         struct hwrm_tf_global_cfg_set_input req = { 0 };
1767         struct hwrm_tf_global_cfg_set_output resp = { 0 };
1768         uint32_t flags = 0;
1769         uint8_t fw_session_id;
1770         struct tf_dev_info *dev;
1771         struct tf_session *tfs;
1772
1773         /* Retrieve the session information */
1774         rc = tf_session_get_session_internal(tfp, &tfs);
1775         if (rc) {
1776                 TFP_DRV_LOG(ERR,
1777                             "%s: Failed to lookup session, rc:%s\n",
1778                             tf_dir_2_str(params->dir),
1779                             strerror(-rc));
1780                 return rc;
1781         }
1782
1783         /* Retrieve the device information */
1784         rc = tf_session_get_device(tfs, &dev);
1785         if (rc) {
1786                 TFP_DRV_LOG(ERR,
1787                             "%s: Failed to lookup device, rc:%s\n",
1788                             tf_dir_2_str(params->dir),
1789                             strerror(-rc));
1790                 return rc;
1791         }
1792
1793         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1794         if (rc) {
1795                 TFP_DRV_LOG(ERR,
1796                             "%s: Unable to lookup FW id, rc:%s\n",
1797                             tf_dir_2_str(params->dir),
1798                             strerror(-rc));
1799                 return rc;
1800         }
1801
1802         flags = (params->dir == TF_DIR_TX ?
1803                  HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
1804                  HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
1805
1806         /* Populate the request */
1807         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1808         req.flags = tfp_cpu_to_le_32(flags);
1809         req.type = tfp_cpu_to_le_32(params->type);
1810         req.offset = tfp_cpu_to_le_32(params->offset);
1811
1812         /* Check for data size conformity */
1813         if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
1814                 rc = -EINVAL;
1815                 TFP_DRV_LOG(ERR,
1816                             "%s: Invalid parameters for msg type, rc:%s\n",
1817                             tf_dir_2_str(params->dir),
1818                             strerror(-rc));
1819                 return rc;
1820         }
1821
1822         tfp_memcpy(req.data, params->config,
1823                    params->config_sz_in_bytes);
1824
1825         /* Only set mask if pointer is provided
1826          */
1827         if (params->config_mask) {
1828                 tfp_memcpy(req.mask,
1829                            params->config_mask,
1830                            params->config_sz_in_bytes);
1831         }
1832
1833         req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1834
1835         parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
1836         parms.req_data = (uint32_t *)&req;
1837         parms.req_size = sizeof(req);
1838         parms.resp_data = (uint32_t *)&resp;
1839         parms.resp_size = sizeof(resp);
1840         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1841
1842         rc = tfp_send_msg_direct(tfp, &parms);
1843
1844         if (rc != 0)
1845                 return rc;
1846
1847         return 0;
1848 }
1849
1850 int
1851 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
1852                           enum tf_dir dir,
1853                           uint16_t hcapi_type,
1854                           uint32_t starting_idx,
1855                           uint16_t num_entries,
1856                           uint16_t entry_sz_in_bytes,
1857                           uint64_t physical_mem_addr)
1858 {
1859         int rc;
1860         struct tfp_send_msg_parms parms = { 0 };
1861         struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
1862         struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
1863         int data_size = 0;
1864         uint8_t fw_session_id;
1865         struct tf_dev_info *dev;
1866         struct tf_session *tfs;
1867
1868         /* Retrieve the session information */
1869         rc = tf_session_get_session(tfp, &tfs);
1870         if (rc) {
1871                 TFP_DRV_LOG(ERR,
1872                             "%s: Failed to lookup session, rc:%s\n",
1873                             tf_dir_2_str(dir),
1874                             strerror(-rc));
1875                 return rc;
1876         }
1877
1878         /* Retrieve the device information */
1879         rc = tf_session_get_device(tfs, &dev);
1880         if (rc) {
1881                 TFP_DRV_LOG(ERR,
1882                             "%s: Failed to lookup device, rc:%s\n",
1883                             tf_dir_2_str(dir),
1884                             strerror(-rc));
1885                 return rc;
1886         }
1887
1888         rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1889         if (rc) {
1890                 TFP_DRV_LOG(ERR,
1891                             "%s: Unable to lookup FW id, rc:%s\n",
1892                             tf_dir_2_str(dir),
1893                             strerror(-rc));
1894                 return rc;
1895         }
1896
1897         /* Populate the request */
1898         req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1899         req.flags = tfp_cpu_to_le_16(dir);
1900         req.type = tfp_cpu_to_le_32(hcapi_type);
1901         req.start_index = tfp_cpu_to_le_32(starting_idx);
1902         req.num_entries = tfp_cpu_to_le_32(num_entries);
1903
1904         data_size = num_entries * entry_sz_in_bytes;
1905
1906         req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
1907
1908         parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
1909         parms.req_data = (uint32_t *)&req;
1910         parms.req_size = sizeof(req);
1911         parms.resp_data = (uint32_t *)&resp;
1912         parms.resp_size = sizeof(resp);
1913         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1914
1915         rc = tfp_send_msg_direct(tfp,
1916                                  &parms);
1917         if (rc)
1918                 return rc;
1919
1920         /* Verify that we got enough buffer to return the requested data */
1921         if (tfp_le_to_cpu_32(resp.size) != data_size)
1922                 return -EINVAL;
1923
1924         return 0;
1925 }
1926
1927 int
1928 tf_msg_get_if_tbl_entry(struct tf *tfp,
1929                         struct tf_if_tbl_get_parms *params)
1930 {
1931         int rc = 0;
1932         struct tfp_send_msg_parms parms = { 0 };
1933         struct hwrm_tf_if_tbl_get_input req = { 0 };
1934         struct hwrm_tf_if_tbl_get_output resp = { 0 };
1935         uint32_t flags = 0;
1936         struct tf_dev_info *dev;
1937         struct tf_session *tfs;
1938
1939         /* Retrieve the session information */
1940         rc = tf_session_get_session(tfp, &tfs);
1941         if (rc) {
1942                 TFP_DRV_LOG(ERR,
1943                             "%s: Failed to lookup session, rc:%s\n",
1944                             tf_dir_2_str(params->dir),
1945                             strerror(-rc));
1946                 return rc;
1947         }
1948
1949         /* Retrieve the device information */
1950         rc = tf_session_get_device(tfs, &dev);
1951         if (rc) {
1952                 TFP_DRV_LOG(ERR,
1953                             "%s: Failed to lookup device, rc:%s\n",
1954                             tf_dir_2_str(params->dir),
1955                             strerror(-rc));
1956                 return rc;
1957         }
1958
1959         flags = (params->dir == TF_DIR_TX ?
1960                 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
1961                 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
1962
1963         /* Populate the request */
1964         req.fw_session_id =
1965                 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
1966         req.flags = flags;
1967         req.type = params->hcapi_type;
1968         req.index = tfp_cpu_to_le_16(params->idx);
1969         req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
1970
1971         parms.tf_type = HWRM_TF_IF_TBL_GET;
1972         parms.req_data = (uint32_t *)&req;
1973         parms.req_size = sizeof(req);
1974         parms.resp_data = (uint32_t *)&resp;
1975         parms.resp_size = sizeof(resp);
1976         parms.mailbox = dev->ops->tf_dev_get_mailbox();
1977
1978         rc = tfp_send_msg_direct(tfp, &parms);
1979
1980         if (rc != 0)
1981                 return rc;
1982
1983         tfp_memcpy(params->data, resp.data, req.size);
1984
1985         return 0;
1986 }
1987
1988 int
1989 tf_msg_set_if_tbl_entry(struct tf *tfp,
1990                         struct tf_if_tbl_set_parms *params)
1991 {
1992         int rc = 0;
1993         struct tfp_send_msg_parms parms = { 0 };
1994         struct hwrm_tf_if_tbl_set_input req = { 0 };
1995         struct hwrm_tf_if_tbl_get_output resp = { 0 };
1996         uint32_t flags = 0;
1997         struct tf_dev_info *dev;
1998         struct tf_session *tfs;
1999
2000         /* Retrieve the session information */
2001         rc = tf_session_get_session(tfp, &tfs);
2002         if (rc) {
2003                 TFP_DRV_LOG(ERR,
2004                             "%s: Failed to lookup session, rc:%s\n",
2005                             tf_dir_2_str(params->dir),
2006                             strerror(-rc));
2007                 return rc;
2008         }
2009
2010         /* Retrieve the device information */
2011         rc = tf_session_get_device(tfs, &dev);
2012         if (rc)
2013                 return rc;
2014
2015         flags = (params->dir == TF_DIR_TX ?
2016                 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2017                 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2018
2019         /* Populate the request */
2020         req.fw_session_id =
2021                 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2022         req.flags = flags;
2023         req.type = params->hcapi_type;
2024         req.index = tfp_cpu_to_le_32(params->idx);
2025         req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2026         tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2027
2028         parms.tf_type = HWRM_TF_IF_TBL_SET;
2029         parms.req_data = (uint32_t *)&req;
2030         parms.req_size = sizeof(req);
2031         parms.resp_data = (uint32_t *)&resp;
2032         parms.resp_size = sizeof(resp);
2033         parms.mailbox = dev->ops->tf_dev_get_mailbox();
2034
2035         rc = tfp_send_msg_direct(tfp, &parms);
2036
2037         if (rc != 0)
2038                 return rc;
2039
2040         return 0;
2041 }