cxgb3_offload.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) 2006-2008 Chelsio, 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. * OpenIB.org 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. #ifndef _CXGB3_OFFLOAD_H
  33. #define _CXGB3_OFFLOAD_H
  34. #include <linux/list.h>
  35. #include <linux/skbuff.h>
  36. #include "l2t.h"
  37. #include "t3cdev.h"
  38. #include "t3_cpl.h"
  39. struct adapter;
  40. void cxgb3_offload_init(void);
  41. void cxgb3_adapter_ofld(struct adapter *adapter);
  42. void cxgb3_adapter_unofld(struct adapter *adapter);
  43. int cxgb3_offload_activate(struct adapter *adapter);
  44. void cxgb3_offload_deactivate(struct adapter *adapter);
  45. void cxgb3_set_dummy_ops(struct t3cdev *dev);
  46. struct t3cdev *dev2t3cdev(struct net_device *dev);
  47. /*
  48. * Client registration. Users of T3 driver must register themselves.
  49. * The T3 driver will call the add function of every client for each T3
  50. * adapter activated, passing up the t3cdev ptr. Each client fills out an
  51. * array of callback functions to process CPL messages.
  52. */
  53. void cxgb3_register_client(struct cxgb3_client *client);
  54. void cxgb3_unregister_client(struct cxgb3_client *client);
  55. void cxgb3_add_clients(struct t3cdev *tdev);
  56. void cxgb3_remove_clients(struct t3cdev *tdev);
  57. void cxgb3_event_notify(struct t3cdev *tdev, u32 event, u32 port);
  58. typedef int (*cxgb3_cpl_handler_func)(struct t3cdev *dev,
  59. struct sk_buff *skb, void *ctx);
  60. enum {
  61. OFFLOAD_STATUS_UP,
  62. OFFLOAD_STATUS_DOWN,
  63. OFFLOAD_PORT_DOWN,
  64. OFFLOAD_PORT_UP
  65. };
  66. struct cxgb3_client {
  67. char *name;
  68. void (*add) (struct t3cdev *);
  69. void (*remove) (struct t3cdev *);
  70. cxgb3_cpl_handler_func *handlers;
  71. int (*redirect)(void *ctx, struct dst_entry *old,
  72. struct dst_entry *new, struct l2t_entry *l2t);
  73. struct list_head client_list;
  74. void (*event_handler)(struct t3cdev *tdev, u32 event, u32 port);
  75. };
  76. /*
  77. * TID allocation services.
  78. */
  79. int cxgb3_alloc_atid(struct t3cdev *dev, struct cxgb3_client *client,
  80. void *ctx);
  81. int cxgb3_alloc_stid(struct t3cdev *dev, struct cxgb3_client *client,
  82. void *ctx);
  83. void *cxgb3_free_atid(struct t3cdev *dev, int atid);
  84. void cxgb3_free_stid(struct t3cdev *dev, int stid);
  85. void cxgb3_insert_tid(struct t3cdev *dev, struct cxgb3_client *client,
  86. void *ctx, unsigned int tid);
  87. void cxgb3_queue_tid_release(struct t3cdev *dev, unsigned int tid);
  88. void cxgb3_remove_tid(struct t3cdev *dev, void *ctx, unsigned int tid);
  89. struct t3c_tid_entry {
  90. struct cxgb3_client *client;
  91. void *ctx;
  92. };
  93. /* CPL message priority levels */
  94. enum {
  95. CPL_PRIORITY_DATA = 0, /* data messages */
  96. CPL_PRIORITY_SETUP = 1, /* connection setup messages */
  97. CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
  98. CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */
  99. CPL_PRIORITY_ACK = 1, /* RX ACK messages */
  100. CPL_PRIORITY_CONTROL = 1 /* offload control messages */
  101. };
  102. /* Flags for return value of CPL message handlers */
  103. enum {
  104. CPL_RET_BUF_DONE = 1, /* buffer processing done, buffer may be freed */
  105. CPL_RET_BAD_MSG = 2, /* bad CPL message (e.g., unknown opcode) */
  106. CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */
  107. };
  108. typedef int (*cpl_handler_func)(struct t3cdev *dev, struct sk_buff *skb);
  109. /*
  110. * Returns a pointer to the first byte of the CPL header in an sk_buff that
  111. * contains a CPL message.
  112. */
  113. static inline void *cplhdr(struct sk_buff *skb)
  114. {
  115. return skb->data;
  116. }
  117. void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
  118. union listen_entry {
  119. struct t3c_tid_entry t3c_tid;
  120. union listen_entry *next;
  121. };
  122. union active_open_entry {
  123. struct t3c_tid_entry t3c_tid;
  124. union active_open_entry *next;
  125. };
  126. /*
  127. * Holds the size, base address, free list start, etc of the TID, server TID,
  128. * and active-open TID tables for a offload device.
  129. * The tables themselves are allocated dynamically.
  130. */
  131. struct tid_info {
  132. struct t3c_tid_entry *tid_tab;
  133. unsigned int ntids;
  134. atomic_t tids_in_use;
  135. union listen_entry *stid_tab;
  136. unsigned int nstids;
  137. unsigned int stid_base;
  138. union active_open_entry *atid_tab;
  139. unsigned int natids;
  140. unsigned int atid_base;
  141. /*
  142. * The following members are accessed R/W so we put them in their own
  143. * cache lines.
  144. *
  145. * XXX We could combine the atid fields above with the lock here since
  146. * atids are use once (unlike other tids). OTOH the above fields are
  147. * usually in cache due to tid_tab.
  148. */
  149. spinlock_t atid_lock ____cacheline_aligned_in_smp;
  150. union active_open_entry *afree;
  151. unsigned int atids_in_use;
  152. spinlock_t stid_lock ____cacheline_aligned;
  153. union listen_entry *sfree;
  154. unsigned int stids_in_use;
  155. };
  156. struct t3c_data {
  157. struct list_head list_node;
  158. struct t3cdev *dev;
  159. unsigned int tx_max_chunk; /* max payload for TX_DATA */
  160. unsigned int max_wrs; /* max in-flight WRs per connection */
  161. unsigned int nmtus;
  162. const unsigned short *mtus;
  163. struct tid_info tid_maps;
  164. struct t3c_tid_entry *tid_release_list;
  165. spinlock_t tid_release_lock;
  166. struct work_struct tid_release_task;
  167. struct sk_buff *nofail_skb;
  168. unsigned int release_list_incomplete;
  169. };
  170. /*
  171. * t3cdev -> t3c_data accessor
  172. */
  173. #define T3C_DATA(dev) (*(struct t3c_data **)&(dev)->l4opt)
  174. #endif