diff options
| author | Sridhar Samudrala <sridhar.samudrala@intel.com> | 2017-05-11 14:23:19 -0400 |
|---|---|---|
| committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2017-06-01 17:26:23 -0400 |
| commit | 73556269aab30c39cba9cf8efafc402d0deb87b2 (patch) | |
| tree | 60000d69a9c9971eb5861b53d860ec781e70cf70 /include/linux/avf | |
| parent | a33c83c4353b2efc4d883bad06a86a9ba2dde4fc (diff) | |
virtchnl: Add compile time static asserts to validate structure sizes
This uses preprocessor tricks to make sure that a divide by zero
occurs if a struct changes size outside the expected number of
bytes.
Signed-off-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'include/linux/avf')
| -rw-r--r-- | include/linux/avf/virtchnl.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/include/linux/avf/virtchnl.h b/include/linux/avf/virtchnl.h index 72466c69f749..c893b9520a67 100644 --- a/include/linux/avf/virtchnl.h +++ b/include/linux/avf/virtchnl.h | |||
| @@ -135,6 +135,14 @@ enum virtchnl_ops { | |||
| 135 | VIRTCHNL_OP_SET_RSS_HENA = 26, | 135 | VIRTCHNL_OP_SET_RSS_HENA = 26, |
| 136 | }; | 136 | }; |
| 137 | 137 | ||
| 138 | /* This macro is used to generate a compilation error if a structure | ||
| 139 | * is not exactly the correct length. It gives a divide by zero error if the | ||
| 140 | * structure is not of the correct size, otherwise it creates an enum that is | ||
| 141 | * never used. | ||
| 142 | */ | ||
| 143 | #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ | ||
| 144 | { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } | ||
| 145 | |||
| 138 | /* Virtual channel message descriptor. This overlays the admin queue | 146 | /* Virtual channel message descriptor. This overlays the admin queue |
| 139 | * descriptor. All other data is passed in external buffers. | 147 | * descriptor. All other data is passed in external buffers. |
| 140 | */ | 148 | */ |
| @@ -146,6 +154,8 @@ struct virtchnl_msg { | |||
| 146 | u32 vfid; /* used by PF when sending to VF */ | 154 | u32 vfid; /* used by PF when sending to VF */ |
| 147 | }; | 155 | }; |
| 148 | 156 | ||
| 157 | VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); | ||
| 158 | |||
| 149 | /* Message descriptions and data structures.*/ | 159 | /* Message descriptions and data structures.*/ |
| 150 | 160 | ||
| 151 | /* VIRTCHNL_OP_VERSION | 161 | /* VIRTCHNL_OP_VERSION |
| @@ -169,6 +179,8 @@ struct virtchnl_version_info { | |||
| 169 | u32 minor; | 179 | u32 minor; |
| 170 | }; | 180 | }; |
| 171 | 181 | ||
| 182 | VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); | ||
| 183 | |||
| 172 | #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) | 184 | #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) |
| 173 | #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) | 185 | #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) |
| 174 | 186 | ||
| @@ -209,6 +221,8 @@ struct virtchnl_vsi_resource { | |||
| 209 | u8 default_mac_addr[ETH_ALEN]; | 221 | u8 default_mac_addr[ETH_ALEN]; |
| 210 | }; | 222 | }; |
| 211 | 223 | ||
| 224 | VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); | ||
| 225 | |||
| 212 | /* VF offload flags | 226 | /* VF offload flags |
| 213 | * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including | 227 | * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including |
| 214 | * TX/RX Checksum offloading and TSO for non-tunnelled packets. | 228 | * TX/RX Checksum offloading and TSO for non-tunnelled packets. |
| @@ -244,6 +258,8 @@ struct virtchnl_vf_resource { | |||
| 244 | struct virtchnl_vsi_resource vsi_res[1]; | 258 | struct virtchnl_vsi_resource vsi_res[1]; |
| 245 | }; | 259 | }; |
| 246 | 260 | ||
| 261 | VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); | ||
| 262 | |||
| 247 | /* VIRTCHNL_OP_CONFIG_TX_QUEUE | 263 | /* VIRTCHNL_OP_CONFIG_TX_QUEUE |
| 248 | * VF sends this message to set up parameters for one TX queue. | 264 | * VF sends this message to set up parameters for one TX queue. |
| 249 | * External data buffer contains one instance of virtchnl_txq_info. | 265 | * External data buffer contains one instance of virtchnl_txq_info. |
| @@ -260,6 +276,8 @@ struct virtchnl_txq_info { | |||
| 260 | u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ | 276 | u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ |
| 261 | }; | 277 | }; |
| 262 | 278 | ||
| 279 | VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); | ||
| 280 | |||
| 263 | /* VIRTCHNL_OP_CONFIG_RX_QUEUE | 281 | /* VIRTCHNL_OP_CONFIG_RX_QUEUE |
| 264 | * VF sends this message to set up parameters for one RX queue. | 282 | * VF sends this message to set up parameters for one RX queue. |
| 265 | * External data buffer contains one instance of virtchnl_rxq_info. | 283 | * External data buffer contains one instance of virtchnl_rxq_info. |
| @@ -281,6 +299,8 @@ struct virtchnl_rxq_info { | |||
| 281 | u32 pad2; | 299 | u32 pad2; |
| 282 | }; | 300 | }; |
| 283 | 301 | ||
| 302 | VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); | ||
| 303 | |||
| 284 | /* VIRTCHNL_OP_CONFIG_VSI_QUEUES | 304 | /* VIRTCHNL_OP_CONFIG_VSI_QUEUES |
| 285 | * VF sends this message to set parameters for all active TX and RX queues | 305 | * VF sends this message to set parameters for all active TX and RX queues |
| 286 | * associated with the specified VSI. | 306 | * associated with the specified VSI. |
| @@ -294,6 +314,8 @@ struct virtchnl_queue_pair_info { | |||
| 294 | struct virtchnl_rxq_info rxq; | 314 | struct virtchnl_rxq_info rxq; |
| 295 | }; | 315 | }; |
| 296 | 316 | ||
| 317 | VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); | ||
| 318 | |||
| 297 | struct virtchnl_vsi_queue_config_info { | 319 | struct virtchnl_vsi_queue_config_info { |
| 298 | u16 vsi_id; | 320 | u16 vsi_id; |
| 299 | u16 num_queue_pairs; | 321 | u16 num_queue_pairs; |
| @@ -301,6 +323,8 @@ struct virtchnl_vsi_queue_config_info { | |||
| 301 | struct virtchnl_queue_pair_info qpair[1]; | 323 | struct virtchnl_queue_pair_info qpair[1]; |
| 302 | }; | 324 | }; |
| 303 | 325 | ||
| 326 | VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); | ||
| 327 | |||
| 304 | /* VIRTCHNL_OP_CONFIG_IRQ_MAP | 328 | /* VIRTCHNL_OP_CONFIG_IRQ_MAP |
| 305 | * VF uses this message to map vectors to queues. | 329 | * VF uses this message to map vectors to queues. |
| 306 | * The rxq_map and txq_map fields are bitmaps used to indicate which queues | 330 | * The rxq_map and txq_map fields are bitmaps used to indicate which queues |
| @@ -317,11 +341,15 @@ struct virtchnl_vector_map { | |||
| 317 | u16 txitr_idx; | 341 | u16 txitr_idx; |
| 318 | }; | 342 | }; |
| 319 | 343 | ||
| 344 | VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); | ||
| 345 | |||
| 320 | struct virtchnl_irq_map_info { | 346 | struct virtchnl_irq_map_info { |
| 321 | u16 num_vectors; | 347 | u16 num_vectors; |
| 322 | struct virtchnl_vector_map vecmap[1]; | 348 | struct virtchnl_vector_map vecmap[1]; |
| 323 | }; | 349 | }; |
| 324 | 350 | ||
| 351 | VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); | ||
| 352 | |||
| 325 | /* VIRTCHNL_OP_ENABLE_QUEUES | 353 | /* VIRTCHNL_OP_ENABLE_QUEUES |
| 326 | * VIRTCHNL_OP_DISABLE_QUEUES | 354 | * VIRTCHNL_OP_DISABLE_QUEUES |
| 327 | * VF sends these message to enable or disable TX/RX queue pairs. | 355 | * VF sends these message to enable or disable TX/RX queue pairs. |
| @@ -337,6 +365,8 @@ struct virtchnl_queue_select { | |||
| 337 | u32 tx_queues; | 365 | u32 tx_queues; |
| 338 | }; | 366 | }; |
| 339 | 367 | ||
| 368 | VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); | ||
| 369 | |||
| 340 | /* VIRTCHNL_OP_ADD_ETH_ADDR | 370 | /* VIRTCHNL_OP_ADD_ETH_ADDR |
| 341 | * VF sends this message in order to add one or more unicast or multicast | 371 | * VF sends this message in order to add one or more unicast or multicast |
| 342 | * address filters for the specified VSI. | 372 | * address filters for the specified VSI. |
| @@ -354,12 +384,16 @@ struct virtchnl_ether_addr { | |||
| 354 | u8 pad[2]; | 384 | u8 pad[2]; |
| 355 | }; | 385 | }; |
| 356 | 386 | ||
| 387 | VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); | ||
| 388 | |||
| 357 | struct virtchnl_ether_addr_list { | 389 | struct virtchnl_ether_addr_list { |
| 358 | u16 vsi_id; | 390 | u16 vsi_id; |
| 359 | u16 num_elements; | 391 | u16 num_elements; |
| 360 | struct virtchnl_ether_addr list[1]; | 392 | struct virtchnl_ether_addr list[1]; |
| 361 | }; | 393 | }; |
| 362 | 394 | ||
| 395 | VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); | ||
| 396 | |||
| 363 | /* VIRTCHNL_OP_ADD_VLAN | 397 | /* VIRTCHNL_OP_ADD_VLAN |
| 364 | * VF sends this message to add one or more VLAN tag filters for receives. | 398 | * VF sends this message to add one or more VLAN tag filters for receives. |
| 365 | * PF adds the filters and returns status. | 399 | * PF adds the filters and returns status. |
| @@ -380,6 +414,8 @@ struct virtchnl_vlan_filter_list { | |||
| 380 | u16 vlan_id[1]; | 414 | u16 vlan_id[1]; |
| 381 | }; | 415 | }; |
| 382 | 416 | ||
| 417 | VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); | ||
| 418 | |||
| 383 | /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE | 419 | /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE |
| 384 | * VF sends VSI id and flags. | 420 | * VF sends VSI id and flags. |
| 385 | * PF returns status code in retval. | 421 | * PF returns status code in retval. |
| @@ -390,6 +426,8 @@ struct virtchnl_promisc_info { | |||
| 390 | u16 flags; | 426 | u16 flags; |
| 391 | }; | 427 | }; |
| 392 | 428 | ||
| 429 | VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); | ||
| 430 | |||
| 393 | #define FLAG_VF_UNICAST_PROMISC 0x00000001 | 431 | #define FLAG_VF_UNICAST_PROMISC 0x00000001 |
| 394 | #define FLAG_VF_MULTICAST_PROMISC 0x00000002 | 432 | #define FLAG_VF_MULTICAST_PROMISC 0x00000002 |
| 395 | 433 | ||
| @@ -416,12 +454,16 @@ struct virtchnl_rss_key { | |||
| 416 | u8 key[1]; /* RSS hash key, packed bytes */ | 454 | u8 key[1]; /* RSS hash key, packed bytes */ |
| 417 | }; | 455 | }; |
| 418 | 456 | ||
| 457 | VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); | ||
| 458 | |||
| 419 | struct virtchnl_rss_lut { | 459 | struct virtchnl_rss_lut { |
| 420 | u16 vsi_id; | 460 | u16 vsi_id; |
| 421 | u16 lut_entries; | 461 | u16 lut_entries; |
| 422 | u8 lut[1]; /* RSS lookup table*/ | 462 | u8 lut[1]; /* RSS lookup table*/ |
| 423 | }; | 463 | }; |
| 424 | 464 | ||
| 465 | VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); | ||
| 466 | |||
| 425 | /* VIRTCHNL_OP_GET_RSS_HENA_CAPS | 467 | /* VIRTCHNL_OP_GET_RSS_HENA_CAPS |
| 426 | * VIRTCHNL_OP_SET_RSS_HENA | 468 | * VIRTCHNL_OP_SET_RSS_HENA |
| 427 | * VF sends these messages to get and set the hash filter enable bits for RSS. | 469 | * VF sends these messages to get and set the hash filter enable bits for RSS. |
| @@ -433,6 +475,8 @@ struct virtchnl_rss_hena { | |||
| 433 | u64 hena; | 475 | u64 hena; |
| 434 | }; | 476 | }; |
| 435 | 477 | ||
| 478 | VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); | ||
| 479 | |||
| 436 | /* VIRTCHNL_OP_EVENT | 480 | /* VIRTCHNL_OP_EVENT |
| 437 | * PF sends this message to inform the VF driver of events that may affect it. | 481 | * PF sends this message to inform the VF driver of events that may affect it. |
| 438 | * No direct response is expected from the VF, though it may generate other | 482 | * No direct response is expected from the VF, though it may generate other |
| @@ -460,6 +504,8 @@ struct virtchnl_pf_event { | |||
| 460 | int severity; | 504 | int severity; |
| 461 | }; | 505 | }; |
| 462 | 506 | ||
| 507 | VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); | ||
| 508 | |||
| 463 | /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP | 509 | /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP |
| 464 | * VF uses this message to request PF to map IWARP vectors to IWARP queues. | 510 | * VF uses this message to request PF to map IWARP vectors to IWARP queues. |
| 465 | * The request for this originates from the VF IWARP driver through | 511 | * The request for this originates from the VF IWARP driver through |
| @@ -479,11 +525,15 @@ struct virtchnl_iwarp_qv_info { | |||
| 479 | u8 itr_idx; | 525 | u8 itr_idx; |
| 480 | }; | 526 | }; |
| 481 | 527 | ||
| 528 | VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info); | ||
| 529 | |||
| 482 | struct virtchnl_iwarp_qvlist_info { | 530 | struct virtchnl_iwarp_qvlist_info { |
| 483 | u32 num_vectors; | 531 | u32 num_vectors; |
| 484 | struct virtchnl_iwarp_qv_info qv_info[1]; | 532 | struct virtchnl_iwarp_qv_info qv_info[1]; |
| 485 | }; | 533 | }; |
| 486 | 534 | ||
| 535 | VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info); | ||
| 536 | |||
| 487 | /* VF reset states - these are written into the RSTAT register: | 537 | /* VF reset states - these are written into the RSTAT register: |
| 488 | * VFGEN_RSTAT on the VF | 538 | * VFGEN_RSTAT on the VF |
| 489 | * When the PF initiates a reset, it writes 0 | 539 | * When the PF initiates a reset, it writes 0 |
