Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. |
| 3 | * |
Anish Bhatt | ce100b8b | 2014-06-19 21:37:15 -0700 | [diff] [blame] | 4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 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 | |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/if.h> |
| 38 | #include <linux/if_vlan.h> |
| 39 | #include <linux/jhash.h> |
Paul Gortmaker | 310587c | 2011-09-15 19:42:40 -0400 | [diff] [blame] | 40 | #include <linux/module.h> |
| 41 | #include <linux/debugfs.h> |
| 42 | #include <linux/seq_file.h> |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 43 | #include <net/neighbour.h> |
| 44 | #include "cxgb4.h" |
| 45 | #include "l2t.h" |
| 46 | #include "t4_msg.h" |
| 47 | #include "t4fw_api.h" |
Kumar Sanghvi | dcf7b6f | 2013-12-18 16:38:23 +0530 | [diff] [blame] | 48 | #include "t4_regs.h" |
Hariprasad Shenai | 0d80433 | 2015-01-05 16:30:47 +0530 | [diff] [blame] | 49 | #include "t4_values.h" |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 50 | |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 51 | /* identifies sync vs async L2T_WRITE_REQs */ |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 52 | #define SYNC_WR_S 12 |
| 53 | #define SYNC_WR_V(x) ((x) << SYNC_WR_S) |
| 54 | #define SYNC_WR_F SYNC_WR_V(1) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 55 | |
| 56 | struct l2t_data { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 57 | unsigned int l2t_start; /* start index of our piece of the L2T */ |
| 58 | unsigned int l2t_size; /* number of entries in l2tab */ |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 59 | rwlock_t lock; |
| 60 | atomic_t nfree; /* number of free entries */ |
| 61 | struct l2t_entry *rover; /* starting point for next allocation */ |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 62 | struct l2t_entry l2tab[0]; /* MUST BE LAST */ |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static inline unsigned int vlan_prio(const struct l2t_entry *e) |
| 66 | { |
Hariprasad Shenai | e41e282 | 2015-12-17 13:45:07 +0530 | [diff] [blame] | 67 | return e->vlan >> VLAN_PRIO_SHIFT; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline void l2t_hold(struct l2t_data *d, struct l2t_entry *e) |
| 71 | { |
| 72 | if (atomic_add_return(1, &e->refcnt) == 1) /* 0 -> 1 transition */ |
| 73 | atomic_dec(&d->nfree); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * To avoid having to check address families we do not allow v4 and v6 |
| 78 | * neighbors to be on the same hash chain. We keep v4 entries in the first |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 79 | * half of available hash buckets and v6 in the second. We need at least two |
| 80 | * entries in our L2T for this scheme to work. |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 81 | */ |
| 82 | enum { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 83 | L2T_MIN_HASH_BUCKETS = 2, |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 86 | static inline unsigned int arp_hash(struct l2t_data *d, const u32 *key, |
| 87 | int ifindex) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 88 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 89 | unsigned int l2t_size_half = d->l2t_size / 2; |
| 90 | |
| 91 | return jhash_2words(*key, ifindex, 0) % l2t_size_half; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 94 | static inline unsigned int ipv6_hash(struct l2t_data *d, const u32 *key, |
| 95 | int ifindex) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 96 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 97 | unsigned int l2t_size_half = d->l2t_size / 2; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 98 | u32 xor = key[0] ^ key[1] ^ key[2] ^ key[3]; |
| 99 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 100 | return (l2t_size_half + |
| 101 | (jhash_2words(xor, ifindex, 0) % l2t_size_half)); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 104 | static unsigned int addr_hash(struct l2t_data *d, const u32 *addr, |
| 105 | int addr_len, int ifindex) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 106 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 107 | return addr_len == 4 ? arp_hash(d, addr, ifindex) : |
| 108 | ipv6_hash(d, addr, ifindex); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Checks if an L2T entry is for the given IP/IPv6 address. It does not check |
| 113 | * whether the L2T entry and the address are of the same address family. |
| 114 | * Callers ensure an address is only checked against L2T entries of the same |
| 115 | * family, something made trivial by the separation of IP and IPv6 hash chains |
| 116 | * mentioned above. Returns 0 if there's a match, |
| 117 | */ |
| 118 | static int addreq(const struct l2t_entry *e, const u32 *addr) |
| 119 | { |
| 120 | if (e->v6) |
| 121 | return (e->addr[0] ^ addr[0]) | (e->addr[1] ^ addr[1]) | |
| 122 | (e->addr[2] ^ addr[2]) | (e->addr[3] ^ addr[3]); |
| 123 | return e->addr[0] ^ addr[0]; |
| 124 | } |
| 125 | |
| 126 | static void neigh_replace(struct l2t_entry *e, struct neighbour *n) |
| 127 | { |
| 128 | neigh_hold(n); |
| 129 | if (e->neigh) |
| 130 | neigh_release(e->neigh); |
| 131 | e->neigh = n; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Write an L2T entry. Must be called with the entry locked. |
| 136 | * The write may be synchronous or asynchronous. |
| 137 | */ |
| 138 | static int write_l2e(struct adapter *adap, struct l2t_entry *e, int sync) |
| 139 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 140 | struct l2t_data *d = adap->l2t; |
| 141 | unsigned int l2t_idx = e->idx + d->l2t_start; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 142 | struct sk_buff *skb; |
| 143 | struct cpl_l2t_write_req *req; |
| 144 | |
| 145 | skb = alloc_skb(sizeof(*req), GFP_ATOMIC); |
| 146 | if (!skb) |
| 147 | return -ENOMEM; |
| 148 | |
| 149 | req = (struct cpl_l2t_write_req *)__skb_put(skb, sizeof(*req)); |
| 150 | INIT_TP_WR(req, 0); |
| 151 | |
| 152 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 153 | l2t_idx | (sync ? SYNC_WR_F : 0) | |
Hariprasad Shenai | 6c53e93 | 2015-01-08 21:38:15 -0800 | [diff] [blame] | 154 | TID_QID_V(adap->sge.fw_evtq.abs_id))); |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 155 | req->params = htons(L2T_W_PORT_V(e->lport) | L2T_W_NOREPLY_V(!sync)); |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 156 | req->l2t_idx = htons(l2t_idx); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 157 | req->vlan = htons(e->vlan); |
Steve Wise | bfae232 | 2014-04-14 14:22:43 -0500 | [diff] [blame] | 158 | if (e->neigh && !(e->neigh->dev->flags & IFF_LOOPBACK)) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 159 | memcpy(e->dmac, e->neigh->ha, sizeof(e->dmac)); |
| 160 | memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac)); |
| 161 | |
Hariprasad Shenai | 9baeb9d | 2015-12-17 13:45:09 +0530 | [diff] [blame] | 162 | t4_mgmt_tx(adap, skb); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 163 | |
| 164 | if (sync && e->state != L2T_STATE_SWITCHING) |
| 165 | e->state = L2T_STATE_SYNC_WRITE; |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * Send packets waiting in an L2T entry's ARP queue. Must be called with the |
| 171 | * entry locked. |
| 172 | */ |
| 173 | static void send_pending(struct adapter *adap, struct l2t_entry *e) |
| 174 | { |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 175 | struct sk_buff *skb; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 176 | |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 177 | while ((skb = __skb_dequeue(&e->arpq)) != NULL) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 178 | t4_ofld_send(adap, skb); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Process a CPL_L2T_WRITE_RPL. Wake up the ARP queue if it completes a |
| 183 | * synchronous L2T_WRITE. Note that the TID in the reply is really the L2T |
| 184 | * index it refers to. |
| 185 | */ |
| 186 | void do_l2t_write_rpl(struct adapter *adap, const struct cpl_l2t_write_rpl *rpl) |
| 187 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 188 | struct l2t_data *d = adap->l2t; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 189 | unsigned int tid = GET_TID(rpl); |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 190 | unsigned int l2t_idx = tid % L2T_SIZE; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 191 | |
| 192 | if (unlikely(rpl->status != CPL_ERR_NONE)) { |
| 193 | dev_err(adap->pdev_dev, |
| 194 | "Unexpected L2T_WRITE_RPL status %u for entry %u\n", |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 195 | rpl->status, l2t_idx); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 196 | return; |
| 197 | } |
| 198 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 199 | if (tid & SYNC_WR_F) { |
| 200 | struct l2t_entry *e = &d->l2tab[l2t_idx - d->l2t_start]; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 201 | |
| 202 | spin_lock(&e->lock); |
| 203 | if (e->state != L2T_STATE_SWITCHING) { |
| 204 | send_pending(adap, e); |
| 205 | e->state = (e->neigh->nud_state & NUD_STALE) ? |
| 206 | L2T_STATE_STALE : L2T_STATE_VALID; |
| 207 | } |
| 208 | spin_unlock(&e->lock); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Add a packet to an L2T entry's queue of packets awaiting resolution. |
| 214 | * Must be called with the entry's lock held. |
| 215 | */ |
| 216 | static inline void arpq_enqueue(struct l2t_entry *e, struct sk_buff *skb) |
| 217 | { |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 218 | __skb_queue_tail(&e->arpq, skb); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | int cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb, |
| 222 | struct l2t_entry *e) |
| 223 | { |
| 224 | struct adapter *adap = netdev2adap(dev); |
| 225 | |
| 226 | again: |
| 227 | switch (e->state) { |
| 228 | case L2T_STATE_STALE: /* entry is stale, kick off revalidation */ |
| 229 | neigh_event_send(e->neigh, NULL); |
| 230 | spin_lock_bh(&e->lock); |
| 231 | if (e->state == L2T_STATE_STALE) |
| 232 | e->state = L2T_STATE_VALID; |
| 233 | spin_unlock_bh(&e->lock); |
| 234 | case L2T_STATE_VALID: /* fast-path, send the packet on */ |
| 235 | return t4_ofld_send(adap, skb); |
| 236 | case L2T_STATE_RESOLVING: |
| 237 | case L2T_STATE_SYNC_WRITE: |
| 238 | spin_lock_bh(&e->lock); |
| 239 | if (e->state != L2T_STATE_SYNC_WRITE && |
| 240 | e->state != L2T_STATE_RESOLVING) { |
| 241 | spin_unlock_bh(&e->lock); |
| 242 | goto again; |
| 243 | } |
| 244 | arpq_enqueue(e, skb); |
| 245 | spin_unlock_bh(&e->lock); |
| 246 | |
| 247 | if (e->state == L2T_STATE_RESOLVING && |
| 248 | !neigh_event_send(e->neigh, NULL)) { |
| 249 | spin_lock_bh(&e->lock); |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 250 | if (e->state == L2T_STATE_RESOLVING && |
| 251 | !skb_queue_empty(&e->arpq)) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 252 | write_l2e(adap, e, 1); |
| 253 | spin_unlock_bh(&e->lock); |
| 254 | } |
| 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | EXPORT_SYMBOL(cxgb4_l2t_send); |
| 259 | |
| 260 | /* |
| 261 | * Allocate a free L2T entry. Must be called with l2t_data.lock held. |
| 262 | */ |
| 263 | static struct l2t_entry *alloc_l2e(struct l2t_data *d) |
| 264 | { |
| 265 | struct l2t_entry *end, *e, **p; |
| 266 | |
| 267 | if (!atomic_read(&d->nfree)) |
| 268 | return NULL; |
| 269 | |
| 270 | /* there's definitely a free entry */ |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 271 | for (e = d->rover, end = &d->l2tab[d->l2t_size]; e != end; ++e) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 272 | if (atomic_read(&e->refcnt) == 0) |
| 273 | goto found; |
| 274 | |
| 275 | for (e = d->l2tab; atomic_read(&e->refcnt); ++e) |
| 276 | ; |
| 277 | found: |
| 278 | d->rover = e + 1; |
| 279 | atomic_dec(&d->nfree); |
| 280 | |
| 281 | /* |
| 282 | * The entry we found may be an inactive entry that is |
| 283 | * presently in the hash table. We need to remove it. |
| 284 | */ |
| 285 | if (e->state < L2T_STATE_SWITCHING) |
| 286 | for (p = &d->l2tab[e->hash].first; *p; p = &(*p)->next) |
| 287 | if (*p == e) { |
| 288 | *p = e->next; |
| 289 | e->next = NULL; |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | e->state = L2T_STATE_UNUSED; |
| 294 | return e; |
| 295 | } |
| 296 | |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 297 | static struct l2t_entry *find_or_alloc_l2e(struct l2t_data *d, u16 vlan, |
| 298 | u8 port, u8 *dmac) |
| 299 | { |
| 300 | struct l2t_entry *end, *e, **p; |
| 301 | struct l2t_entry *first_free = NULL; |
| 302 | |
| 303 | for (e = &d->l2tab[0], end = &d->l2tab[d->l2t_size]; e != end; ++e) { |
| 304 | if (atomic_read(&e->refcnt) == 0) { |
| 305 | if (!first_free) |
| 306 | first_free = e; |
| 307 | } else { |
| 308 | if (e->state == L2T_STATE_SWITCHING) { |
| 309 | if (ether_addr_equal(e->dmac, dmac) && |
| 310 | (e->vlan == vlan) && (e->lport == port)) |
| 311 | goto exists; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | if (first_free) { |
| 317 | e = first_free; |
| 318 | goto found; |
| 319 | } |
| 320 | |
| 321 | return NULL; |
| 322 | |
| 323 | found: |
| 324 | /* The entry we found may be an inactive entry that is |
| 325 | * presently in the hash table. We need to remove it. |
| 326 | */ |
| 327 | if (e->state < L2T_STATE_SWITCHING) |
| 328 | for (p = &d->l2tab[e->hash].first; *p; p = &(*p)->next) |
| 329 | if (*p == e) { |
| 330 | *p = e->next; |
| 331 | e->next = NULL; |
| 332 | break; |
| 333 | } |
| 334 | e->state = L2T_STATE_UNUSED; |
| 335 | |
| 336 | exists: |
| 337 | return e; |
| 338 | } |
| 339 | |
| 340 | /* Called when an L2T entry has no more users. The entry is left in the hash |
| 341 | * table since it is likely to be reused but we also bump nfree to indicate |
| 342 | * that the entry can be reallocated for a different neighbor. We also drop |
| 343 | * the existing neighbor reference in case the neighbor is going away and is |
| 344 | * waiting on our reference. |
| 345 | * |
| 346 | * Because entries can be reallocated to other neighbors once their ref count |
| 347 | * drops to 0 we need to take the entry's lock to avoid races with a new |
| 348 | * incarnation. |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 349 | */ |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 350 | static void _t4_l2e_free(struct l2t_entry *e) |
| 351 | { |
| 352 | struct l2t_data *d; |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 353 | struct sk_buff *skb; |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 354 | |
| 355 | if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */ |
| 356 | if (e->neigh) { |
| 357 | neigh_release(e->neigh); |
| 358 | e->neigh = NULL; |
| 359 | } |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 360 | while ((skb = __skb_dequeue(&e->arpq)) != NULL) |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 361 | kfree_skb(skb); |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | d = container_of(e, struct l2t_data, l2tab[e->idx]); |
| 365 | atomic_inc(&d->nfree); |
| 366 | } |
| 367 | |
| 368 | /* Locked version of _t4_l2e_free */ |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 369 | static void t4_l2e_free(struct l2t_entry *e) |
| 370 | { |
| 371 | struct l2t_data *d; |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 372 | struct sk_buff *skb; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 373 | |
| 374 | spin_lock_bh(&e->lock); |
| 375 | if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */ |
| 376 | if (e->neigh) { |
| 377 | neigh_release(e->neigh); |
| 378 | e->neigh = NULL; |
| 379 | } |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 380 | while ((skb = __skb_dequeue(&e->arpq)) != NULL) |
Denis Kirjanov | 05eda04 | 2010-06-30 23:45:52 +0000 | [diff] [blame] | 381 | kfree_skb(skb); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 382 | } |
| 383 | spin_unlock_bh(&e->lock); |
| 384 | |
| 385 | d = container_of(e, struct l2t_data, l2tab[e->idx]); |
| 386 | atomic_inc(&d->nfree); |
| 387 | } |
| 388 | |
| 389 | void cxgb4_l2t_release(struct l2t_entry *e) |
| 390 | { |
| 391 | if (atomic_dec_and_test(&e->refcnt)) |
| 392 | t4_l2e_free(e); |
| 393 | } |
| 394 | EXPORT_SYMBOL(cxgb4_l2t_release); |
| 395 | |
| 396 | /* |
| 397 | * Update an L2T entry that was previously used for the same next hop as neigh. |
| 398 | * Must be called with softirqs disabled. |
| 399 | */ |
| 400 | static void reuse_entry(struct l2t_entry *e, struct neighbour *neigh) |
| 401 | { |
| 402 | unsigned int nud_state; |
| 403 | |
| 404 | spin_lock(&e->lock); /* avoid race with t4_l2t_free */ |
| 405 | if (neigh != e->neigh) |
| 406 | neigh_replace(e, neigh); |
| 407 | nud_state = neigh->nud_state; |
| 408 | if (memcmp(e->dmac, neigh->ha, sizeof(e->dmac)) || |
| 409 | !(nud_state & NUD_VALID)) |
| 410 | e->state = L2T_STATE_RESOLVING; |
| 411 | else if (nud_state & NUD_CONNECTED) |
| 412 | e->state = L2T_STATE_VALID; |
| 413 | else |
| 414 | e->state = L2T_STATE_STALE; |
| 415 | spin_unlock(&e->lock); |
| 416 | } |
| 417 | |
| 418 | struct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh, |
| 419 | const struct net_device *physdev, |
| 420 | unsigned int priority) |
| 421 | { |
| 422 | u8 lport; |
| 423 | u16 vlan; |
| 424 | struct l2t_entry *e; |
| 425 | int addr_len = neigh->tbl->key_len; |
| 426 | u32 *addr = (u32 *)neigh->primary_key; |
| 427 | int ifidx = neigh->dev->ifindex; |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 428 | int hash = addr_hash(d, addr, addr_len, ifidx); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 429 | |
| 430 | if (neigh->dev->flags & IFF_LOOPBACK) |
| 431 | lport = netdev2pinfo(physdev)->tx_chan + 4; |
| 432 | else |
| 433 | lport = netdev2pinfo(physdev)->lport; |
| 434 | |
Parav Pandit | d0d7b10 | 2017-02-04 11:00:49 -0600 | [diff] [blame] | 435 | if (is_vlan_dev(neigh->dev)) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 436 | vlan = vlan_dev_vlan_id(neigh->dev); |
| 437 | else |
| 438 | vlan = VLAN_NONE; |
| 439 | |
| 440 | write_lock_bh(&d->lock); |
| 441 | for (e = d->l2tab[hash].first; e; e = e->next) |
| 442 | if (!addreq(e, addr) && e->ifindex == ifidx && |
| 443 | e->vlan == vlan && e->lport == lport) { |
| 444 | l2t_hold(d, e); |
| 445 | if (atomic_read(&e->refcnt) == 1) |
| 446 | reuse_entry(e, neigh); |
| 447 | goto done; |
| 448 | } |
| 449 | |
| 450 | /* Need to allocate a new entry */ |
| 451 | e = alloc_l2e(d); |
| 452 | if (e) { |
| 453 | spin_lock(&e->lock); /* avoid race with t4_l2t_free */ |
| 454 | e->state = L2T_STATE_RESOLVING; |
Steve Wise | bfae232 | 2014-04-14 14:22:43 -0500 | [diff] [blame] | 455 | if (neigh->dev->flags & IFF_LOOPBACK) |
| 456 | memcpy(e->dmac, physdev->dev_addr, sizeof(e->dmac)); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 457 | memcpy(e->addr, addr, addr_len); |
| 458 | e->ifindex = ifidx; |
| 459 | e->hash = hash; |
| 460 | e->lport = lport; |
| 461 | e->v6 = addr_len == 16; |
| 462 | atomic_set(&e->refcnt, 1); |
| 463 | neigh_replace(e, neigh); |
| 464 | e->vlan = vlan; |
| 465 | e->next = d->l2tab[hash].first; |
| 466 | d->l2tab[hash].first = e; |
| 467 | spin_unlock(&e->lock); |
| 468 | } |
| 469 | done: |
| 470 | write_unlock_bh(&d->lock); |
| 471 | return e; |
| 472 | } |
| 473 | EXPORT_SYMBOL(cxgb4_l2t_get); |
| 474 | |
Kumar Sanghvi | dcf7b6f | 2013-12-18 16:38:23 +0530 | [diff] [blame] | 475 | u64 cxgb4_select_ntuple(struct net_device *dev, |
| 476 | const struct l2t_entry *l2t) |
| 477 | { |
| 478 | struct adapter *adap = netdev2adap(dev); |
| 479 | struct tp_params *tp = &adap->params.tp; |
| 480 | u64 ntuple = 0; |
| 481 | |
| 482 | /* Initialize each of the fields which we care about which are present |
| 483 | * in the Compressed Filter Tuple. |
| 484 | */ |
| 485 | if (tp->vlan_shift >= 0 && l2t->vlan != VLAN_NONE) |
Hariprasad Shenai | 0d80433 | 2015-01-05 16:30:47 +0530 | [diff] [blame] | 486 | ntuple |= (u64)(FT_VLAN_VLD_F | l2t->vlan) << tp->vlan_shift; |
Kumar Sanghvi | dcf7b6f | 2013-12-18 16:38:23 +0530 | [diff] [blame] | 487 | |
| 488 | if (tp->port_shift >= 0) |
| 489 | ntuple |= (u64)l2t->lport << tp->port_shift; |
| 490 | |
| 491 | if (tp->protocol_shift >= 0) |
| 492 | ntuple |= (u64)IPPROTO_TCP << tp->protocol_shift; |
| 493 | |
| 494 | if (tp->vnic_shift >= 0) { |
| 495 | u32 viid = cxgb4_port_viid(dev); |
Hariprasad Shenai | 2b5fb1f | 2014-11-21 12:52:04 +0530 | [diff] [blame] | 496 | u32 vf = FW_VIID_VIN_G(viid); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 497 | u32 pf = FW_VIID_PFN_G(viid); |
Hariprasad Shenai | 2b5fb1f | 2014-11-21 12:52:04 +0530 | [diff] [blame] | 498 | u32 vld = FW_VIID_VIVLD_G(viid); |
Kumar Sanghvi | dcf7b6f | 2013-12-18 16:38:23 +0530 | [diff] [blame] | 499 | |
Hariprasad Shenai | 0d80433 | 2015-01-05 16:30:47 +0530 | [diff] [blame] | 500 | ntuple |= (u64)(FT_VNID_ID_VF_V(vf) | |
| 501 | FT_VNID_ID_PF_V(pf) | |
| 502 | FT_VNID_ID_VLD_V(vld)) << tp->vnic_shift; |
Kumar Sanghvi | dcf7b6f | 2013-12-18 16:38:23 +0530 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | return ntuple; |
| 506 | } |
| 507 | EXPORT_SYMBOL(cxgb4_select_ntuple); |
| 508 | |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 509 | /* |
| 510 | * Called when address resolution fails for an L2T entry to handle packets |
| 511 | * on the arpq head. If a packet specifies a failure handler it is invoked, |
| 512 | * otherwise the packet is sent to the device. |
| 513 | */ |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 514 | static void handle_failed_resolution(struct adapter *adap, struct l2t_entry *e) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 515 | { |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 516 | struct sk_buff *skb; |
| 517 | |
| 518 | while ((skb = __skb_dequeue(&e->arpq)) != NULL) { |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 519 | const struct l2t_skb_cb *cb = L2T_SKB_CB(skb); |
| 520 | |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 521 | spin_unlock(&e->lock); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 522 | if (cb->arp_err_handler) |
| 523 | cb->arp_err_handler(cb->handle, skb); |
| 524 | else |
| 525 | t4_ofld_send(adap, skb); |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 526 | spin_lock(&e->lock); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| 530 | /* |
| 531 | * Called when the host's neighbor layer makes a change to some entry that is |
| 532 | * loaded into the HW L2 table. |
| 533 | */ |
| 534 | void t4_l2t_update(struct adapter *adap, struct neighbour *neigh) |
| 535 | { |
| 536 | struct l2t_entry *e; |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 537 | struct sk_buff_head *arpq = NULL; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 538 | struct l2t_data *d = adap->l2t; |
| 539 | int addr_len = neigh->tbl->key_len; |
| 540 | u32 *addr = (u32 *) neigh->primary_key; |
| 541 | int ifidx = neigh->dev->ifindex; |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 542 | int hash = addr_hash(d, addr, addr_len, ifidx); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 543 | |
| 544 | read_lock_bh(&d->lock); |
| 545 | for (e = d->l2tab[hash].first; e; e = e->next) |
| 546 | if (!addreq(e, addr) && e->ifindex == ifidx) { |
| 547 | spin_lock(&e->lock); |
| 548 | if (atomic_read(&e->refcnt)) |
| 549 | goto found; |
| 550 | spin_unlock(&e->lock); |
| 551 | break; |
| 552 | } |
| 553 | read_unlock_bh(&d->lock); |
| 554 | return; |
| 555 | |
| 556 | found: |
| 557 | read_unlock(&d->lock); |
| 558 | |
| 559 | if (neigh != e->neigh) |
| 560 | neigh_replace(e, neigh); |
| 561 | |
| 562 | if (e->state == L2T_STATE_RESOLVING) { |
| 563 | if (neigh->nud_state & NUD_FAILED) { |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 564 | arpq = &e->arpq; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 565 | } else if ((neigh->nud_state & (NUD_CONNECTED | NUD_STALE)) && |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 566 | !skb_queue_empty(&e->arpq)) { |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 567 | write_l2e(adap, e, 1); |
| 568 | } |
| 569 | } else { |
| 570 | e->state = neigh->nud_state & NUD_CONNECTED ? |
| 571 | L2T_STATE_VALID : L2T_STATE_STALE; |
| 572 | if (memcmp(e->dmac, neigh->ha, sizeof(e->dmac))) |
| 573 | write_l2e(adap, e, 0); |
| 574 | } |
| 575 | |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 576 | if (arpq) |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 577 | handle_failed_resolution(adap, e); |
| 578 | spin_unlock_bh(&e->lock); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 581 | /* Allocate an L2T entry for use by a switching rule. Such need to be |
| 582 | * explicitly freed and while busy they are not on any hash chain, so normal |
| 583 | * address resolution updates do not see them. |
| 584 | */ |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 585 | struct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan, |
| 586 | u8 port, u8 *eth_addr) |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 587 | { |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 588 | struct l2t_data *d = adap->l2t; |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 589 | struct l2t_entry *e; |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 590 | int ret; |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 591 | |
| 592 | write_lock_bh(&d->lock); |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 593 | e = find_or_alloc_l2e(d, vlan, port, eth_addr); |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 594 | if (e) { |
| 595 | spin_lock(&e->lock); /* avoid race with t4_l2t_free */ |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 596 | if (!atomic_read(&e->refcnt)) { |
| 597 | e->state = L2T_STATE_SWITCHING; |
| 598 | e->vlan = vlan; |
| 599 | e->lport = port; |
| 600 | ether_addr_copy(e->dmac, eth_addr); |
| 601 | atomic_set(&e->refcnt, 1); |
| 602 | ret = write_l2e(adap, e, 0); |
| 603 | if (ret < 0) { |
| 604 | _t4_l2e_free(e); |
| 605 | spin_unlock(&e->lock); |
| 606 | write_unlock_bh(&d->lock); |
| 607 | return NULL; |
| 608 | } |
| 609 | } else { |
| 610 | atomic_inc(&e->refcnt); |
| 611 | } |
| 612 | |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 613 | spin_unlock(&e->lock); |
| 614 | } |
| 615 | write_unlock_bh(&d->lock); |
| 616 | return e; |
| 617 | } |
| 618 | |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 619 | /** |
| 620 | * @dev: net_device pointer |
| 621 | * @vlan: VLAN Id |
| 622 | * @port: Associated port |
| 623 | * @dmac: Destination MAC address to add to L2T |
| 624 | * Returns pointer to the allocated l2t entry |
| 625 | * |
| 626 | * Allocates an L2T entry for use by switching rule of a filter |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 627 | */ |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 628 | struct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan, |
| 629 | u8 port, u8 *dmac) |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 630 | { |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 631 | struct adapter *adap = netdev2adap(dev); |
| 632 | |
| 633 | return t4_l2t_alloc_switching(adap, vlan, port, dmac); |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 634 | } |
Hariprasad Shenai | f750265 | 2015-12-17 13:45:08 +0530 | [diff] [blame] | 635 | EXPORT_SYMBOL(cxgb4_l2t_alloc_switching); |
Vipul Pandya | f2b7e78 | 2012-12-10 09:30:52 +0000 | [diff] [blame] | 636 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 637 | struct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end) |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 638 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 639 | unsigned int l2t_size; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 640 | int i; |
| 641 | struct l2t_data *d; |
| 642 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 643 | if (l2t_start >= l2t_end || l2t_end >= L2T_SIZE) |
| 644 | return NULL; |
| 645 | l2t_size = l2t_end - l2t_start + 1; |
| 646 | if (l2t_size < L2T_MIN_HASH_BUCKETS) |
| 647 | return NULL; |
| 648 | |
| 649 | d = t4_alloc_mem(sizeof(*d) + l2t_size * sizeof(struct l2t_entry)); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 650 | if (!d) |
| 651 | return NULL; |
| 652 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 653 | d->l2t_start = l2t_start; |
| 654 | d->l2t_size = l2t_size; |
| 655 | |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 656 | d->rover = d->l2tab; |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 657 | atomic_set(&d->nfree, l2t_size); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 658 | rwlock_init(&d->lock); |
| 659 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 660 | for (i = 0; i < d->l2t_size; ++i) { |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 661 | d->l2tab[i].idx = i; |
| 662 | d->l2tab[i].state = L2T_STATE_UNUSED; |
| 663 | spin_lock_init(&d->l2tab[i].lock); |
| 664 | atomic_set(&d->l2tab[i].refcnt, 0); |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 665 | skb_queue_head_init(&d->l2tab[i].arpq); |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 666 | } |
| 667 | return d; |
| 668 | } |
| 669 | |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 670 | static inline void *l2t_get_idx(struct seq_file *seq, loff_t pos) |
| 671 | { |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 672 | struct l2t_data *d = seq->private; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 673 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 674 | return pos >= d->l2t_size ? NULL : &d->l2tab[pos]; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static void *l2t_seq_start(struct seq_file *seq, loff_t *pos) |
| 678 | { |
| 679 | return *pos ? l2t_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
| 680 | } |
| 681 | |
| 682 | static void *l2t_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 683 | { |
| 684 | v = l2t_get_idx(seq, *pos); |
| 685 | if (v) |
| 686 | ++*pos; |
| 687 | return v; |
| 688 | } |
| 689 | |
| 690 | static void l2t_seq_stop(struct seq_file *seq, void *v) |
| 691 | { |
| 692 | } |
| 693 | |
| 694 | static char l2e_state(const struct l2t_entry *e) |
| 695 | { |
| 696 | switch (e->state) { |
| 697 | case L2T_STATE_VALID: return 'V'; |
| 698 | case L2T_STATE_STALE: return 'S'; |
| 699 | case L2T_STATE_SYNC_WRITE: return 'W'; |
Hariprasad Shenai | 749cb5f | 2015-12-17 13:45:10 +0530 | [diff] [blame] | 700 | case L2T_STATE_RESOLVING: |
| 701 | return skb_queue_empty(&e->arpq) ? 'R' : 'A'; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 702 | case L2T_STATE_SWITCHING: return 'X'; |
| 703 | default: |
| 704 | return 'U'; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | static int l2t_seq_show(struct seq_file *seq, void *v) |
| 709 | { |
| 710 | if (v == SEQ_START_TOKEN) |
| 711 | seq_puts(seq, " Idx IP address " |
| 712 | "Ethernet address VLAN/P LP State Users Port\n"); |
| 713 | else { |
| 714 | char ip[60]; |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 715 | struct l2t_data *d = seq->private; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 716 | struct l2t_entry *e = v; |
| 717 | |
| 718 | spin_lock_bh(&e->lock); |
| 719 | if (e->state == L2T_STATE_SWITCHING) |
| 720 | ip[0] = '\0'; |
| 721 | else |
| 722 | sprintf(ip, e->v6 ? "%pI6c" : "%pI4", e->addr); |
| 723 | seq_printf(seq, "%4u %-25s %17pM %4d %u %2u %c %5u %s\n", |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 724 | e->idx + d->l2t_start, ip, e->dmac, |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 725 | e->vlan & VLAN_VID_MASK, vlan_prio(e), e->lport, |
| 726 | l2e_state(e), atomic_read(&e->refcnt), |
| 727 | e->neigh ? e->neigh->dev->name : ""); |
| 728 | spin_unlock_bh(&e->lock); |
| 729 | } |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static const struct seq_operations l2t_seq_ops = { |
| 734 | .start = l2t_seq_start, |
| 735 | .next = l2t_seq_next, |
| 736 | .stop = l2t_seq_stop, |
| 737 | .show = l2t_seq_show |
| 738 | }; |
| 739 | |
| 740 | static int l2t_seq_open(struct inode *inode, struct file *file) |
| 741 | { |
| 742 | int rc = seq_open(file, &l2t_seq_ops); |
| 743 | |
| 744 | if (!rc) { |
| 745 | struct adapter *adap = inode->i_private; |
| 746 | struct seq_file *seq = file->private_data; |
| 747 | |
Hariprasad Shenai | 5be9ed8 | 2015-07-07 21:49:18 +0530 | [diff] [blame] | 748 | seq->private = adap->l2t; |
Dimitris Michailidis | 625ba2c | 2010-04-01 15:28:25 +0000 | [diff] [blame] | 749 | } |
| 750 | return rc; |
| 751 | } |
| 752 | |
| 753 | const struct file_operations t4_l2t_fops = { |
| 754 | .owner = THIS_MODULE, |
| 755 | .open = l2t_seq_open, |
| 756 | .read = seq_read, |
| 757 | .llseek = seq_lseek, |
| 758 | .release = seq_release, |
| 759 | }; |