l2t.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 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_L2T_H
  35. #define __CXGB4_L2T_H
  36. #include <linux/spinlock.h>
  37. #include <linux/if_ether.h>
  38. #include <linux/atomic.h>
  39. #define VLAN_NONE 0xfff
  40. enum { L2T_SIZE = 4096 }; /* # of L2T entries */
  41. enum {
  42. L2T_STATE_VALID, /* entry is up to date */
  43. L2T_STATE_STALE, /* entry may be used but needs revalidation */
  44. L2T_STATE_RESOLVING, /* entry needs address resolution */
  45. L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */
  46. L2T_STATE_NOARP, /* Netdev down or removed*/
  47. /* when state is one of the below the entry is not hashed */
  48. L2T_STATE_SWITCHING, /* entry is being used by a switching filter */
  49. L2T_STATE_UNUSED /* entry not in use */
  50. };
  51. struct adapter;
  52. struct l2t_data;
  53. struct neighbour;
  54. struct net_device;
  55. struct file_operations;
  56. struct cpl_l2t_write_rpl;
  57. /*
  58. * Each L2T entry plays multiple roles. First of all, it keeps state for the
  59. * corresponding entry of the HW L2 table and maintains a queue of offload
  60. * packets awaiting address resolution. Second, it is a node of a hash table
  61. * chain, where the nodes of the chain are linked together through their next
  62. * pointer. Finally, each node is a bucket of a hash table, pointing to the
  63. * first element in its chain through its first pointer.
  64. */
  65. struct l2t_entry {
  66. u16 state; /* entry state */
  67. u16 idx; /* entry index within in-memory table */
  68. u32 addr[4]; /* next hop IP or IPv6 address */
  69. int ifindex; /* neighbor's net_device's ifindex */
  70. struct neighbour *neigh; /* associated neighbour */
  71. struct l2t_entry *first; /* start of hash chain */
  72. struct l2t_entry *next; /* next l2t_entry on chain */
  73. struct sk_buff_head arpq; /* packet queue awaiting resolution */
  74. spinlock_t lock;
  75. atomic_t refcnt; /* entry reference count */
  76. u16 hash; /* hash bucket the entry is on */
  77. u16 vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */
  78. u8 v6; /* whether entry is for IPv6 */
  79. u8 lport; /* associated offload logical interface */
  80. u8 dmac[ETH_ALEN]; /* neighbour's MAC address */
  81. };
  82. typedef void (*arp_err_handler_t)(void *handle, struct sk_buff *skb);
  83. /*
  84. * Callback stored in an skb to handle address resolution failure.
  85. */
  86. struct l2t_skb_cb {
  87. void *handle;
  88. arp_err_handler_t arp_err_handler;
  89. };
  90. #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
  91. static inline void t4_set_arp_err_handler(struct sk_buff *skb, void *handle,
  92. arp_err_handler_t handler)
  93. {
  94. L2T_SKB_CB(skb)->handle = handle;
  95. L2T_SKB_CB(skb)->arp_err_handler = handler;
  96. }
  97. void cxgb4_l2t_release(struct l2t_entry *e);
  98. int cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb,
  99. struct l2t_entry *e);
  100. struct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh,
  101. const struct net_device *physdev,
  102. unsigned int priority);
  103. u64 cxgb4_select_ntuple(struct net_device *dev,
  104. const struct l2t_entry *l2t);
  105. struct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan,
  106. u8 port, u8 *dmac);
  107. void t4_l2t_update(struct adapter *adap, struct neighbour *neigh);
  108. struct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan,
  109. u8 port, u8 *dmac);
  110. struct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end);
  111. void do_l2t_write_rpl(struct adapter *p, const struct cpl_l2t_write_rpl *rpl);
  112. extern const struct file_operations t4_l2t_fops;
  113. #endif /* __CXGB4_L2T_H */