1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <stdio.h>
30#include <string.h>
31#include <stdlib.h>
32#include <errno.h>
33
34#include "hdt-cli.h"
35#include "hdt-common.h"
36
37void main_show_kernel(int argc __unused, char **argv __unused,
38 struct s_hardware *hardware)
39{
40 char buffer[1024] = {0};
41 struct pci_device *pci_device;
42 bool found = false;
43 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
44 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
45
46 reset_more_printf();
47 more_printf("Kernel modules\n");
48
49
50
51 if ((hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP)
52 && (hardware->modules_alias_return_code == -ENOMODULESALIAS)) {
53 more_printf(" modules.pcimap and modules.alias files are missing\n");
54 return;
55 }
56
57
58 for_each_pci_func(pci_device, hardware->pci_domain) {
59 memset(kernel_modules, 0, sizeof kernel_modules);
60
61 for (int kmod = 0;
62 kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
63 if (kmod > 0) {
64 strncat(kernel_modules, " | ", 3);
65 }
66 strncat(kernel_modules,
67 pci_device->dev_info->linux_kernel_module[kmod],
68 LINUX_KERNEL_MODULE_SIZE - 1);
69 }
70
71 if ((pci_device->dev_info->linux_kernel_module_count > 0)
72 && (!strstr(buffer, kernel_modules))) {
73 found = true;
74 if (pci_device->dev_info->linux_kernel_module_count > 1)
75 strncat(buffer, "(", 1);
76 strncat(buffer, kernel_modules, sizeof(kernel_modules));
77 if (pci_device->dev_info->linux_kernel_module_count > 1)
78 strncat(buffer, ")", 1);
79 strncat(buffer, " # ", 3);
80 }
81
82 }
83 if (found == true) {
84 strncat(buffer, "\n", 1);
85 more_printf("%s", buffer);
86 }
87}
88
89static void show_kernel_modules(int argc __unused, char **argv __unused,
90 struct s_hardware *hardware)
91{
92 struct pci_device *pci_device;
93 char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
94 MAX_KERNEL_MODULES_PER_PCI_DEVICE];
95 char modules[MAX_PCI_CLASSES][256] = {{0}};
96 char category_name[MAX_PCI_CLASSES][256] = {{0}};
97
98 if (hardware->pci_ids_return_code == -ENOPCIIDS) {
99 more_printf(" Missing pci.ids, we can't compute the list\n");
100 return;
101 }
102
103 if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
104 more_printf(" Missing modules.pcimap, we can't compute the list\n");
105 return;
106 }
107
108 reset_more_printf();
109 for_each_pci_func(pci_device, hardware->pci_domain) {
110 memset(kernel_modules, 0, sizeof kernel_modules);
111
112 for (int kmod = 0;
113 kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
114 strncat(kernel_modules,
115 pci_device->dev_info->linux_kernel_module[kmod],
116 LINUX_KERNEL_MODULE_SIZE - 1);
117 strncat(kernel_modules, " ", 1);
118 }
119
120 if ((pci_device->dev_info->linux_kernel_module_count > 0)
121 && (!strstr(modules[pci_device->class[2]], kernel_modules))) {
122 strncat(modules[pci_device->class[2]], kernel_modules,
123 sizeof(kernel_modules));
124 snprintf(category_name[pci_device->class[2]],
125 sizeof(category_name[pci_device->class[2]]),
126 "%s", pci_device->dev_info->category_name);
127 }
128 }
129
130 for (int i = 0; i < MAX_PCI_CLASSES; i++) {
131 if (strlen(category_name[i]) > 1) {
132 more_printf("%s : %s\n", category_name[i], modules[i]);
133 }
134 }
135}
136
137struct cli_module_descr kernel_show_modules = {
138 .modules = NULL,
139 .default_callback = show_kernel_modules,
140};
141
142struct cli_mode_descr kernel_mode = {
143 .mode = KERNEL_MODE,
144 .name = CLI_KERNEL,
145 .default_modules = NULL,
146 .show_modules = &kernel_show_modules,
147 .set_modules = NULL,
148};
149