Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * pci.c: Linux user space PCI bus management. |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vlib/vlib.h> |
| 41 | #include <vlib/pci/pci.h> |
| 42 | #include <vlib/unix/unix.h> |
| 43 | |
| 44 | #include <sys/types.h> |
| 45 | #include <sys/stat.h> |
| 46 | #include <fcntl.h> |
| 47 | #include <dirent.h> |
| 48 | #include <sys/ioctl.h> |
| 49 | #include <net/if.h> |
| 50 | #include <linux/ethtool.h> |
| 51 | #include <linux/sockios.h> |
| 52 | |
| 53 | vlib_pci_main_t pci_main; |
| 54 | |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 55 | VLIB_REGISTER_LOG_CLASS (pci_log, static) = { |
| 56 | .class_name = "pci", |
| 57 | }; |
| 58 | |
| 59 | #define log_debug(h, f, ...) \ |
| 60 | vlib_log (VLIB_LOG_LEVEL_DEBUG, pci_log.class, "%U: " f, \ |
| 61 | format_vlib_pci_log, h, ##__VA_ARGS__) |
| 62 | |
| 63 | u8 * |
| 64 | format_vlib_pci_log (u8 *s, va_list *va) |
| 65 | { |
| 66 | vlib_pci_dev_handle_t h = va_arg (*va, vlib_pci_dev_handle_t); |
| 67 | return format (s, "%U", format_vlib_pci_addr, |
| 68 | vlib_pci_get_addr (vlib_get_main (), h)); |
| 69 | } |
| 70 | |
| 71 | vlib_pci_device_info_t *__attribute__ ((weak)) |
| 72 | vlib_pci_get_device_info (vlib_main_t *vm, vlib_pci_addr_t *addr, |
| 73 | clib_error_t **error) |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 74 | { |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 75 | if (error) |
| 76 | *error = clib_error_return (0, "unsupported"); |
| 77 | return 0; |
| 78 | } |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 79 | |
Ray Kinsella | 5714a49 | 2021-11-02 13:33:44 +0000 | [diff] [blame] | 80 | clib_error_t *__attribute__ ((weak)) |
| 81 | vlib_pci_get_device_root_bus (vlib_pci_addr_t *addr, vlib_pci_addr_t *root_bus) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 86 | vlib_pci_addr_t * __attribute__ ((weak)) vlib_pci_get_all_dev_addrs () |
| 87 | { |
| 88 | return 0; |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 91 | static clib_error_t * |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 92 | _vlib_pci_config_set_control_bit (vlib_main_t *vm, vlib_pci_dev_handle_t h, |
| 93 | u16 bit, int new_val, int *already_set) |
| 94 | { |
| 95 | u16 control, old; |
| 96 | clib_error_t *err; |
| 97 | |
| 98 | err = vlib_pci_read_write_config ( |
| 99 | vm, h, VLIB_READ, STRUCT_OFFSET_OF (vlib_pci_config_t, command), &old, |
| 100 | STRUCT_SIZE_OF (vlib_pci_config_t, command)); |
| 101 | |
| 102 | if (err) |
| 103 | return err; |
| 104 | |
| 105 | control = new_val ? old | bit : old & ~bit; |
| 106 | *already_set = old == control; |
| 107 | if (*already_set) |
| 108 | return 0; |
| 109 | |
| 110 | return vlib_pci_read_write_config ( |
| 111 | vm, h, VLIB_WRITE, STRUCT_OFFSET_OF (vlib_pci_config_t, command), &control, |
| 112 | STRUCT_SIZE_OF (vlib_pci_config_t, command)); |
| 113 | } |
| 114 | |
| 115 | clib_error_t * |
| 116 | vlib_pci_intr_enable (vlib_main_t *vm, vlib_pci_dev_handle_t h) |
| 117 | { |
| 118 | const vlib_pci_config_reg_command_t cmd = { .intx_disable = 1 }; |
| 119 | clib_error_t *err; |
| 120 | int already_set; |
| 121 | |
| 122 | err = _vlib_pci_config_set_control_bit (vm, h, cmd.as_u16, 0, &already_set); |
| 123 | log_debug (h, "interrupt%senabled", already_set ? " " : " already "); |
| 124 | return err; |
| 125 | } |
| 126 | |
| 127 | clib_error_t * |
| 128 | vlib_pci_intr_disable (vlib_main_t *vm, vlib_pci_dev_handle_t h) |
| 129 | { |
| 130 | const vlib_pci_config_reg_command_t cmd = { .intx_disable = 1 }; |
| 131 | clib_error_t *err; |
| 132 | int already_set; |
| 133 | |
| 134 | err = _vlib_pci_config_set_control_bit (vm, h, cmd.as_u16, 1, &already_set); |
| 135 | log_debug (h, "interrupt%sdisabled", already_set ? " " : " already "); |
| 136 | return err; |
| 137 | } |
| 138 | |
| 139 | clib_error_t * |
| 140 | vlib_pci_bus_master_enable (vlib_main_t *vm, vlib_pci_dev_handle_t h) |
| 141 | { |
| 142 | const vlib_pci_config_reg_command_t cmd = { .bus_master = 1 }; |
| 143 | clib_error_t *err; |
| 144 | int already_set; |
| 145 | |
| 146 | err = _vlib_pci_config_set_control_bit (vm, h, cmd.as_u16, 1, &already_set); |
| 147 | log_debug (h, "bus-master%senabled", already_set ? " " : " already "); |
| 148 | return err; |
| 149 | } |
| 150 | |
| 151 | clib_error_t * |
| 152 | vlib_pci_bus_master_disable (vlib_main_t *vm, vlib_pci_dev_handle_t h) |
| 153 | { |
| 154 | const vlib_pci_config_reg_command_t cmd = { .bus_master = 1 }; |
| 155 | clib_error_t *err; |
| 156 | int already_set; |
| 157 | |
| 158 | err = _vlib_pci_config_set_control_bit (vm, h, cmd.as_u16, 0, &already_set); |
| 159 | log_debug (h, "bus-master%sdisabled", already_set ? " " : " already "); |
| 160 | return err; |
| 161 | } |
| 162 | |
| 163 | clib_error_t * |
| 164 | vlib_pci_function_level_reset (vlib_main_t *vm, vlib_pci_dev_handle_t h) |
| 165 | { |
| 166 | vlib_pci_config_t cfg; |
| 167 | pci_capability_pcie_t *cap; |
| 168 | pci_capability_pcie_dev_control_t dev_control; |
| 169 | clib_error_t *err; |
| 170 | u8 offset; |
| 171 | |
| 172 | log_debug (h, "function level reset"); |
| 173 | |
| 174 | err = vlib_pci_read_write_config (vm, h, VLIB_READ, 0, &cfg, sizeof (cfg)); |
| 175 | if (err) |
| 176 | return err; |
| 177 | |
| 178 | offset = cfg.cap_ptr; |
Dave Wallace | 054229e | 2023-07-28 16:31:51 -0400 | [diff] [blame] | 179 | /* Make gcc happy, otherwise gcc fails build due to cap not set if offset == |
| 180 | * 0 */ |
| 181 | cap = (pci_capability_pcie_t *) (cfg.data + offset); |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 182 | |
| 183 | while (offset) |
| 184 | { |
| 185 | cap = (pci_capability_pcie_t *) (cfg.data + offset); |
| 186 | |
| 187 | if (cap->capability_id == PCI_CAP_ID_PCIE) |
| 188 | break; |
| 189 | |
| 190 | offset = cap->next_offset; |
| 191 | } |
| 192 | |
| 193 | if (cap->capability_id != PCI_CAP_ID_PCIE) |
| 194 | return clib_error_return (0, "PCIe capability config not found"); |
| 195 | |
| 196 | if (cap->dev_caps.flr_capable == 0) |
| 197 | return clib_error_return (0, "PCIe function level reset not supported"); |
| 198 | |
| 199 | dev_control = cap->dev_control; |
| 200 | dev_control.function_level_reset = 1; |
| 201 | |
| 202 | if ((err = vlib_pci_write_config_u16 ( |
| 203 | vm, h, offset + STRUCT_OFFSET_OF (pci_capability_pcie_t, dev_control), |
| 204 | &dev_control.as_u16))) |
| 205 | return err; |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static clib_error_t * |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 211 | show_pci_fn (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 212 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 213 | { |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 214 | vlib_pci_addr_t *addr = 0, *addrs; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 215 | int show_all = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 216 | u8 *s = 0; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 217 | |
| 218 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 219 | { |
| 220 | if (unformat (input, "all")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 221 | show_all = 1; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 222 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 223 | return clib_error_return (0, "unknown input `%U'", |
| 224 | format_unformat_error, input); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Damjan Marion | 4a348e8 | 2020-11-25 17:13:38 +0100 | [diff] [blame] | 227 | vlib_cli_output (vm, "%-13s%-5s%-12s%-14s%-16s%-32s%s", |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 228 | "Address", "Sock", "VID:PID", "Link Speed", "Driver", |
| 229 | "Product Name", "Vital Product Data"); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 230 | |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 231 | addrs = vlib_pci_get_all_dev_addrs (); |
Damjan Marion | 1436100 | 2021-03-11 12:17:33 +0100 | [diff] [blame] | 232 | |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 233 | vec_foreach (addr, addrs) |
| 234 | { |
| 235 | vlib_pci_device_info_t *d; |
Damjan Marion | 2322798 | 2018-10-22 13:38:57 +0200 | [diff] [blame] | 236 | d = vlib_pci_get_device_info (vm, addr, 0); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 237 | |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 238 | if (!d) |
| 239 | continue; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 240 | |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 241 | if (d->device_class != PCI_CLASS_NETWORK_ETHERNET && !show_all) |
Damjan Marion | 1436100 | 2021-03-11 12:17:33 +0100 | [diff] [blame] | 242 | continue; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 243 | |
Damjan Marion | 1436100 | 2021-03-11 12:17:33 +0100 | [diff] [blame] | 244 | vec_reset_length (s); |
| 245 | if (d->numa_node >= 0) |
| 246 | s = format (s, " %d", d->numa_node); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 247 | |
Damjan Marion | 1436100 | 2021-03-11 12:17:33 +0100 | [diff] [blame] | 248 | vlib_cli_output ( |
| 249 | vm, "%-13U%-5v%04x:%04x %-14U%-16s%-32v%U", format_vlib_pci_addr, |
| 250 | addr, s, d->vendor_id, d->device_id, format_vlib_pci_link_speed, d, |
| 251 | d->driver_name ? (char *) d->driver_name : "", d->product_name, |
| 252 | format_vlib_pci_vpd, d->vpd_r, (u8 *) 0); |
| 253 | vlib_pci_free_device_info (d); |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 254 | } |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 255 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 256 | vec_free (s); |
Damjan Marion | cef87f1 | 2017-10-05 15:32:41 +0200 | [diff] [blame] | 257 | vec_free (addrs); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | uword |
| 262 | unformat_vlib_pci_addr (unformat_input_t * input, va_list * args) |
| 263 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 264 | vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 265 | u32 x[4]; |
| 266 | |
| 267 | if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3])) |
| 268 | return 0; |
| 269 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 270 | addr->domain = x[0]; |
| 271 | addr->bus = x[1]; |
| 272 | addr->slot = x[2]; |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 273 | addr->function = x[3]; |
| 274 | |
| 275 | return 1; |
| 276 | } |
| 277 | |
| 278 | u8 * |
| 279 | format_vlib_pci_addr (u8 * s, va_list * va) |
| 280 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 281 | vlib_pci_addr_t *addr = va_arg (*va, vlib_pci_addr_t *); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 282 | return format (s, "%04x:%02x:%02x.%x", addr->domain, addr->bus, |
| 283 | addr->slot, addr->function); |
| 284 | } |
| 285 | |
| 286 | u8 * |
Ray Kinsella | 6efe025 | 2021-11-02 13:26:49 +0000 | [diff] [blame] | 287 | format_vlib_pci_link_port (u8 *s, va_list *va) |
| 288 | { |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 289 | vlib_pci_config_t *c = va_arg (*va, vlib_pci_config_t *); |
| 290 | pci_capability_pcie_t *r = pci_config_find_capability (c, PCI_CAP_ID_PCIE); |
Ray Kinsella | 6efe025 | 2021-11-02 13:26:49 +0000 | [diff] [blame] | 291 | |
| 292 | if (!r) |
| 293 | return format (s, "unknown"); |
| 294 | |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 295 | return format (s, "P%d", r->link_caps.port_number); |
| 296 | } |
| 297 | |
| 298 | static u8 * |
| 299 | _vlib_pci_link_speed (u8 *s, u8 speed, u8 width) |
| 300 | { |
| 301 | static char *speeds[] = { |
| 302 | [1] = "2.5", [2] = "5.0", [3] = "8.0", [4] = "16.0", [5] = "32.0" |
| 303 | }; |
| 304 | |
| 305 | if (speed > ARRAY_LEN (speeds) || speeds[speed] == 0) |
| 306 | s = format (s, "unknown speed"); |
| 307 | else |
| 308 | s = format (s, "%s GT/s", speeds[speed]); |
| 309 | |
| 310 | return format (s, " x%u", width); |
Ray Kinsella | 6efe025 | 2021-11-02 13:26:49 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | u8 * |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 314 | format_vlib_pci_link_speed (u8 *s, va_list *va) |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 315 | { |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 316 | vlib_pci_config_t *c = va_arg (*va, vlib_pci_config_t *); |
| 317 | pci_capability_pcie_t *r = pci_config_find_capability (c, PCI_CAP_ID_PCIE); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 318 | |
| 319 | if (!r) |
| 320 | return format (s, "unknown"); |
| 321 | |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 322 | return _vlib_pci_link_speed (s, r->link_status.link_speed, |
| 323 | r->link_status.negotiated_link_width); |
| 324 | } |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 325 | |
Damjan Marion | 00ea98a | 2023-07-28 13:19:49 +0200 | [diff] [blame] | 326 | u8 * |
| 327 | format_vlib_pci_link_speed_cap (u8 *s, va_list *va) |
| 328 | { |
| 329 | vlib_pci_config_t *c = va_arg (*va, vlib_pci_config_t *); |
| 330 | pci_capability_pcie_t *r = pci_config_find_capability (c, PCI_CAP_ID_PCIE); |
| 331 | |
| 332 | if (!r) |
| 333 | return format (s, "unknown"); |
| 334 | |
| 335 | return _vlib_pci_link_speed (s, r->link_caps.max_link_speed, |
| 336 | r->link_caps.max_link_width); |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 339 | u8 * |
| 340 | format_vlib_pci_vpd (u8 * s, va_list * args) |
| 341 | { |
| 342 | u8 *data = va_arg (*args, u8 *); |
| 343 | u8 *id = va_arg (*args, u8 *); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 344 | u32 indent = format_get_indent (s); |
Damjan Marion | 7d22161 | 2016-12-26 11:39:42 +0100 | [diff] [blame] | 345 | char *string_types[] = { "PN", "EC", "SN", "MN", 0 }; |
| 346 | uword p = 0; |
| 347 | int first_line = 1; |
| 348 | |
| 349 | if (vec_len (data) < 3) |
| 350 | return s; |
| 351 | |
| 352 | while (p + 3 < vec_len (data)) |
| 353 | { |
| 354 | |
| 355 | if (data[p] == 0 && data[p + 1] == 0) |
| 356 | return s; |
| 357 | |
| 358 | if (p + data[p + 2] > vec_len (data)) |
| 359 | return s; |
| 360 | |
| 361 | if (id == 0) |
| 362 | { |
| 363 | int is_string = 0; |
| 364 | char **c = string_types; |
| 365 | |
| 366 | while (c[0]) |
| 367 | { |
| 368 | if (*(u16 *) & data[p] == *(u16 *) c[0]) |
| 369 | is_string = 1; |
| 370 | c++; |
| 371 | } |
| 372 | |
| 373 | if (data[p + 2]) |
| 374 | { |
| 375 | if (!first_line) |
| 376 | s = format (s, "\n%U", format_white_space, indent); |
| 377 | else |
| 378 | { |
| 379 | first_line = 0; |
| 380 | s = format (s, " "); |
| 381 | } |
| 382 | |
| 383 | s = format (s, "%c%c: ", data[p], data[p + 1]); |
| 384 | if (is_string) |
| 385 | vec_add (s, data + p + 3, data[p + 2]); |
| 386 | else |
| 387 | { |
| 388 | int i; |
| 389 | const int max_bytes = 8; |
| 390 | s = format (s, "0x"); |
| 391 | for (i = 0; i < clib_min (data[p + 2], max_bytes); i++) |
| 392 | s = format (s, " %02x", data[p + 3 + i]); |
| 393 | |
| 394 | if (data[p + 2] > max_bytes) |
| 395 | s = format (s, " ..."); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | else if (*(u16 *) & data[p] == *(u16 *) id) |
| 400 | { |
| 401 | vec_add (s, data + p + 3, data[p + 2]); |
| 402 | return s; |
| 403 | } |
| 404 | |
| 405 | p += 3 + data[p + 2]; |
| 406 | } |
| 407 | |
| 408 | return s; |
| 409 | } |
| 410 | |
Damjan Marion | 5a206ea | 2016-05-12 22:11:03 +0200 | [diff] [blame] | 411 | VLIB_CLI_COMMAND (show_pci_command, static) = { |
| 412 | .path = "show pci", |
| 413 | .short_help = "show pci [all]", |
| 414 | .function = show_pci_fn, |
| 415 | }; |