18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is part of the Chelsio T4 Ethernet driver for Linux. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 78c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the 108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or 138c2ecf20Sopenharmony_ci * without modification, are permitted provided that the following 148c2ecf20Sopenharmony_ci * conditions are met: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above 178c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 188c2ecf20Sopenharmony_ci * disclaimer. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above 218c2ecf20Sopenharmony_ci * copyright notice, this list of conditions and the following 228c2ecf20Sopenharmony_ci * disclaimer in the documentation and/or other materials 238c2ecf20Sopenharmony_ci * provided with the distribution. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 328c2ecf20Sopenharmony_ci * SOFTWARE. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifndef __CXGB4_L2T_H 368c2ecf20Sopenharmony_ci#define __CXGB4_L2T_H 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 398c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 408c2ecf20Sopenharmony_ci#include <linux/atomic.h> 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define VLAN_NONE 0xfff 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cienum { L2T_SIZE = 4096 }; /* # of L2T entries */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cienum { 478c2ecf20Sopenharmony_ci L2T_STATE_VALID, /* entry is up to date */ 488c2ecf20Sopenharmony_ci L2T_STATE_STALE, /* entry may be used but needs revalidation */ 498c2ecf20Sopenharmony_ci L2T_STATE_RESOLVING, /* entry needs address resolution */ 508c2ecf20Sopenharmony_ci L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */ 518c2ecf20Sopenharmony_ci L2T_STATE_NOARP, /* Netdev down or removed*/ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci /* when state is one of the below the entry is not hashed */ 548c2ecf20Sopenharmony_ci L2T_STATE_SWITCHING, /* entry is being used by a switching filter */ 558c2ecf20Sopenharmony_ci L2T_STATE_UNUSED /* entry not in use */ 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct adapter; 598c2ecf20Sopenharmony_cistruct l2t_data; 608c2ecf20Sopenharmony_cistruct neighbour; 618c2ecf20Sopenharmony_cistruct net_device; 628c2ecf20Sopenharmony_cistruct file_operations; 638c2ecf20Sopenharmony_cistruct cpl_l2t_write_rpl; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* 668c2ecf20Sopenharmony_ci * Each L2T entry plays multiple roles. First of all, it keeps state for the 678c2ecf20Sopenharmony_ci * corresponding entry of the HW L2 table and maintains a queue of offload 688c2ecf20Sopenharmony_ci * packets awaiting address resolution. Second, it is a node of a hash table 698c2ecf20Sopenharmony_ci * chain, where the nodes of the chain are linked together through their next 708c2ecf20Sopenharmony_ci * pointer. Finally, each node is a bucket of a hash table, pointing to the 718c2ecf20Sopenharmony_ci * first element in its chain through its first pointer. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_cistruct l2t_entry { 748c2ecf20Sopenharmony_ci u16 state; /* entry state */ 758c2ecf20Sopenharmony_ci u16 idx; /* entry index within in-memory table */ 768c2ecf20Sopenharmony_ci u32 addr[4]; /* next hop IP or IPv6 address */ 778c2ecf20Sopenharmony_ci int ifindex; /* neighbor's net_device's ifindex */ 788c2ecf20Sopenharmony_ci struct neighbour *neigh; /* associated neighbour */ 798c2ecf20Sopenharmony_ci struct l2t_entry *first; /* start of hash chain */ 808c2ecf20Sopenharmony_ci struct l2t_entry *next; /* next l2t_entry on chain */ 818c2ecf20Sopenharmony_ci struct sk_buff_head arpq; /* packet queue awaiting resolution */ 828c2ecf20Sopenharmony_ci spinlock_t lock; 838c2ecf20Sopenharmony_ci atomic_t refcnt; /* entry reference count */ 848c2ecf20Sopenharmony_ci u16 hash; /* hash bucket the entry is on */ 858c2ecf20Sopenharmony_ci u16 vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */ 868c2ecf20Sopenharmony_ci u8 v6; /* whether entry is for IPv6 */ 878c2ecf20Sopenharmony_ci u8 lport; /* associated offload logical interface */ 888c2ecf20Sopenharmony_ci u8 dmac[ETH_ALEN]; /* neighbour's MAC address */ 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_citypedef void (*arp_err_handler_t)(void *handle, struct sk_buff *skb); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * Callback stored in an skb to handle address resolution failure. 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_cistruct l2t_skb_cb { 978c2ecf20Sopenharmony_ci void *handle; 988c2ecf20Sopenharmony_ci arp_err_handler_t arp_err_handler; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic inline void t4_set_arp_err_handler(struct sk_buff *skb, void *handle, 1048c2ecf20Sopenharmony_ci arp_err_handler_t handler) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci L2T_SKB_CB(skb)->handle = handle; 1078c2ecf20Sopenharmony_ci L2T_SKB_CB(skb)->arp_err_handler = handler; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_civoid cxgb4_l2t_release(struct l2t_entry *e); 1118c2ecf20Sopenharmony_ciint cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb, 1128c2ecf20Sopenharmony_ci struct l2t_entry *e); 1138c2ecf20Sopenharmony_cistruct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh, 1148c2ecf20Sopenharmony_ci const struct net_device *physdev, 1158c2ecf20Sopenharmony_ci unsigned int priority); 1168c2ecf20Sopenharmony_ciu64 cxgb4_select_ntuple(struct net_device *dev, 1178c2ecf20Sopenharmony_ci const struct l2t_entry *l2t); 1188c2ecf20Sopenharmony_cistruct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan, 1198c2ecf20Sopenharmony_ci u8 port, u8 *dmac); 1208c2ecf20Sopenharmony_civoid t4_l2t_update(struct adapter *adap, struct neighbour *neigh); 1218c2ecf20Sopenharmony_cistruct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan, 1228c2ecf20Sopenharmony_ci u8 port, u8 *dmac); 1238c2ecf20Sopenharmony_cistruct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end); 1248c2ecf20Sopenharmony_civoid do_l2t_write_rpl(struct adapter *p, const struct cpl_l2t_write_rpl *rpl); 1258c2ecf20Sopenharmony_cibool cxgb4_check_l2t_valid(struct l2t_entry *e); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciextern const struct file_operations t4_l2t_fops; 1288c2ecf20Sopenharmony_ci#endif /* __CXGB4_L2T_H */ 129