usnic_vnic.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #ifndef USNIC_VNIC_H_
  34. #define USNIC_VNIC_H_
  35. #include <linux/pci.h>
  36. #include "vnic_dev.h"
  37. /* =USNIC_VNIC_RES_TYPE= =VNIC_RES= =DESC= */
  38. #define USNIC_VNIC_RES_TYPES \
  39. DEFINE_USNIC_VNIC_RES_AT(EOL, RES_TYPE_EOL, "EOL", 0) \
  40. DEFINE_USNIC_VNIC_RES(WQ, RES_TYPE_WQ, "WQ") \
  41. DEFINE_USNIC_VNIC_RES(RQ, RES_TYPE_RQ, "RQ") \
  42. DEFINE_USNIC_VNIC_RES(CQ, RES_TYPE_CQ, "CQ") \
  43. DEFINE_USNIC_VNIC_RES(INTR, RES_TYPE_INTR_CTRL, "INT") \
  44. DEFINE_USNIC_VNIC_RES(MAX, RES_TYPE_MAX, "MAX")\
  45. #define DEFINE_USNIC_VNIC_RES_AT(usnic_vnic_res_t, vnic_res_type, desc, val) \
  46. USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t = val,
  47. #define DEFINE_USNIC_VNIC_RES(usnic_vnic_res_t, vnic_res_type, desc) \
  48. USNIC_VNIC_RES_TYPE_##usnic_vnic_res_t,
  49. enum usnic_vnic_res_type {
  50. USNIC_VNIC_RES_TYPES
  51. };
  52. #undef DEFINE_USNIC_VNIC_RES
  53. #undef DEFINE_USNIC_VNIC_RES_AT
  54. struct usnic_vnic_res {
  55. enum usnic_vnic_res_type type;
  56. unsigned int vnic_idx;
  57. struct usnic_vnic *vnic;
  58. void __iomem *ctrl;
  59. void *owner;
  60. };
  61. struct usnic_vnic_res_chunk {
  62. enum usnic_vnic_res_type type;
  63. int cnt;
  64. int free_cnt;
  65. struct usnic_vnic_res **res;
  66. struct usnic_vnic *vnic;
  67. };
  68. struct usnic_vnic_res_desc {
  69. enum usnic_vnic_res_type type;
  70. uint16_t cnt;
  71. };
  72. struct usnic_vnic_res_spec {
  73. struct usnic_vnic_res_desc resources[USNIC_VNIC_RES_TYPE_MAX];
  74. };
  75. const char *usnic_vnic_res_type_to_str(enum usnic_vnic_res_type res_type);
  76. const char *usnic_vnic_pci_name(struct usnic_vnic *vnic);
  77. int usnic_vnic_dump(struct usnic_vnic *vnic, char *buf, int buf_sz,
  78. void *hdr_obj,
  79. int (*printtitle)(void *, char*, int),
  80. int (*printcols)(char *, int),
  81. int (*printrow)(void *, char *, int));
  82. void usnic_vnic_res_spec_update(struct usnic_vnic_res_spec *spec,
  83. enum usnic_vnic_res_type trgt_type,
  84. u16 cnt);
  85. int usnic_vnic_res_spec_satisfied(const struct usnic_vnic_res_spec *min_spec,
  86. struct usnic_vnic_res_spec *res_spec);
  87. int usnic_vnic_spec_dump(char *buf, int buf_sz,
  88. struct usnic_vnic_res_spec *res_spec);
  89. int usnic_vnic_check_room(struct usnic_vnic *vnic,
  90. struct usnic_vnic_res_spec *res_spec);
  91. int usnic_vnic_res_cnt(struct usnic_vnic *vnic,
  92. enum usnic_vnic_res_type type);
  93. int usnic_vnic_res_free_cnt(struct usnic_vnic *vnic,
  94. enum usnic_vnic_res_type type);
  95. struct usnic_vnic_res_chunk *
  96. usnic_vnic_get_resources(struct usnic_vnic *vnic,
  97. enum usnic_vnic_res_type type,
  98. int cnt,
  99. void *owner);
  100. void usnic_vnic_put_resources(struct usnic_vnic_res_chunk *chunk);
  101. struct pci_dev *usnic_vnic_get_pdev(struct usnic_vnic *vnic);
  102. struct vnic_dev_bar *usnic_vnic_get_bar(struct usnic_vnic *vnic,
  103. int bar_num);
  104. struct usnic_vnic *usnic_vnic_alloc(struct pci_dev *pdev);
  105. void usnic_vnic_free(struct usnic_vnic *vnic);
  106. u16 usnic_vnic_get_index(struct usnic_vnic *vnic);
  107. #endif /*!USNIC_VNIC_H_*/