/*******************************************************************************
*
* Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenFabrics.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/if_vlan.h>
#include <linux/crc32.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/init.h>
#include <linux/io.h>
#include <asm/irq.h>
#include <asm/byteorder.h>
#include <net/netevent.h>
#include <net/neighbour.h>
#include "i40iw.h"
/**
* i40iw_arp_table - manage arp table
* @iwdev: iwarp device
* @ip_addr: ip address for device
* @mac_addr: mac address ptr
* @action: modify, delete or add
*/
int i40iw_arp_table(struct i40iw_device *iwdev,
u32 *ip_addr,
bool ipv4,
u8 *mac_addr,
u32 action)
{
int arp_index;
int err;
u32 ip[4];
if (ipv4) {
memset(ip, 0, sizeof(ip));
ip[0] = *ip_addr;
} else {
memcpy(ip, ip_addr, sizeof(ip));
}
for (arp_index = 0; (u32)arp_index < iwdev->arp_table_size; arp_index++)
if (memcmp(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip)) == 0)
break;
switch (action) {
case I40IW_ARP_ADD:
if (arp_index != iwdev->arp_table_size)
return -1;
arp_index = 0;
err = i40iw_alloc_resource(iwdev, iwdev->allocated_arps,
iwdev->arp_table_size,
(u32 *)&arp_index,
&iwdev->next_arp_index);
if (err)
return err;
memcpy(iwdev->arp_table[arp_index].ip_addr, ip, sizeof(ip));
ether_addr_copy(iwdev->arp_table[arp_index].mac_addr, mac_addr);
break;
case I40IW_ARP_RESOLVE:
if (arp_index ==