sched.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CXGB4_SCHED_H
  35. #define __CXGB4_SCHED_H
  36. #include <linux/spinlock.h>
  37. #include <linux/atomic.h>
  38. #define SCHED_CLS_NONE 0xff
  39. #define FW_SCHED_CLS_NONE 0xffffffff
  40. /* Max rate that can be set to a scheduling class is 10 Gbps */
  41. #define SCHED_MAX_RATE_KBPS 10000000U
  42. enum {
  43. SCHED_STATE_ACTIVE,
  44. SCHED_STATE_UNUSED,
  45. };
  46. enum sched_fw_ops {
  47. SCHED_FW_OP_ADD,
  48. };
  49. enum sched_bind_type {
  50. SCHED_QUEUE,
  51. };
  52. struct sched_queue_entry {
  53. struct list_head list;
  54. unsigned int cntxt_id;
  55. struct ch_sched_queue param;
  56. };
  57. struct sched_class {
  58. u8 state;
  59. u8 idx;
  60. struct ch_sched_params info;
  61. struct list_head queue_list;
  62. spinlock_t lock; /* Per class lock */
  63. atomic_t refcnt;
  64. };
  65. struct sched_table { /* per port scheduling table */
  66. u8 sched_size;
  67. rwlock_t rw_lock; /* Table lock */
  68. struct sched_class tab[0];
  69. };
  70. static inline bool can_sched(struct net_device *dev)
  71. {
  72. struct port_info *pi = netdev2pinfo(dev);
  73. return !pi->sched_tbl ? false : true;
  74. }
  75. static inline bool valid_class_id(struct net_device *dev, u8 class_id)
  76. {
  77. struct port_info *pi = netdev2pinfo(dev);
  78. if ((class_id > pi->sched_tbl->sched_size - 1) &&
  79. (class_id != SCHED_CLS_NONE))
  80. return false;
  81. return true;
  82. }
  83. int cxgb4_sched_class_bind(struct net_device *dev, void *arg,
  84. enum sched_bind_type type);
  85. int cxgb4_sched_class_unbind(struct net_device *dev, void *arg,
  86. enum sched_bind_type type);
  87. struct sched_class *cxgb4_sched_class_alloc(struct net_device *dev,
  88. struct ch_sched_params *p);
  89. struct sched_table *t4_init_sched(unsigned int size);
  90. void t4_cleanup_sched(struct adapter *adap);
  91. #endif /* __CXGB4_SCHED_H */