2014-08-07 22:14:28 +00:00
|
|
|
/* Applied Micro X-Gene SoC Ethernet Driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014, Applied Micro Circuits Corporation
|
|
|
|
* Authors: Iyappan Subramanian <isubramanian@apm.com>
|
|
|
|
* Ravi Patel <rapatel@apm.com>
|
|
|
|
* Keyur Chudgar <kchudgar@apm.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xgene_enet_main.h"
|
|
|
|
#include "xgene_enet_hw.h"
|
2014-10-14 00:05:34 +00:00
|
|
|
#include "xgene_enet_sgmac.h"
|
2014-10-10 01:32:06 +00:00
|
|
|
#include "xgene_enet_xgmac.h"
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
#define RES_ENET_CSR 0
|
|
|
|
#define RES_RING_CSR 1
|
|
|
|
#define RES_RING_CMD 2
|
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
static const struct of_device_id xgene_enet_of_match[];
|
2015-06-23 09:17:14 +00:00
|
|
|
static const struct acpi_device_id xgene_enet_acpi_match[];
|
2015-04-28 20:52:39 +00:00
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static void xgene_enet_init_bufpool(struct xgene_enet_desc_ring *buf_pool)
|
|
|
|
{
|
|
|
|
struct xgene_enet_raw_desc16 *raw_desc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < buf_pool->slots; i++) {
|
|
|
|
raw_desc = &buf_pool->raw_desc16[i];
|
|
|
|
|
|
|
|
/* Hardware expects descriptor in little endian format */
|
|
|
|
raw_desc->m0 = cpu_to_le64(i |
|
|
|
|
SET_VAL(FPQNUM, buf_pool->dst_ring_num) |
|
|
|
|
SET_VAL(STASH, 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_refill_bufpool(struct xgene_enet_desc_ring *buf_pool,
|
|
|
|
u32 nbuf)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct xgene_enet_raw_desc16 *raw_desc;
|
2015-04-28 20:52:37 +00:00
|
|
|
struct xgene_enet_pdata *pdata;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct net_device *ndev;
|
|
|
|
struct device *dev;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
u32 tail = buf_pool->tail;
|
|
|
|
u32 slots = buf_pool->slots - 1;
|
|
|
|
u16 bufdatalen, len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ndev = buf_pool->ndev;
|
|
|
|
dev = ndev_to_dev(buf_pool->ndev);
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata = netdev_priv(ndev);
|
2014-08-07 22:14:28 +00:00
|
|
|
bufdatalen = BUF_LEN_CODE_2K | (SKB_BUFFER_SIZE & GENMASK(11, 0));
|
|
|
|
len = XGENE_ENET_MAX_MTU;
|
|
|
|
|
|
|
|
for (i = 0; i < nbuf; i++) {
|
|
|
|
raw_desc = &buf_pool->raw_desc16[tail];
|
|
|
|
|
|
|
|
skb = netdev_alloc_skb_ip_align(ndev, len);
|
|
|
|
if (unlikely(!skb))
|
|
|
|
return -ENOMEM;
|
|
|
|
buf_pool->rx_skb[tail] = skb;
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(dev, skb->data, len, DMA_FROM_DEVICE);
|
|
|
|
if (dma_mapping_error(dev, dma_addr)) {
|
|
|
|
netdev_err(ndev, "DMA mapping error\n");
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_desc->m1 = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) |
|
|
|
|
SET_VAL(BUFDATALEN, bufdatalen) |
|
|
|
|
SET_BIT(COHERENT));
|
|
|
|
tail = (tail + 1) & slots;
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata->ring_ops->wr_cmd(buf_pool, nbuf);
|
2014-08-07 22:14:28 +00:00
|
|
|
buf_pool->tail = tail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 xgene_enet_hdr_len(const void *data)
|
|
|
|
{
|
|
|
|
const struct ethhdr *eth = data;
|
|
|
|
|
|
|
|
return (eth->h_proto == htons(ETH_P_8021Q)) ? VLAN_ETH_HLEN : ETH_HLEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_delete_bufpool(struct xgene_enet_desc_ring *buf_pool)
|
|
|
|
{
|
2015-04-28 20:52:37 +00:00
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(buf_pool->ndev);
|
2014-08-07 22:14:28 +00:00
|
|
|
struct xgene_enet_raw_desc16 *raw_desc;
|
|
|
|
u32 slots = buf_pool->slots - 1;
|
|
|
|
u32 tail = buf_pool->tail;
|
|
|
|
u32 userinfo;
|
|
|
|
int i, len;
|
|
|
|
|
2015-04-28 20:52:37 +00:00
|
|
|
len = pdata->ring_ops->len(buf_pool);
|
2014-08-07 22:14:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tail = (tail - 1) & slots;
|
|
|
|
raw_desc = &buf_pool->raw_desc16[tail];
|
|
|
|
|
|
|
|
/* Hardware stores descriptor in little endian format */
|
|
|
|
userinfo = GET_VAL(USERINFO, le64_to_cpu(raw_desc->m0));
|
|
|
|
dev_kfree_skb_any(buf_pool->rx_skb[userinfo]);
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata->ring_ops->wr_cmd(buf_pool, -len);
|
2014-08-07 22:14:28 +00:00
|
|
|
buf_pool->tail = tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t xgene_enet_rx_irq(const int irq, void *data)
|
|
|
|
{
|
|
|
|
struct xgene_enet_desc_ring *rx_ring = data;
|
|
|
|
|
|
|
|
if (napi_schedule_prep(&rx_ring->napi)) {
|
|
|
|
disable_irq_nosync(irq);
|
|
|
|
__napi_schedule(&rx_ring->napi);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_tx_completion(struct xgene_enet_desc_ring *cp_ring,
|
|
|
|
struct xgene_enet_raw_desc *raw_desc)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct device *dev;
|
2015-08-26 18:48:06 +00:00
|
|
|
skb_frag_t *frag;
|
|
|
|
dma_addr_t *frag_dma_addr;
|
2014-08-07 22:14:28 +00:00
|
|
|
u16 skb_index;
|
|
|
|
u8 status;
|
2015-08-26 18:48:06 +00:00
|
|
|
int i, ret = 0;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
skb_index = GET_VAL(USERINFO, le64_to_cpu(raw_desc->m0));
|
|
|
|
skb = cp_ring->cp_skb[skb_index];
|
2015-08-26 18:48:06 +00:00
|
|
|
frag_dma_addr = &cp_ring->frag_dma_addr[skb_index * MAX_SKB_FRAGS];
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
dev = ndev_to_dev(cp_ring->ndev);
|
|
|
|
dma_unmap_single(dev, GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)),
|
2015-08-26 18:48:06 +00:00
|
|
|
skb_headlen(skb),
|
2014-08-07 22:14:28 +00:00
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
|
|
|
frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
dma_unmap_page(dev, frag_dma_addr[i], skb_frag_size(frag),
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
/* Checking for error */
|
|
|
|
status = GET_VAL(LERR, le64_to_cpu(raw_desc->m0));
|
|
|
|
if (unlikely(status > 2)) {
|
|
|
|
xgene_enet_parse_error(cp_ring, netdev_priv(cp_ring->ndev),
|
|
|
|
status);
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (likely(skb)) {
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
} else {
|
|
|
|
netdev_err(cp_ring->ndev, "completion skb is NULL\n");
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 xgene_enet_work_msg(struct sk_buff *skb)
|
|
|
|
{
|
2015-08-26 18:48:06 +00:00
|
|
|
struct net_device *ndev = skb->dev;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct iphdr *iph;
|
2015-08-26 18:48:06 +00:00
|
|
|
u8 l3hlen = 0, l4hlen = 0;
|
|
|
|
u8 ethhdr, proto = 0, csum_enable = 0;
|
|
|
|
u64 hopinfo = 0;
|
|
|
|
u32 hdr_len, mss = 0;
|
|
|
|
u32 i, len, nr_frags;
|
|
|
|
|
|
|
|
ethhdr = xgene_enet_hdr_len(skb->data);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
if (unlikely(skb->protocol != htons(ETH_P_IP)) &&
|
|
|
|
unlikely(skb->protocol != htons(ETH_P_8021Q)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (unlikely(!(skb->dev->features & NETIF_F_IP_CSUM)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
iph = ip_hdr(skb);
|
|
|
|
if (unlikely(ip_is_fragment(iph)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (likely(iph->protocol == IPPROTO_TCP)) {
|
|
|
|
l4hlen = tcp_hdrlen(skb) >> 2;
|
|
|
|
csum_enable = 1;
|
|
|
|
proto = TSO_IPPROTO_TCP;
|
2015-08-26 18:48:06 +00:00
|
|
|
if (ndev->features & NETIF_F_TSO) {
|
|
|
|
hdr_len = ethhdr + ip_hdrlen(skb) + tcp_hdrlen(skb);
|
|
|
|
mss = skb_shinfo(skb)->gso_size;
|
|
|
|
|
|
|
|
if (skb_is_nonlinear(skb)) {
|
|
|
|
len = skb_headlen(skb);
|
|
|
|
nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
|
|
|
|
for (i = 0; i < 2 && i < nr_frags; i++)
|
|
|
|
len += skb_shinfo(skb)->frags[i].size;
|
|
|
|
|
|
|
|
/* HW requires header must reside in 3 buffer */
|
|
|
|
if (unlikely(hdr_len > len)) {
|
|
|
|
if (skb_linearize(skb))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mss || ((skb->len - hdr_len) <= mss))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
hopinfo |= SET_BIT(ET);
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
} else if (iph->protocol == IPPROTO_UDP) {
|
|
|
|
l4hlen = UDP_HDR_SIZE;
|
|
|
|
csum_enable = 1;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
l3hlen = ip_hdrlen(skb) >> 2;
|
2015-08-26 18:48:06 +00:00
|
|
|
hopinfo |= SET_VAL(TCPHDR, l4hlen) |
|
2014-08-07 22:14:28 +00:00
|
|
|
SET_VAL(IPHDR, l3hlen) |
|
|
|
|
SET_VAL(ETHHDR, ethhdr) |
|
|
|
|
SET_VAL(EC, csum_enable) |
|
|
|
|
SET_VAL(IS, proto) |
|
|
|
|
SET_BIT(IC) |
|
|
|
|
SET_BIT(TYPE_ETH_WORK_MESSAGE);
|
|
|
|
|
|
|
|
return hopinfo;
|
|
|
|
}
|
|
|
|
|
2015-08-26 18:48:05 +00:00
|
|
|
static u16 xgene_enet_encode_len(u16 len)
|
|
|
|
{
|
|
|
|
return (len == BUFLEN_16K) ? 0 : len;
|
|
|
|
}
|
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
static void xgene_set_addr_len(__le64 *desc, u32 idx, dma_addr_t addr, u32 len)
|
|
|
|
{
|
|
|
|
desc[idx ^ 1] = cpu_to_le64(SET_VAL(DATAADDR, addr) |
|
|
|
|
SET_VAL(BUFDATALEN, len));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __le64 *xgene_enet_get_exp_bufs(struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
|
|
|
__le64 *exp_bufs;
|
|
|
|
|
|
|
|
exp_bufs = &ring->exp_bufs[ring->exp_buf_tail * MAX_EXP_BUFFS];
|
|
|
|
memset(exp_bufs, 0, sizeof(__le64) * MAX_EXP_BUFFS);
|
|
|
|
ring->exp_buf_tail = (ring->exp_buf_tail + 1) & ((ring->slots / 2) - 1);
|
|
|
|
|
|
|
|
return exp_bufs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dma_addr_t *xgene_get_frag_dma_array(struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
|
|
|
return &ring->cp_ring->frag_dma_addr[ring->tail * MAX_SKB_FRAGS];
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static int xgene_enet_setup_tx_desc(struct xgene_enet_desc_ring *tx_ring,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct device *dev = ndev_to_dev(tx_ring->ndev);
|
2015-12-17 06:26:05 +00:00
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(tx_ring->ndev);
|
2014-08-07 22:14:28 +00:00
|
|
|
struct xgene_enet_raw_desc *raw_desc;
|
2015-08-26 18:48:06 +00:00
|
|
|
__le64 *exp_desc = NULL, *exp_bufs = NULL;
|
|
|
|
dma_addr_t dma_addr, pbuf_addr, *frag_dma_addr;
|
|
|
|
skb_frag_t *frag;
|
2014-08-07 22:14:28 +00:00
|
|
|
u16 tail = tx_ring->tail;
|
|
|
|
u64 hopinfo;
|
2015-08-26 18:48:05 +00:00
|
|
|
u32 len, hw_len;
|
2015-08-26 18:48:06 +00:00
|
|
|
u8 ll = 0, nv = 0, idx = 0;
|
|
|
|
bool split = false;
|
|
|
|
u32 size, offset, ell_bytes = 0;
|
|
|
|
u32 i, fidx, nr_frags, count = 1;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
raw_desc = &tx_ring->raw_desc[tail];
|
2015-08-26 18:48:06 +00:00
|
|
|
tail = (tail + 1) & (tx_ring->slots - 1);
|
2014-08-07 22:14:28 +00:00
|
|
|
memset(raw_desc, 0, sizeof(struct xgene_enet_raw_desc));
|
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
hopinfo = xgene_enet_work_msg(skb);
|
|
|
|
if (!hopinfo)
|
|
|
|
return -EINVAL;
|
|
|
|
raw_desc->m3 = cpu_to_le64(SET_VAL(HENQNUM, tx_ring->dst_ring_num) |
|
|
|
|
hopinfo);
|
|
|
|
|
2015-08-26 18:48:05 +00:00
|
|
|
len = skb_headlen(skb);
|
|
|
|
hw_len = xgene_enet_encode_len(len);
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE);
|
2014-08-07 22:14:28 +00:00
|
|
|
if (dma_mapping_error(dev, dma_addr)) {
|
|
|
|
netdev_err(tx_ring->ndev, "DMA mapping error\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hardware expects descriptor in little endian format */
|
|
|
|
raw_desc->m1 = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) |
|
2015-08-26 18:48:05 +00:00
|
|
|
SET_VAL(BUFDATALEN, hw_len) |
|
2014-08-07 22:14:28 +00:00
|
|
|
SET_BIT(COHERENT));
|
2015-08-26 18:48:05 +00:00
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
if (!skb_is_nonlinear(skb))
|
|
|
|
goto out;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
/* scatter gather */
|
|
|
|
nv = 1;
|
|
|
|
exp_desc = (void *)&tx_ring->raw_desc[tail];
|
2015-08-26 18:48:05 +00:00
|
|
|
tail = (tail + 1) & (tx_ring->slots - 1);
|
2015-08-26 18:48:06 +00:00
|
|
|
memset(exp_desc, 0, sizeof(struct xgene_enet_raw_desc));
|
|
|
|
|
|
|
|
nr_frags = skb_shinfo(skb)->nr_frags;
|
|
|
|
for (i = nr_frags; i < 4 ; i++)
|
|
|
|
exp_desc[i ^ 1] = cpu_to_le64(LAST_BUFFER);
|
|
|
|
|
|
|
|
frag_dma_addr = xgene_get_frag_dma_array(tx_ring);
|
|
|
|
|
|
|
|
for (i = 0, fidx = 0; split || (fidx < nr_frags); i++) {
|
|
|
|
if (!split) {
|
|
|
|
frag = &skb_shinfo(skb)->frags[fidx];
|
|
|
|
size = skb_frag_size(frag);
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
pbuf_addr = skb_frag_dma_map(dev, frag, 0, size,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
if (dma_mapping_error(dev, pbuf_addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
frag_dma_addr[fidx] = pbuf_addr;
|
|
|
|
fidx++;
|
|
|
|
|
|
|
|
if (size > BUFLEN_16K)
|
|
|
|
split = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > BUFLEN_16K) {
|
|
|
|
len = BUFLEN_16K;
|
|
|
|
size -= BUFLEN_16K;
|
|
|
|
} else {
|
|
|
|
len = size;
|
|
|
|
split = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_addr = pbuf_addr + offset;
|
|
|
|
hw_len = xgene_enet_encode_len(len);
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
xgene_set_addr_len(exp_desc, i, dma_addr, hw_len);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (split || (fidx != nr_frags)) {
|
|
|
|
exp_bufs = xgene_enet_get_exp_bufs(tx_ring);
|
|
|
|
xgene_set_addr_len(exp_bufs, idx, dma_addr,
|
|
|
|
hw_len);
|
|
|
|
idx++;
|
|
|
|
ell_bytes += len;
|
|
|
|
} else {
|
|
|
|
xgene_set_addr_len(exp_desc, i, dma_addr,
|
|
|
|
hw_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xgene_set_addr_len(exp_bufs, idx, dma_addr, hw_len);
|
|
|
|
idx++;
|
|
|
|
ell_bytes += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (split)
|
|
|
|
offset += BUFLEN_16K;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (idx) {
|
|
|
|
ll = 1;
|
|
|
|
dma_addr = dma_map_single(dev, exp_bufs,
|
|
|
|
sizeof(u64) * MAX_EXP_BUFFS,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
if (dma_mapping_error(dev, dma_addr)) {
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
i = ell_bytes >> LL_BYTES_LSB_LEN;
|
|
|
|
exp_desc[2] = cpu_to_le64(SET_VAL(DATAADDR, dma_addr) |
|
|
|
|
SET_VAL(LL_BYTES_MSB, i) |
|
|
|
|
SET_VAL(LL_LEN, idx));
|
|
|
|
raw_desc->m2 = cpu_to_le64(SET_VAL(LL_BYTES_LSB, ell_bytes));
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
raw_desc->m0 = cpu_to_le64(SET_VAL(LL, ll) | SET_VAL(NV, nv) |
|
|
|
|
SET_VAL(USERINFO, tx_ring->tail));
|
|
|
|
tx_ring->cp_ring->cp_skb[tx_ring->tail] = skb;
|
2016-02-17 23:00:41 +00:00
|
|
|
pdata->tx_level[tx_ring->cp_ring->index] += count;
|
2015-08-26 18:48:05 +00:00
|
|
|
tx_ring->tail = tail;
|
|
|
|
|
|
|
|
return count;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static netdev_tx_t xgene_enet_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
2016-02-17 23:00:41 +00:00
|
|
|
struct xgene_enet_desc_ring *tx_ring;
|
|
|
|
int index = skb->queue_mapping;
|
|
|
|
u32 tx_level = pdata->tx_level[index];
|
2015-08-26 18:48:05 +00:00
|
|
|
int count;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
tx_ring = pdata->tx_ring[index];
|
|
|
|
if (tx_level < pdata->txc_level[index])
|
|
|
|
tx_level += ((typeof(pdata->tx_level[index]))~0U);
|
2015-12-17 06:26:05 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
if ((tx_level - pdata->txc_level[index]) > pdata->tx_qcnt_hi) {
|
|
|
|
netif_stop_subqueue(ndev, index);
|
2014-08-07 22:14:28 +00:00
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
if (skb_padto(skb, XGENE_MIN_ENET_FRAME_SIZE))
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
|
2015-08-26 18:48:05 +00:00
|
|
|
count = xgene_enet_setup_tx_desc(tx_ring, skb);
|
|
|
|
if (count <= 0) {
|
2014-08-07 22:14:28 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_tx_timestamp(skb);
|
|
|
|
|
2016-05-13 23:53:00 +00:00
|
|
|
tx_ring->tx_packets++;
|
|
|
|
tx_ring->tx_bytes += skb->len;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-11-25 17:02:10 +00:00
|
|
|
pdata->ring_ops->wr_cmd(tx_ring, count);
|
2014-08-07 22:14:28 +00:00
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_skip_csum(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct iphdr *iph = ip_hdr(skb);
|
|
|
|
|
|
|
|
if (!ip_is_fragment(iph) ||
|
|
|
|
(iph->protocol != IPPROTO_TCP && iph->protocol != IPPROTO_UDP)) {
|
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_rx_frame(struct xgene_enet_desc_ring *rx_ring,
|
|
|
|
struct xgene_enet_raw_desc *raw_desc)
|
|
|
|
{
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct xgene_enet_pdata *pdata;
|
|
|
|
struct device *dev;
|
|
|
|
struct xgene_enet_desc_ring *buf_pool;
|
|
|
|
u32 datalen, skb_index;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
u8 status;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ndev = rx_ring->ndev;
|
|
|
|
pdata = netdev_priv(ndev);
|
|
|
|
dev = ndev_to_dev(rx_ring->ndev);
|
|
|
|
buf_pool = rx_ring->buf_pool;
|
|
|
|
|
|
|
|
dma_unmap_single(dev, GET_VAL(DATAADDR, le64_to_cpu(raw_desc->m1)),
|
|
|
|
XGENE_ENET_MAX_MTU, DMA_FROM_DEVICE);
|
|
|
|
skb_index = GET_VAL(USERINFO, le64_to_cpu(raw_desc->m0));
|
|
|
|
skb = buf_pool->rx_skb[skb_index];
|
|
|
|
|
|
|
|
/* checking for error */
|
2016-05-13 23:53:00 +00:00
|
|
|
status = (GET_VAL(ELERR, le64_to_cpu(raw_desc->m0)) << LERR_LEN) ||
|
|
|
|
GET_VAL(LERR, le64_to_cpu(raw_desc->m0));
|
2014-08-07 22:14:28 +00:00
|
|
|
if (unlikely(status > 2)) {
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
xgene_enet_parse_error(rx_ring, netdev_priv(rx_ring->ndev),
|
|
|
|
status);
|
|
|
|
ret = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* strip off CRC as HW isn't doing this */
|
|
|
|
datalen = GET_VAL(BUFDATALEN, le64_to_cpu(raw_desc->m1));
|
2015-08-26 18:48:06 +00:00
|
|
|
datalen = (datalen & DATALEN_MASK) - 4;
|
2014-08-07 22:14:28 +00:00
|
|
|
prefetch(skb->data - NET_IP_ALIGN);
|
|
|
|
skb_put(skb, datalen);
|
|
|
|
|
|
|
|
skb_checksum_none_assert(skb);
|
|
|
|
skb->protocol = eth_type_trans(skb, ndev);
|
|
|
|
if (likely((ndev->features & NETIF_F_IP_CSUM) &&
|
|
|
|
skb->protocol == htons(ETH_P_IP))) {
|
|
|
|
xgene_enet_skip_csum(skb);
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:53:00 +00:00
|
|
|
rx_ring->rx_packets++;
|
|
|
|
rx_ring->rx_bytes += datalen;
|
2014-08-07 22:14:28 +00:00
|
|
|
napi_gro_receive(&rx_ring->napi, skb);
|
|
|
|
out:
|
|
|
|
if (--rx_ring->nbufpool == 0) {
|
|
|
|
ret = xgene_enet_refill_bufpool(buf_pool, NUM_BUFPOOL);
|
|
|
|
rx_ring->nbufpool = NUM_BUFPOOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_rx_desc(struct xgene_enet_raw_desc *raw_desc)
|
|
|
|
{
|
|
|
|
return GET_VAL(FPQNUM, le64_to_cpu(raw_desc->m0)) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_process_ring(struct xgene_enet_desc_ring *ring,
|
|
|
|
int budget)
|
|
|
|
{
|
2016-02-17 23:00:41 +00:00
|
|
|
struct net_device *ndev = ring->ndev;
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
2015-08-26 18:48:06 +00:00
|
|
|
struct xgene_enet_raw_desc *raw_desc, *exp_desc;
|
2014-08-07 22:14:28 +00:00
|
|
|
u16 head = ring->head;
|
|
|
|
u16 slots = ring->slots - 1;
|
2015-12-17 06:26:05 +00:00
|
|
|
int ret, desc_count, count = 0, processed = 0;
|
|
|
|
bool is_completion;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
raw_desc = &ring->raw_desc[head];
|
2015-12-17 06:26:05 +00:00
|
|
|
desc_count = 0;
|
|
|
|
is_completion = false;
|
2015-08-26 18:48:06 +00:00
|
|
|
exp_desc = NULL;
|
2014-08-07 22:14:28 +00:00
|
|
|
if (unlikely(xgene_enet_is_desc_slot_empty(raw_desc)))
|
|
|
|
break;
|
|
|
|
|
2015-01-29 22:38:23 +00:00
|
|
|
/* read fpqnum field after dataaddr field */
|
|
|
|
dma_rmb();
|
2015-08-26 18:48:06 +00:00
|
|
|
if (GET_BIT(NV, le64_to_cpu(raw_desc->m0))) {
|
|
|
|
head = (head + 1) & slots;
|
|
|
|
exp_desc = &ring->raw_desc[head];
|
|
|
|
|
|
|
|
if (unlikely(xgene_enet_is_desc_slot_empty(exp_desc))) {
|
|
|
|
head = (head - 1) & slots;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dma_rmb();
|
|
|
|
count++;
|
2015-12-17 06:26:05 +00:00
|
|
|
desc_count++;
|
2015-08-26 18:48:06 +00:00
|
|
|
}
|
2015-12-17 06:26:05 +00:00
|
|
|
if (is_rx_desc(raw_desc)) {
|
2014-08-07 22:14:28 +00:00
|
|
|
ret = xgene_enet_rx_frame(ring, raw_desc);
|
2015-12-17 06:26:05 +00:00
|
|
|
} else {
|
2014-08-07 22:14:28 +00:00
|
|
|
ret = xgene_enet_tx_completion(ring, raw_desc);
|
2015-12-17 06:26:05 +00:00
|
|
|
is_completion = true;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
xgene_enet_mark_desc_slot_empty(raw_desc);
|
2015-08-26 18:48:06 +00:00
|
|
|
if (exp_desc)
|
|
|
|
xgene_enet_mark_desc_slot_empty(exp_desc);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
head = (head + 1) & slots;
|
|
|
|
count++;
|
2015-12-17 06:26:05 +00:00
|
|
|
desc_count++;
|
2015-08-26 18:48:06 +00:00
|
|
|
processed++;
|
2015-12-17 06:26:05 +00:00
|
|
|
if (is_completion)
|
2016-02-17 23:00:41 +00:00
|
|
|
pdata->txc_level[ring->index] += desc_count;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
} while (--budget);
|
|
|
|
|
|
|
|
if (likely(count)) {
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata->ring_ops->wr_cmd(ring, -count);
|
2014-08-07 22:14:28 +00:00
|
|
|
ring->head = head;
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
if (__netif_subqueue_stopped(ndev, ring->index))
|
|
|
|
netif_start_subqueue(ndev, ring->index);
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
return processed;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_napi(struct napi_struct *napi, const int budget)
|
|
|
|
{
|
|
|
|
struct xgene_enet_desc_ring *ring;
|
|
|
|
int processed;
|
|
|
|
|
|
|
|
ring = container_of(napi, struct xgene_enet_desc_ring, napi);
|
|
|
|
processed = xgene_enet_process_ring(ring, budget);
|
|
|
|
|
|
|
|
if (processed != budget) {
|
|
|
|
napi_complete(napi);
|
|
|
|
enable_irq(ring->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
return processed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_timeout(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
2016-02-17 23:00:41 +00:00
|
|
|
struct netdev_queue *txq;
|
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
pdata->mac_ops->reset(pdata);
|
2016-02-17 23:00:41 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pdata->txq_cnt; i++) {
|
|
|
|
txq = netdev_get_tx_queue(ndev, i);
|
|
|
|
txq->trans_start = jiffies;
|
|
|
|
netif_tx_start_queue(txq);
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_register_irq(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
|
|
|
struct device *dev = ndev_to_dev(ndev);
|
2015-03-25 19:19:12 +00:00
|
|
|
struct xgene_enet_desc_ring *ring;
|
2016-02-17 23:00:41 +00:00
|
|
|
int ret = 0, i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
ring = pdata->rx_ring[i];
|
|
|
|
irq_set_status_flags(ring->irq, IRQ_DISABLE_UNLAZY);
|
|
|
|
ret = devm_request_irq(dev, ring->irq, xgene_enet_rx_irq,
|
2016-05-13 23:52:58 +00:00
|
|
|
0, ring->irq_name, ring);
|
2016-02-17 23:00:41 +00:00
|
|
|
if (ret) {
|
|
|
|
netdev_err(ndev, "Failed to request irq %s\n",
|
|
|
|
ring->irq_name);
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
ring = pdata->tx_ring[i]->cp_ring;
|
2016-01-22 00:07:41 +00:00
|
|
|
irq_set_status_flags(ring->irq, IRQ_DISABLE_UNLAZY);
|
2015-03-25 19:19:12 +00:00
|
|
|
ret = devm_request_irq(dev, ring->irq, xgene_enet_rx_irq,
|
2016-05-13 23:52:58 +00:00
|
|
|
0, ring->irq_name, ring);
|
2015-03-25 19:19:12 +00:00
|
|
|
if (ret) {
|
|
|
|
netdev_err(ndev, "Failed to request irq %s\n",
|
|
|
|
ring->irq_name);
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_free_irq(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata;
|
2016-01-22 00:07:41 +00:00
|
|
|
struct xgene_enet_desc_ring *ring;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct device *dev;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
pdata = netdev_priv(ndev);
|
|
|
|
dev = ndev_to_dev(ndev);
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
ring = pdata->rx_ring[i];
|
|
|
|
irq_clear_status_flags(ring->irq, IRQ_DISABLE_UNLAZY);
|
|
|
|
devm_free_irq(dev, ring->irq, ring);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
ring = pdata->tx_ring[i]->cp_ring;
|
2016-01-22 00:07:41 +00:00
|
|
|
irq_clear_status_flags(ring->irq, IRQ_DISABLE_UNLAZY);
|
|
|
|
devm_free_irq(dev, ring->irq, ring);
|
2015-03-25 19:19:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_napi_enable(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct napi_struct *napi;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
napi = &pdata->rx_ring[i]->napi;
|
|
|
|
napi_enable(napi);
|
|
|
|
}
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
napi = &pdata->tx_ring[i]->cp_ring->napi;
|
2015-03-25 19:19:12 +00:00
|
|
|
napi_enable(napi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_napi_disable(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct napi_struct *napi;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
napi = &pdata->rx_ring[i]->napi;
|
|
|
|
napi_disable(napi);
|
|
|
|
}
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
napi = &pdata->tx_ring[i]->cp_ring->napi;
|
2015-03-25 19:19:12 +00:00
|
|
|
napi_disable(napi);
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_open(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
2015-12-08 20:18:25 +00:00
|
|
|
const struct xgene_mac_ops *mac_ops = pdata->mac_ops;
|
2014-08-07 22:14:28 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
ret = netif_set_real_num_tx_queues(ndev, pdata->txq_cnt);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = netif_set_real_num_rx_queues(ndev, pdata->rxq_cnt);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
mac_ops->tx_enable(pdata);
|
|
|
|
mac_ops->rx_enable(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-11-23 20:04:52 +00:00
|
|
|
xgene_enet_napi_enable(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
ret = xgene_enet_register_irq(ndev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-10-10 01:32:06 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII)
|
2014-08-07 22:14:28 +00:00
|
|
|
phy_start(pdata->phy_dev);
|
2014-10-10 01:32:06 +00:00
|
|
|
else
|
|
|
|
schedule_delayed_work(&pdata->link_work, PHY_POLL_LINK_OFF);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
netif_start_queue(ndev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_close(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
2015-12-08 20:18:25 +00:00
|
|
|
const struct xgene_mac_ops *mac_ops = pdata->mac_ops;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
netif_stop_queue(ndev);
|
|
|
|
|
2014-10-10 01:32:06 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII)
|
2014-08-07 22:14:28 +00:00
|
|
|
phy_stop(pdata->phy_dev);
|
2014-10-10 01:32:06 +00:00
|
|
|
else
|
|
|
|
cancel_delayed_work_sync(&pdata->link_work);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
mac_ops->tx_disable(pdata);
|
|
|
|
mac_ops->rx_disable(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-11-23 20:04:52 +00:00
|
|
|
xgene_enet_free_irq(ndev);
|
|
|
|
xgene_enet_napi_disable(pdata);
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++)
|
|
|
|
xgene_enet_process_ring(pdata->rx_ring[i], -1);
|
2015-11-23 20:04:52 +00:00
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_delete_ring(struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata;
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
pdata = netdev_priv(ring->ndev);
|
|
|
|
dev = ndev_to_dev(ring->ndev);
|
|
|
|
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata->ring_ops->clear(ring);
|
2014-08-07 22:14:28 +00:00
|
|
|
dma_free_coherent(dev, ring->size, ring->desc_addr, ring->dma);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_delete_desc_rings(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct xgene_enet_desc_ring *buf_pool;
|
2016-02-17 23:00:41 +00:00
|
|
|
struct xgene_enet_desc_ring *ring;
|
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->txq_cnt; i++) {
|
|
|
|
ring = pdata->tx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
xgene_enet_delete_ring(ring);
|
|
|
|
pdata->tx_ring[i] = NULL;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
ring = pdata->rx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
buf_pool = ring->buf_pool;
|
|
|
|
xgene_enet_delete_bufpool(buf_pool);
|
|
|
|
xgene_enet_delete_ring(buf_pool);
|
|
|
|
xgene_enet_delete_ring(ring);
|
|
|
|
pdata->rx_ring[i] = NULL;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_get_ring_size(struct device *dev,
|
|
|
|
enum xgene_enet_ring_cfgsize cfgsize)
|
|
|
|
{
|
|
|
|
int size = -EINVAL;
|
|
|
|
|
|
|
|
switch (cfgsize) {
|
|
|
|
case RING_CFGSIZE_512B:
|
|
|
|
size = 0x200;
|
|
|
|
break;
|
|
|
|
case RING_CFGSIZE_2KB:
|
|
|
|
size = 0x800;
|
|
|
|
break;
|
|
|
|
case RING_CFGSIZE_16KB:
|
|
|
|
size = 0x4000;
|
|
|
|
break;
|
|
|
|
case RING_CFGSIZE_64KB:
|
|
|
|
size = 0x10000;
|
|
|
|
break;
|
|
|
|
case RING_CFGSIZE_512KB:
|
|
|
|
size = 0x80000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(dev, "Unsupported cfg ring size %d\n", cfgsize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_free_desc_ring(struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
2015-04-28 20:52:37 +00:00
|
|
|
struct xgene_enet_pdata *pdata;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
if (!ring)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev = ndev_to_dev(ring->ndev);
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata = netdev_priv(ring->ndev);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
if (ring->desc_addr) {
|
2015-04-28 20:52:37 +00:00
|
|
|
pdata->ring_ops->clear(ring);
|
2014-08-07 22:14:28 +00:00
|
|
|
dma_free_coherent(dev, ring->size, ring->desc_addr, ring->dma);
|
|
|
|
}
|
|
|
|
devm_kfree(dev, ring);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_free_desc_rings(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdata->pdev->dev;
|
|
|
|
struct xgene_enet_desc_ring *ring;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->txq_cnt; i++) {
|
|
|
|
ring = pdata->tx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
if (ring->cp_ring && ring->cp_ring->cp_skb)
|
|
|
|
devm_kfree(dev, ring->cp_ring->cp_skb);
|
|
|
|
if (ring->cp_ring && pdata->cq_cnt)
|
|
|
|
xgene_enet_free_desc_ring(ring->cp_ring);
|
|
|
|
xgene_enet_free_desc_ring(ring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
ring = pdata->rx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
if (ring->buf_pool) {
|
|
|
|
if (ring->buf_pool->rx_skb)
|
|
|
|
devm_kfree(dev, ring->buf_pool->rx_skb);
|
|
|
|
xgene_enet_free_desc_ring(ring->buf_pool);
|
|
|
|
}
|
|
|
|
xgene_enet_free_desc_ring(ring);
|
2014-08-21 20:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
static bool is_irq_mbox_required(struct xgene_enet_pdata *pdata,
|
|
|
|
struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
|
|
|
if ((pdata->enet_id == XGENE_ENET2) &&
|
|
|
|
(xgene_enet_ring_owner(ring->id) == RING_OWNER_CPU)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __iomem *xgene_enet_ring_cmd_base(struct xgene_enet_pdata *pdata,
|
|
|
|
struct xgene_enet_desc_ring *ring)
|
|
|
|
{
|
|
|
|
u8 num_ring_id_shift = pdata->ring_ops->num_ring_id_shift;
|
|
|
|
|
|
|
|
return pdata->ring_cmd_addr + (ring->num << num_ring_id_shift);
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static struct xgene_enet_desc_ring *xgene_enet_create_desc_ring(
|
|
|
|
struct net_device *ndev, u32 ring_num,
|
|
|
|
enum xgene_enet_ring_cfgsize cfgsize, u32 ring_id)
|
|
|
|
{
|
|
|
|
struct xgene_enet_desc_ring *ring;
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
|
|
|
struct device *dev = ndev_to_dev(ndev);
|
2014-08-14 11:59:42 +00:00
|
|
|
int size;
|
|
|
|
|
|
|
|
size = xgene_enet_get_ring_size(dev, cfgsize);
|
|
|
|
if (size < 0)
|
|
|
|
return NULL;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
ring = devm_kzalloc(dev, sizeof(struct xgene_enet_desc_ring),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ring)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ring->ndev = ndev;
|
|
|
|
ring->num = ring_num;
|
|
|
|
ring->cfgsize = cfgsize;
|
|
|
|
ring->id = ring_id;
|
|
|
|
|
|
|
|
ring->desc_addr = dma_zalloc_coherent(dev, size, &ring->dma,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ring->desc_addr) {
|
|
|
|
devm_kfree(dev, ring);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ring->size = size;
|
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
if (is_irq_mbox_required(pdata, ring)) {
|
|
|
|
ring->irq_mbox_addr = dma_zalloc_coherent(dev, INTR_MBOX_SIZE,
|
|
|
|
&ring->irq_mbox_dma, GFP_KERNEL);
|
|
|
|
if (!ring->irq_mbox_addr) {
|
|
|
|
dma_free_coherent(dev, size, ring->desc_addr,
|
|
|
|
ring->dma);
|
|
|
|
devm_kfree(dev, ring);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ring->cmd_base = xgene_enet_ring_cmd_base(pdata, ring);
|
2014-08-07 22:14:28 +00:00
|
|
|
ring->cmd = ring->cmd_base + INC_DEC_CMD_ADDR;
|
2015-04-28 20:52:37 +00:00
|
|
|
ring = pdata->ring_ops->setup(ring);
|
2014-08-07 22:14:28 +00:00
|
|
|
netdev_dbg(ndev, "ring info: num=%d size=%d id=%d slots=%d\n",
|
|
|
|
ring->num, ring->size, ring->id, ring->slots);
|
|
|
|
|
|
|
|
return ring;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u16 xgene_enet_get_ring_id(enum xgene_ring_owner owner, u8 bufnum)
|
|
|
|
{
|
|
|
|
return (owner << 6) | (bufnum & GENMASK(5, 0));
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
static enum xgene_ring_owner xgene_derive_ring_owner(struct xgene_enet_pdata *p)
|
|
|
|
{
|
|
|
|
enum xgene_ring_owner owner;
|
|
|
|
|
|
|
|
if (p->enet_id == XGENE_ENET1) {
|
|
|
|
switch (p->phy_mode) {
|
|
|
|
case PHY_INTERFACE_MODE_SGMII:
|
|
|
|
owner = RING_OWNER_ETH0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
owner = (!p->port_id) ? RING_OWNER_ETH0 :
|
|
|
|
RING_OWNER_ETH1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
owner = (!p->port_id) ? RING_OWNER_ETH0 : RING_OWNER_ETH1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
2016-04-29 18:10:13 +00:00
|
|
|
static u8 xgene_start_cpu_bufnum(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdata->pdev->dev;
|
|
|
|
u32 cpu_bufnum;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = device_property_read_u32(dev, "channel", &cpu_bufnum);
|
|
|
|
|
|
|
|
return (!ret) ? cpu_bufnum : pdata->cpu_bufnum;
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static int xgene_enet_create_desc_rings(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
|
|
|
struct device *dev = ndev_to_dev(ndev);
|
|
|
|
struct xgene_enet_desc_ring *rx_ring, *tx_ring, *cp_ring;
|
|
|
|
struct xgene_enet_desc_ring *buf_pool = NULL;
|
2015-04-28 20:52:39 +00:00
|
|
|
enum xgene_ring_owner owner;
|
2015-08-26 18:48:06 +00:00
|
|
|
dma_addr_t dma_exp_bufs;
|
2016-04-29 18:10:13 +00:00
|
|
|
u8 cpu_bufnum;
|
2015-03-17 18:27:13 +00:00
|
|
|
u8 eth_bufnum = pdata->eth_bufnum;
|
|
|
|
u8 bp_bufnum = pdata->bp_bufnum;
|
|
|
|
u16 ring_num = pdata->ring_num;
|
|
|
|
u16 ring_id;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i, ret, size;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-04-29 18:10:13 +00:00
|
|
|
cpu_bufnum = xgene_start_cpu_bufnum(pdata);
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
/* allocate rx descriptor ring */
|
|
|
|
owner = xgene_derive_ring_owner(pdata);
|
|
|
|
ring_id = xgene_enet_get_ring_id(RING_OWNER_CPU, cpu_bufnum++);
|
|
|
|
rx_ring = xgene_enet_create_desc_ring(ndev, ring_num++,
|
|
|
|
RING_CFGSIZE_16KB,
|
|
|
|
ring_id);
|
|
|
|
if (!rx_ring) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
/* allocate buffer pool for receiving packets */
|
|
|
|
owner = xgene_derive_ring_owner(pdata);
|
|
|
|
ring_id = xgene_enet_get_ring_id(owner, bp_bufnum++);
|
|
|
|
buf_pool = xgene_enet_create_desc_ring(ndev, ring_num++,
|
|
|
|
RING_CFGSIZE_2KB,
|
|
|
|
ring_id);
|
|
|
|
if (!buf_pool) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2015-08-26 18:48:06 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
rx_ring->nbufpool = NUM_BUFPOOL;
|
|
|
|
rx_ring->buf_pool = buf_pool;
|
|
|
|
rx_ring->irq = pdata->irqs[i];
|
|
|
|
if (!pdata->cq_cnt) {
|
|
|
|
snprintf(rx_ring->irq_name, IRQ_ID_SIZE, "%s-rx-txc",
|
|
|
|
ndev->name);
|
|
|
|
} else {
|
|
|
|
snprintf(rx_ring->irq_name, IRQ_ID_SIZE, "%s-rx%d",
|
|
|
|
ndev->name, i);
|
|
|
|
}
|
|
|
|
buf_pool->rx_skb = devm_kcalloc(dev, buf_pool->slots,
|
|
|
|
sizeof(struct sk_buff *),
|
2015-08-26 18:48:06 +00:00
|
|
|
GFP_KERNEL);
|
2016-02-17 23:00:41 +00:00
|
|
|
if (!buf_pool->rx_skb) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2015-08-26 18:48:06 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
buf_pool->dst_ring_num = xgene_enet_dst_ring_num(buf_pool);
|
|
|
|
rx_ring->buf_pool = buf_pool;
|
|
|
|
pdata->rx_ring[i] = rx_ring;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->txq_cnt; i++) {
|
|
|
|
/* allocate tx descriptor ring */
|
|
|
|
owner = xgene_derive_ring_owner(pdata);
|
|
|
|
ring_id = xgene_enet_get_ring_id(owner, eth_bufnum++);
|
|
|
|
tx_ring = xgene_enet_create_desc_ring(ndev, ring_num++,
|
2015-03-25 19:19:12 +00:00
|
|
|
RING_CFGSIZE_16KB,
|
|
|
|
ring_id);
|
2016-02-17 23:00:41 +00:00
|
|
|
if (!tx_ring) {
|
2015-03-25 19:19:12 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
size = (tx_ring->slots / 2) * sizeof(__le64) * MAX_EXP_BUFFS;
|
|
|
|
tx_ring->exp_bufs = dma_zalloc_coherent(dev, size,
|
|
|
|
&dma_exp_bufs,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!tx_ring->exp_bufs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2015-08-26 18:48:06 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
pdata->tx_ring[i] = tx_ring;
|
|
|
|
|
|
|
|
if (!pdata->cq_cnt) {
|
|
|
|
cp_ring = pdata->rx_ring[i];
|
|
|
|
} else {
|
|
|
|
/* allocate tx completion descriptor ring */
|
|
|
|
ring_id = xgene_enet_get_ring_id(RING_OWNER_CPU,
|
|
|
|
cpu_bufnum++);
|
|
|
|
cp_ring = xgene_enet_create_desc_ring(ndev, ring_num++,
|
|
|
|
RING_CFGSIZE_16KB,
|
|
|
|
ring_id);
|
|
|
|
if (!cp_ring) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2015-08-26 18:48:06 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
cp_ring->irq = pdata->irqs[pdata->rxq_cnt + i];
|
|
|
|
cp_ring->index = i;
|
|
|
|
snprintf(cp_ring->irq_name, IRQ_ID_SIZE, "%s-txc%d",
|
|
|
|
ndev->name, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
cp_ring->cp_skb = devm_kcalloc(dev, tx_ring->slots,
|
|
|
|
sizeof(struct sk_buff *),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!cp_ring->cp_skb) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
size = sizeof(dma_addr_t) * MAX_SKB_FRAGS;
|
|
|
|
cp_ring->frag_dma_addr = devm_kcalloc(dev, tx_ring->slots,
|
|
|
|
size, GFP_KERNEL);
|
|
|
|
if (!cp_ring->frag_dma_addr) {
|
|
|
|
devm_kfree(dev, cp_ring->cp_skb);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_ring->cp_ring = cp_ring;
|
|
|
|
tx_ring->dst_ring_num = xgene_enet_dst_ring_num(cp_ring);
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->ring_ops->coalesce(pdata->tx_ring[0]);
|
|
|
|
pdata->tx_qcnt_hi = pdata->tx_ring[0]->slots - 128;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
xgene_enet_free_desc_rings(pdata);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rtnl_link_stats64 *xgene_enet_get_stats64(
|
|
|
|
struct net_device *ndev,
|
|
|
|
struct rtnl_link_stats64 *storage)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
|
|
|
struct rtnl_link_stats64 *stats = &pdata->stats;
|
2016-05-13 23:53:00 +00:00
|
|
|
struct xgene_enet_desc_ring *ring;
|
|
|
|
int i;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-05-13 23:53:00 +00:00
|
|
|
memset(stats, 0, sizeof(struct rtnl_link_stats64));
|
|
|
|
for (i = 0; i < pdata->txq_cnt; i++) {
|
|
|
|
ring = pdata->tx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
stats->tx_packets += ring->tx_packets;
|
|
|
|
stats->tx_bytes += ring->tx_bytes;
|
|
|
|
}
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2016-05-13 23:53:00 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
ring = pdata->rx_ring[i];
|
|
|
|
if (ring) {
|
|
|
|
stats->rx_packets += ring->rx_packets;
|
|
|
|
stats->rx_bytes += ring->rx_bytes;
|
|
|
|
stats->rx_errors += ring->rx_length_errors +
|
|
|
|
ring->rx_crc_errors +
|
|
|
|
ring->rx_frame_errors +
|
|
|
|
ring->rx_fifo_errors;
|
|
|
|
stats->rx_dropped += ring->rx_dropped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(storage, stats, sizeof(struct rtnl_link_stats64));
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_set_mac_address(struct net_device *ndev, void *addr)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = eth_mac_addr(ndev, addr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-10-10 01:32:05 +00:00
|
|
|
pdata->mac_ops->set_mac_addr(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops xgene_ndev_ops = {
|
|
|
|
.ndo_open = xgene_enet_open,
|
|
|
|
.ndo_stop = xgene_enet_close,
|
|
|
|
.ndo_start_xmit = xgene_enet_start_xmit,
|
|
|
|
.ndo_tx_timeout = xgene_enet_timeout,
|
|
|
|
.ndo_get_stats64 = xgene_enet_get_stats64,
|
|
|
|
.ndo_change_mtu = eth_change_mtu,
|
|
|
|
.ndo_set_mac_address = xgene_enet_set_mac_address,
|
|
|
|
};
|
|
|
|
|
2015-06-24 07:29:51 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
2015-11-23 13:32:15 +00:00
|
|
|
static void xgene_get_port_id_acpi(struct device *dev,
|
2015-06-23 09:17:14 +00:00
|
|
|
struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
u64 temp;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(ACPI_HANDLE(dev), "_SUN", NULL, &temp);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
pdata->port_id = 0;
|
|
|
|
} else {
|
|
|
|
pdata->port_id = temp;
|
|
|
|
}
|
|
|
|
|
2015-11-23 13:32:15 +00:00
|
|
|
return;
|
2015-06-23 09:17:14 +00:00
|
|
|
}
|
2015-06-24 07:29:51 +00:00
|
|
|
#endif
|
2015-06-23 09:17:14 +00:00
|
|
|
|
2015-11-23 13:32:15 +00:00
|
|
|
static void xgene_get_port_id_dt(struct device *dev, struct xgene_enet_pdata *pdata)
|
2015-03-17 18:27:13 +00:00
|
|
|
{
|
|
|
|
u32 id = 0;
|
|
|
|
|
2015-11-23 13:32:15 +00:00
|
|
|
of_property_read_u32(dev->of_node, "port-id", &id);
|
2015-03-17 18:27:13 +00:00
|
|
|
|
2015-11-23 13:32:15 +00:00
|
|
|
pdata->port_id = id & BIT(0);
|
|
|
|
|
|
|
|
return;
|
2015-03-17 18:27:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 22:25:15 +00:00
|
|
|
static int xgene_get_tx_delay(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdata->pdev->dev;
|
|
|
|
int delay, ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(dev->of_node, "tx-delay", &delay);
|
|
|
|
if (ret) {
|
|
|
|
pdata->tx_delay = 4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delay < 0 || delay > 7) {
|
|
|
|
dev_err(dev, "Invalid tx-delay specified\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->tx_delay = delay;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_get_rx_delay(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdata->pdev->dev;
|
|
|
|
int delay, ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(dev->of_node, "rx-delay", &delay);
|
|
|
|
if (ret) {
|
|
|
|
pdata->rx_delay = 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delay < 0 || delay > 7) {
|
|
|
|
dev_err(dev, "Invalid rx-delay specified\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->rx_delay = delay;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-06 22:41:33 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
static int xgene_enet_get_irqs(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = pdata->pdev;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
int i, ret, max_irqs;
|
|
|
|
|
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII)
|
|
|
|
max_irqs = 1;
|
|
|
|
else if (pdata->phy_mode == PHY_INTERFACE_MODE_SGMII)
|
|
|
|
max_irqs = 2;
|
|
|
|
else
|
|
|
|
max_irqs = XGENE_MAX_ENET_IRQ;
|
|
|
|
|
|
|
|
for (i = 0; i < max_irqs; i++) {
|
|
|
|
ret = platform_get_irq(pdev, i);
|
|
|
|
if (ret <= 0) {
|
2016-05-13 23:52:59 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
max_irqs = i;
|
|
|
|
pdata->rxq_cnt = max_irqs / 2;
|
|
|
|
pdata->txq_cnt = max_irqs / 2;
|
|
|
|
pdata->cq_cnt = max_irqs / 2;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-17 23:00:41 +00:00
|
|
|
dev_err(dev, "Unable to get ENET IRQ\n");
|
|
|
|
ret = ret ? : -ENXIO;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
pdata->irqs[i] = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static int xgene_enet_get_resources(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct device *dev;
|
|
|
|
struct resource *res;
|
|
|
|
void __iomem *base_addr;
|
2015-04-28 20:52:40 +00:00
|
|
|
u32 offset;
|
2015-06-25 13:13:29 +00:00
|
|
|
int ret = 0;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
pdev = pdata->pdev;
|
|
|
|
dev = &pdev->dev;
|
|
|
|
ndev = pdata->ndev;
|
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, RES_ENET_CSR);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(dev, "Resource enet_csr not defined\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
pdata->base_addr = devm_ioremap(dev, res->start, resource_size(res));
|
2015-01-08 10:52:12 +00:00
|
|
|
if (!pdata->base_addr) {
|
2014-08-07 22:14:28 +00:00
|
|
|
dev_err(dev, "Unable to retrieve ENET Port CSR region\n");
|
2015-01-08 10:52:12 +00:00
|
|
|
return -ENOMEM;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, RES_RING_CSR);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(dev, "Resource ring_csr not defined\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
pdata->ring_csr_addr = devm_ioremap(dev, res->start,
|
|
|
|
resource_size(res));
|
2015-01-08 10:52:12 +00:00
|
|
|
if (!pdata->ring_csr_addr) {
|
2014-08-07 22:14:28 +00:00
|
|
|
dev_err(dev, "Unable to retrieve ENET Ring CSR region\n");
|
2015-01-08 10:52:12 +00:00
|
|
|
return -ENOMEM;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, RES_RING_CMD);
|
|
|
|
if (!res) {
|
|
|
|
dev_err(dev, "Resource ring_cmd not defined\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
pdata->ring_cmd_addr = devm_ioremap(dev, res->start,
|
|
|
|
resource_size(res));
|
2015-01-08 10:52:12 +00:00
|
|
|
if (!pdata->ring_cmd_addr) {
|
2014-08-07 22:14:28 +00:00
|
|
|
dev_err(dev, "Unable to retrieve ENET Ring command region\n");
|
2015-01-08 10:52:12 +00:00
|
|
|
return -ENOMEM;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 09:17:14 +00:00
|
|
|
if (dev->of_node)
|
2015-11-23 13:32:15 +00:00
|
|
|
xgene_get_port_id_dt(dev, pdata);
|
2015-06-23 09:17:14 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
else
|
2015-11-23 13:32:15 +00:00
|
|
|
xgene_get_port_id_acpi(dev, pdata);
|
2015-06-23 09:17:14 +00:00
|
|
|
#endif
|
2015-03-17 18:27:13 +00:00
|
|
|
|
2015-08-19 18:56:42 +00:00
|
|
|
if (!device_get_mac_address(dev, ndev->dev_addr, ETH_ALEN))
|
2014-08-07 22:14:28 +00:00
|
|
|
eth_hw_addr_random(ndev);
|
2015-01-06 22:41:33 +00:00
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len);
|
|
|
|
|
2015-08-19 18:56:42 +00:00
|
|
|
pdata->phy_mode = device_get_phy_mode(dev);
|
2014-08-07 22:14:28 +00:00
|
|
|
if (pdata->phy_mode < 0) {
|
2014-10-10 01:32:06 +00:00
|
|
|
dev_err(dev, "Unable to get phy-connection-type\n");
|
|
|
|
return pdata->phy_mode;
|
|
|
|
}
|
|
|
|
if (pdata->phy_mode != PHY_INTERFACE_MODE_RGMII &&
|
2014-10-14 00:05:34 +00:00
|
|
|
pdata->phy_mode != PHY_INTERFACE_MODE_SGMII &&
|
2014-10-10 01:32:06 +00:00
|
|
|
pdata->phy_mode != PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
dev_err(dev, "Incorrect phy-connection-type specified\n");
|
|
|
|
return -ENODEV;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 22:25:15 +00:00
|
|
|
ret = xgene_get_tx_delay(pdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = xgene_get_rx_delay(pdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
ret = xgene_enet_get_irqs(pdata);
|
|
|
|
if (ret)
|
2015-03-25 19:19:12 +00:00
|
|
|
return ret;
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
pdata->clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(pdata->clk)) {
|
2015-01-06 22:41:33 +00:00
|
|
|
/* Firmware may have set up the clock already. */
|
2015-06-23 09:17:17 +00:00
|
|
|
dev_info(dev, "clocks have been setup already\n");
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
if (pdata->phy_mode != PHY_INTERFACE_MODE_XGMII)
|
|
|
|
base_addr = pdata->base_addr - (pdata->port_id * MAC_OFFSET);
|
|
|
|
else
|
|
|
|
base_addr = pdata->base_addr;
|
2014-08-07 22:14:28 +00:00
|
|
|
pdata->eth_csr_addr = base_addr + BLOCK_ETH_CSR_OFFSET;
|
2016-02-17 23:00:39 +00:00
|
|
|
pdata->cle.base = base_addr + BLOCK_ETH_CLE_CSR_OFFSET;
|
2014-08-07 22:14:28 +00:00
|
|
|
pdata->eth_ring_if_addr = base_addr + BLOCK_ETH_RING_IF_OFFSET;
|
|
|
|
pdata->eth_diag_csr_addr = base_addr + BLOCK_ETH_DIAG_CSR_OFFSET;
|
2014-10-14 00:05:34 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII ||
|
|
|
|
pdata->phy_mode == PHY_INTERFACE_MODE_SGMII) {
|
2015-03-17 18:27:13 +00:00
|
|
|
pdata->mcx_mac_addr = pdata->base_addr + BLOCK_ETH_MAC_OFFSET;
|
2015-04-28 20:52:40 +00:00
|
|
|
offset = (pdata->enet_id == XGENE_ENET1) ?
|
|
|
|
BLOCK_ETH_MAC_CSR_OFFSET :
|
|
|
|
X2_BLOCK_ETH_MAC_CSR_OFFSET;
|
|
|
|
pdata->mcx_mac_csr_addr = base_addr + offset;
|
2014-10-10 01:32:06 +00:00
|
|
|
} else {
|
|
|
|
pdata->mcx_mac_addr = base_addr + BLOCK_AXG_MAC_OFFSET;
|
|
|
|
pdata->mcx_mac_csr_addr = base_addr + BLOCK_AXG_MAC_CSR_OFFSET;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
pdata->rx_buff_cnt = NUM_PKT_BUF;
|
|
|
|
|
2014-10-10 01:32:06 +00:00
|
|
|
return 0;
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_init_hw(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
2016-02-17 23:00:39 +00:00
|
|
|
struct xgene_enet_cle *enet_cle = &pdata->cle;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct net_device *ndev = pdata->ndev;
|
|
|
|
struct xgene_enet_desc_ring *buf_pool;
|
|
|
|
u16 dst_ring_num;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i, ret;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2014-11-03 19:59:55 +00:00
|
|
|
ret = pdata->port_ops->reset(pdata);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
ret = xgene_enet_create_desc_rings(ndev);
|
|
|
|
if (ret) {
|
|
|
|
netdev_err(ndev, "Error in ring configuration\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup buffer pool */
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
buf_pool = pdata->rx_ring[i]->buf_pool;
|
|
|
|
xgene_enet_init_bufpool(buf_pool);
|
|
|
|
ret = xgene_enet_refill_bufpool(buf_pool, pdata->rx_buff_cnt);
|
|
|
|
if (ret) {
|
|
|
|
xgene_enet_delete_desc_rings(pdata);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
dst_ring_num = xgene_enet_dst_ring_num(pdata->rx_ring[0]);
|
|
|
|
buf_pool = pdata->rx_ring[0]->buf_pool;
|
2016-02-17 23:00:39 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
/* Initialize and Enable PreClassifier Tree */
|
|
|
|
enet_cle->max_nodes = 512;
|
|
|
|
enet_cle->max_dbptrs = 1024;
|
|
|
|
enet_cle->parsers = 3;
|
|
|
|
enet_cle->active_parser = PARSER_ALL;
|
|
|
|
enet_cle->ptree.start_node = 0;
|
|
|
|
enet_cle->ptree.start_dbptr = 0;
|
|
|
|
enet_cle->jump_bytes = 8;
|
|
|
|
ret = pdata->cle_ops->cle_init(pdata);
|
|
|
|
if (ret) {
|
|
|
|
netdev_err(ndev, "Preclass Tree init error\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pdata->port_ops->cle_bypass(pdata, dst_ring_num, buf_pool->id);
|
|
|
|
}
|
|
|
|
|
2014-10-10 01:32:06 +00:00
|
|
|
pdata->mac_ops->init(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
static void xgene_enet_setup_ops(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
2014-10-10 01:32:06 +00:00
|
|
|
switch (pdata->phy_mode) {
|
|
|
|
case PHY_INTERFACE_MODE_RGMII:
|
|
|
|
pdata->mac_ops = &xgene_gmac_ops;
|
|
|
|
pdata->port_ops = &xgene_gport_ops;
|
2014-10-14 00:05:33 +00:00
|
|
|
pdata->rm = RM3;
|
2016-02-17 23:00:41 +00:00
|
|
|
pdata->rxq_cnt = 1;
|
|
|
|
pdata->txq_cnt = 1;
|
|
|
|
pdata->cq_cnt = 0;
|
2014-10-10 01:32:06 +00:00
|
|
|
break;
|
2014-10-14 00:05:34 +00:00
|
|
|
case PHY_INTERFACE_MODE_SGMII:
|
|
|
|
pdata->mac_ops = &xgene_sgmac_ops;
|
|
|
|
pdata->port_ops = &xgene_sgport_ops;
|
|
|
|
pdata->rm = RM1;
|
2016-02-17 23:00:41 +00:00
|
|
|
pdata->rxq_cnt = 1;
|
|
|
|
pdata->txq_cnt = 1;
|
|
|
|
pdata->cq_cnt = 1;
|
2014-10-14 00:05:34 +00:00
|
|
|
break;
|
2014-10-10 01:32:06 +00:00
|
|
|
default:
|
|
|
|
pdata->mac_ops = &xgene_xgmac_ops;
|
|
|
|
pdata->port_ops = &xgene_xgport_ops;
|
2016-02-17 23:00:39 +00:00
|
|
|
pdata->cle_ops = &xgene_cle3in_ops;
|
2014-10-14 00:05:33 +00:00
|
|
|
pdata->rm = RM0;
|
2016-05-13 23:52:59 +00:00
|
|
|
if (!pdata->rxq_cnt) {
|
|
|
|
pdata->rxq_cnt = XGENE_NUM_RX_RING;
|
|
|
|
pdata->txq_cnt = XGENE_NUM_TX_RING;
|
|
|
|
pdata->cq_cnt = XGENE_NUM_TXC_RING;
|
|
|
|
}
|
2014-10-10 01:32:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-03-17 18:27:13 +00:00
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
if (pdata->enet_id == XGENE_ENET1) {
|
|
|
|
switch (pdata->port_id) {
|
|
|
|
case 0:
|
2016-05-13 23:52:59 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
pdata->cpu_bufnum = X2_START_CPU_BUFNUM_0;
|
|
|
|
pdata->eth_bufnum = X2_START_ETH_BUFNUM_0;
|
|
|
|
pdata->bp_bufnum = X2_START_BP_BUFNUM_0;
|
|
|
|
pdata->ring_num = START_RING_NUM_0;
|
|
|
|
} else {
|
|
|
|
pdata->cpu_bufnum = START_CPU_BUFNUM_0;
|
|
|
|
pdata->eth_bufnum = START_ETH_BUFNUM_0;
|
|
|
|
pdata->bp_bufnum = START_BP_BUFNUM_0;
|
|
|
|
pdata->ring_num = START_RING_NUM_0;
|
|
|
|
}
|
2015-04-28 20:52:39 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-09-08 22:50:26 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
pdata->cpu_bufnum = XG_START_CPU_BUFNUM_1;
|
|
|
|
pdata->eth_bufnum = XG_START_ETH_BUFNUM_1;
|
|
|
|
pdata->bp_bufnum = XG_START_BP_BUFNUM_1;
|
|
|
|
pdata->ring_num = XG_START_RING_NUM_1;
|
|
|
|
} else {
|
|
|
|
pdata->cpu_bufnum = START_CPU_BUFNUM_1;
|
|
|
|
pdata->eth_bufnum = START_ETH_BUFNUM_1;
|
|
|
|
pdata->bp_bufnum = START_BP_BUFNUM_1;
|
|
|
|
pdata->ring_num = START_RING_NUM_1;
|
|
|
|
}
|
2015-04-28 20:52:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pdata->ring_ops = &xgene_ring1_ops;
|
|
|
|
} else {
|
|
|
|
switch (pdata->port_id) {
|
|
|
|
case 0:
|
|
|
|
pdata->cpu_bufnum = X2_START_CPU_BUFNUM_0;
|
|
|
|
pdata->eth_bufnum = X2_START_ETH_BUFNUM_0;
|
|
|
|
pdata->bp_bufnum = X2_START_BP_BUFNUM_0;
|
|
|
|
pdata->ring_num = X2_START_RING_NUM_0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pdata->cpu_bufnum = X2_START_CPU_BUFNUM_1;
|
|
|
|
pdata->eth_bufnum = X2_START_ETH_BUFNUM_1;
|
|
|
|
pdata->bp_bufnum = X2_START_BP_BUFNUM_1;
|
|
|
|
pdata->ring_num = X2_START_RING_NUM_1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pdata->rm = RM0;
|
|
|
|
pdata->ring_ops = &xgene_ring2_ops;
|
2015-03-17 18:27:13 +00:00
|
|
|
}
|
2014-10-10 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 19:19:12 +00:00
|
|
|
static void xgene_enet_napi_add(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct napi_struct *napi;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
napi = &pdata->rx_ring[i]->napi;
|
|
|
|
netif_napi_add(pdata->ndev, napi, xgene_enet_napi,
|
|
|
|
NAPI_POLL_WEIGHT);
|
|
|
|
}
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
napi = &pdata->tx_ring[i]->cp_ring->napi;
|
2015-03-25 19:19:12 +00:00
|
|
|
netif_napi_add(pdata->ndev, napi, xgene_enet_napi,
|
|
|
|
NAPI_POLL_WEIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xgene_enet_napi_del(struct xgene_enet_pdata *pdata)
|
|
|
|
{
|
|
|
|
struct napi_struct *napi;
|
2016-02-17 23:00:41 +00:00
|
|
|
int i;
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->rxq_cnt; i++) {
|
|
|
|
napi = &pdata->rx_ring[i]->napi;
|
|
|
|
netif_napi_del(napi);
|
|
|
|
}
|
2015-03-25 19:19:12 +00:00
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
for (i = 0; i < pdata->cq_cnt; i++) {
|
|
|
|
napi = &pdata->tx_ring[i]->cp_ring->napi;
|
2015-03-25 19:19:12 +00:00
|
|
|
netif_napi_del(napi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
static int xgene_enet_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct net_device *ndev;
|
|
|
|
struct xgene_enet_pdata *pdata;
|
|
|
|
struct device *dev = &pdev->dev;
|
2015-12-08 20:18:25 +00:00
|
|
|
const struct xgene_mac_ops *mac_ops;
|
2015-04-28 20:52:39 +00:00
|
|
|
const struct of_device_id *of_id;
|
2014-08-07 22:14:28 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-02-17 23:00:41 +00:00
|
|
|
ndev = alloc_etherdev_mqs(sizeof(struct xgene_enet_pdata),
|
|
|
|
XGENE_NUM_RX_RING, XGENE_NUM_TX_RING);
|
2014-08-07 22:14:28 +00:00
|
|
|
if (!ndev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pdata = netdev_priv(ndev);
|
|
|
|
|
|
|
|
pdata->pdev = pdev;
|
|
|
|
pdata->ndev = ndev;
|
|
|
|
SET_NETDEV_DEV(ndev, dev);
|
|
|
|
platform_set_drvdata(pdev, pdata);
|
|
|
|
ndev->netdev_ops = &xgene_ndev_ops;
|
|
|
|
xgene_enet_set_ethtool_ops(ndev);
|
|
|
|
ndev->features |= NETIF_F_IP_CSUM |
|
|
|
|
NETIF_F_GSO |
|
2015-08-26 18:48:06 +00:00
|
|
|
NETIF_F_GRO |
|
|
|
|
NETIF_F_SG;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-04-28 20:52:39 +00:00
|
|
|
of_id = of_match_device(xgene_enet_of_match, &pdev->dev);
|
|
|
|
if (of_id) {
|
|
|
|
pdata->enet_id = (enum xgene_enet_id)of_id->data;
|
2015-06-23 09:17:14 +00:00
|
|
|
}
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
else {
|
|
|
|
const struct acpi_device_id *acpi_id;
|
|
|
|
|
|
|
|
acpi_id = acpi_match_device(xgene_enet_acpi_match, &pdev->dev);
|
|
|
|
if (acpi_id)
|
|
|
|
pdata->enet_id = (enum xgene_enet_id) acpi_id->driver_data;
|
2015-04-28 20:52:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-06-23 09:17:14 +00:00
|
|
|
if (!pdata->enet_id) {
|
|
|
|
free_netdev(ndev);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2015-04-28 20:52:39 +00:00
|
|
|
|
2014-08-07 22:14:28 +00:00
|
|
|
ret = xgene_enet_get_resources(pdata);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
xgene_enet_setup_ops(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-08-26 18:48:06 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) {
|
|
|
|
ndev->features |= NETIF_F_TSO;
|
|
|
|
pdata->mss = XGENE_ENET_MSS;
|
|
|
|
}
|
|
|
|
ndev->hw_features = ndev->features;
|
|
|
|
|
2015-11-23 20:04:52 +00:00
|
|
|
ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64));
|
2014-08-07 22:14:28 +00:00
|
|
|
if (ret) {
|
2015-11-23 20:04:52 +00:00
|
|
|
netdev_err(ndev, "No usable DMA configuration\n");
|
2014-08-07 22:14:28 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2015-11-23 20:04:52 +00:00
|
|
|
ret = register_netdev(ndev);
|
2014-08-07 22:14:28 +00:00
|
|
|
if (ret) {
|
2015-11-23 20:04:52 +00:00
|
|
|
netdev_err(ndev, "Failed to register netdev\n");
|
2014-08-07 22:14:28 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = xgene_enet_init_hw(pdata);
|
|
|
|
if (ret)
|
2016-05-03 14:05:07 +00:00
|
|
|
goto err_netdev;
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2014-10-14 00:05:33 +00:00
|
|
|
mac_ops = pdata->mac_ops;
|
2015-11-23 20:04:52 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII) {
|
2014-10-10 01:32:06 +00:00
|
|
|
ret = xgene_enet_mdio_config(pdata);
|
2015-11-23 20:04:52 +00:00
|
|
|
if (ret)
|
2016-05-03 14:05:07 +00:00
|
|
|
goto err_netdev;
|
2015-11-23 20:04:52 +00:00
|
|
|
} else {
|
2014-10-14 00:05:33 +00:00
|
|
|
INIT_DELAYED_WORK(&pdata->link_work, mac_ops->link_state);
|
2015-11-23 20:04:52 +00:00
|
|
|
}
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-11-23 20:04:52 +00:00
|
|
|
xgene_enet_napi_add(pdata);
|
|
|
|
return 0;
|
2016-05-03 14:05:07 +00:00
|
|
|
err_netdev:
|
2014-11-03 19:59:55 +00:00
|
|
|
unregister_netdev(ndev);
|
2016-05-03 14:05:07 +00:00
|
|
|
err:
|
2014-08-07 22:14:28 +00:00
|
|
|
free_netdev(ndev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xgene_enet_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct xgene_enet_pdata *pdata;
|
2015-12-08 20:18:25 +00:00
|
|
|
const struct xgene_mac_ops *mac_ops;
|
2014-08-07 22:14:28 +00:00
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
pdata = platform_get_drvdata(pdev);
|
2014-10-10 01:32:05 +00:00
|
|
|
mac_ops = pdata->mac_ops;
|
2014-08-07 22:14:28 +00:00
|
|
|
ndev = pdata->ndev;
|
|
|
|
|
2014-10-10 01:32:05 +00:00
|
|
|
mac_ops->rx_disable(pdata);
|
|
|
|
mac_ops->tx_disable(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
|
2015-03-25 19:19:12 +00:00
|
|
|
xgene_enet_napi_del(pdata);
|
2015-08-25 22:03:03 +00:00
|
|
|
if (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII)
|
|
|
|
xgene_enet_mdio_remove(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
unregister_netdev(ndev);
|
2015-08-25 22:03:03 +00:00
|
|
|
xgene_enet_delete_desc_rings(pdata);
|
2014-10-10 01:32:05 +00:00
|
|
|
pdata->port_ops->shutdown(pdata);
|
2014-08-07 22:14:28 +00:00
|
|
|
free_netdev(ndev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static const struct acpi_device_id xgene_enet_acpi_match[] = {
|
2015-06-23 09:17:14 +00:00
|
|
|
{ "APMC0D05", XGENE_ENET1},
|
|
|
|
{ "APMC0D30", XGENE_ENET1},
|
|
|
|
{ "APMC0D31", XGENE_ENET1},
|
2015-09-08 22:50:26 +00:00
|
|
|
{ "APMC0D3F", XGENE_ENET1},
|
2015-06-23 09:17:16 +00:00
|
|
|
{ "APMC0D26", XGENE_ENET2},
|
|
|
|
{ "APMC0D25", XGENE_ENET2},
|
2015-01-06 22:41:33 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, xgene_enet_acpi_match);
|
|
|
|
#endif
|
|
|
|
|
2015-02-11 10:25:40 +00:00
|
|
|
#ifdef CONFIG_OF
|
2015-03-17 18:37:36 +00:00
|
|
|
static const struct of_device_id xgene_enet_of_match[] = {
|
2015-04-28 20:52:39 +00:00
|
|
|
{.compatible = "apm,xgene-enet", .data = (void *)XGENE_ENET1},
|
|
|
|
{.compatible = "apm,xgene1-sgenet", .data = (void *)XGENE_ENET1},
|
|
|
|
{.compatible = "apm,xgene1-xgenet", .data = (void *)XGENE_ENET1},
|
2015-04-28 20:52:40 +00:00
|
|
|
{.compatible = "apm,xgene2-sgenet", .data = (void *)XGENE_ENET2},
|
2015-04-28 20:52:39 +00:00
|
|
|
{.compatible = "apm,xgene2-xgenet", .data = (void *)XGENE_ENET2},
|
2014-08-07 22:14:28 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2015-01-06 22:41:33 +00:00
|
|
|
MODULE_DEVICE_TABLE(of, xgene_enet_of_match);
|
2015-02-11 10:25:40 +00:00
|
|
|
#endif
|
2014-08-07 22:14:28 +00:00
|
|
|
|
|
|
|
static struct platform_driver xgene_enet_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "xgene-enet",
|
2015-01-06 22:41:33 +00:00
|
|
|
.of_match_table = of_match_ptr(xgene_enet_of_match),
|
|
|
|
.acpi_match_table = ACPI_PTR(xgene_enet_acpi_match),
|
2014-08-07 22:14:28 +00:00
|
|
|
},
|
|
|
|
.probe = xgene_enet_probe,
|
|
|
|
.remove = xgene_enet_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(xgene_enet_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("APM X-Gene SoC Ethernet driver");
|
|
|
|
MODULE_VERSION(XGENE_DRV_VERSION);
|
2014-10-10 01:32:05 +00:00
|
|
|
MODULE_AUTHOR("Iyappan Subramanian <isubramanian@apm.com>");
|
2014-08-07 22:14:28 +00:00
|
|
|
MODULE_AUTHOR("Keyur Chudgar <kchudgar@apm.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|