162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * This file is part of the Chelsio T4 Ethernet driver for Linux. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * This software is available to you under a choice of one of two 762306a36Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 862306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 962306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the 1062306a36Sopenharmony_ci * OpenIB.org BSD license below: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or 1362306a36Sopenharmony_ci * without modification, are permitted provided that the following 1462306a36Sopenharmony_ci * conditions are met: 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * - Redistributions of source code must retain the above 1762306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 1862306a36Sopenharmony_ci * disclaimer. 1962306a36Sopenharmony_ci * 2062306a36Sopenharmony_ci * - Redistributions in binary form must reproduce the above 2162306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 2262306a36Sopenharmony_ci * disclaimer in the documentation and/or other materials 2362306a36Sopenharmony_ci * provided with the distribution. 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 2662306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2762306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2862306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 2962306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 3062306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 3162306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 3262306a36Sopenharmony_ci * SOFTWARE. 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifndef __CXGB4_L2T_H 3662306a36Sopenharmony_ci#define __CXGB4_L2T_H 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#include <linux/spinlock.h> 3962306a36Sopenharmony_ci#include <linux/if_ether.h> 4062306a36Sopenharmony_ci#include <linux/atomic.h> 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#define VLAN_NONE 0xfff 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_cienum { L2T_SIZE = 4096 }; /* # of L2T entries */ 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cienum { 4762306a36Sopenharmony_ci L2T_STATE_VALID, /* entry is up to date */ 4862306a36Sopenharmony_ci L2T_STATE_STALE, /* entry may be used but needs revalidation */ 4962306a36Sopenharmony_ci L2T_STATE_RESOLVING, /* entry needs address resolution */ 5062306a36Sopenharmony_ci L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */ 5162306a36Sopenharmony_ci L2T_STATE_NOARP, /* Netdev down or removed*/ 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci /* when state is one of the below the entry is not hashed */ 5462306a36Sopenharmony_ci L2T_STATE_SWITCHING, /* entry is being used by a switching filter */ 5562306a36Sopenharmony_ci L2T_STATE_UNUSED /* entry not in use */ 5662306a36Sopenharmony_ci}; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_cistruct adapter; 5962306a36Sopenharmony_cistruct l2t_data; 6062306a36Sopenharmony_cistruct neighbour; 6162306a36Sopenharmony_cistruct net_device; 6262306a36Sopenharmony_cistruct file_operations; 6362306a36Sopenharmony_cistruct cpl_l2t_write_rpl; 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* 6662306a36Sopenharmony_ci * Each L2T entry plays multiple roles. First of all, it keeps state for the 6762306a36Sopenharmony_ci * corresponding entry of the HW L2 table and maintains a queue of offload 6862306a36Sopenharmony_ci * packets awaiting address resolution. Second, it is a node of a hash table 6962306a36Sopenharmony_ci * chain, where the nodes of the chain are linked together through their next 7062306a36Sopenharmony_ci * pointer. Finally, each node is a bucket of a hash table, pointing to the 7162306a36Sopenharmony_ci * first element in its chain through its first pointer. 7262306a36Sopenharmony_ci */ 7362306a36Sopenharmony_cistruct l2t_entry { 7462306a36Sopenharmony_ci u16 state; /* entry state */ 7562306a36Sopenharmony_ci u16 idx; /* entry index within in-memory table */ 7662306a36Sopenharmony_ci u32 addr[4]; /* next hop IP or IPv6 address */ 7762306a36Sopenharmony_ci int ifindex; /* neighbor's net_device's ifindex */ 7862306a36Sopenharmony_ci struct neighbour *neigh; /* associated neighbour */ 7962306a36Sopenharmony_ci struct l2t_entry *first; /* start of hash chain */ 8062306a36Sopenharmony_ci struct l2t_entry *next; /* next l2t_entry on chain */ 8162306a36Sopenharmony_ci struct sk_buff_head arpq; /* packet queue awaiting resolution */ 8262306a36Sopenharmony_ci spinlock_t lock; 8362306a36Sopenharmony_ci atomic_t refcnt; /* entry reference count */ 8462306a36Sopenharmony_ci u16 hash; /* hash bucket the entry is on */ 8562306a36Sopenharmony_ci u16 vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */ 8662306a36Sopenharmony_ci u8 v6; /* whether entry is for IPv6 */ 8762306a36Sopenharmony_ci u8 lport; /* associated offload logical interface */ 8862306a36Sopenharmony_ci u8 dmac[ETH_ALEN]; /* neighbour's MAC address */ 8962306a36Sopenharmony_ci}; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_citypedef void (*arp_err_handler_t)(void *handle, struct sk_buff *skb); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* 9462306a36Sopenharmony_ci * Callback stored in an skb to handle address resolution failure. 9562306a36Sopenharmony_ci */ 9662306a36Sopenharmony_cistruct l2t_skb_cb { 9762306a36Sopenharmony_ci void *handle; 9862306a36Sopenharmony_ci arp_err_handler_t arp_err_handler; 9962306a36Sopenharmony_ci}; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistatic inline void t4_set_arp_err_handler(struct sk_buff *skb, void *handle, 10462306a36Sopenharmony_ci arp_err_handler_t handler) 10562306a36Sopenharmony_ci{ 10662306a36Sopenharmony_ci L2T_SKB_CB(skb)->handle = handle; 10762306a36Sopenharmony_ci L2T_SKB_CB(skb)->arp_err_handler = handler; 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_civoid cxgb4_l2t_release(struct l2t_entry *e); 11162306a36Sopenharmony_ciint cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb, 11262306a36Sopenharmony_ci struct l2t_entry *e); 11362306a36Sopenharmony_cistruct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh, 11462306a36Sopenharmony_ci const struct net_device *physdev, 11562306a36Sopenharmony_ci unsigned int priority); 11662306a36Sopenharmony_ciu64 cxgb4_select_ntuple(struct net_device *dev, 11762306a36Sopenharmony_ci const struct l2t_entry *l2t); 11862306a36Sopenharmony_cistruct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan, 11962306a36Sopenharmony_ci u8 port, u8 *dmac); 12062306a36Sopenharmony_civoid t4_l2t_update(struct adapter *adap, struct neighbour *neigh); 12162306a36Sopenharmony_cistruct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan, 12262306a36Sopenharmony_ci u8 port, u8 *dmac); 12362306a36Sopenharmony_cistruct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end); 12462306a36Sopenharmony_civoid do_l2t_write_rpl(struct adapter *p, const struct cpl_l2t_write_rpl *rpl); 12562306a36Sopenharmony_cibool cxgb4_check_l2t_valid(struct l2t_entry *e); 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciextern const struct file_operations t4_l2t_fops; 12862306a36Sopenharmony_ci#endif /* __CXGB4_L2T_H */ 129