-2

I am new in DPDK,so i get some doubt when read code. code as below in DPDK in kni_misc.c

...

switch (dev_info.device_id) {
            **#define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) case (dev):
            #include <rte_pci_dev_ids.h>**
                ret = igb_kni_probe(found_pci, &lad_dev);
                break;
            #define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) \
                            case (dev):
            #include <rte_pci_dev_ids.h>
                ret = ixgbe_kni_probe(found_pci, &lad_dev);
                break;
            default:
                ret = -1;
                break;

            }

...

after switch , define a macro RTE_PCI_DEV_ID_DECL_IGB(how to use it ?) after case, include rte_pci_dev_ids.h, and i also find this macro in the h file.

**

A not complete Macro definition between switch and case, and the Macro which find in the h file included after case. i can not understand it.

**

Could anyone help me to understand this code.

The syntax of this code? Compilation process ? Working process ?

Thanks.

DK.Xu
  • 3
  • 2

1 Answers1

-1

You need to look inside the header file e.g. rte_pci_dev_ids.h. These header files will indicate all the supported vendor and device ids. The macro definition before the include will convert all such definitions into "case" statement.

So essentially the statement below the include statement (calling probe) will apply to all "devices" that are mentioned inside the header file (e.g. rte_pci_dev_ids.h). So to add a new device, you simply have to include it in the header file and no change is required in the switch-case.

Ketan Mukadam
  • 789
  • 3
  • 7