Skip to content

Commit

Permalink
Merge branch 'hns-misc-fixes'
Browse files Browse the repository at this point in the history
Salil Mehta says:

====================
net: hns: Misc. HNS Bug Fixes & Code Improvements

This patch set introduces various HNS bug fixes, optimizations and code
improvements.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Apr 3, 2017
2 parents d4f4b91 + b4957ab commit cdccf74
Show file tree
Hide file tree
Showing 17 changed files with 653 additions and 560 deletions.
7 changes: 6 additions & 1 deletion drivers/net/ethernet/hisilicon/hns/hnae.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ static int hnae_alloc_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb)

static void hnae_free_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb)
{
if (unlikely(!cb->priv))
return;

if (cb->type == DESC_TYPE_SKB)
dev_kfree_skb_any((struct sk_buff *)cb->priv);
else if (unlikely(is_rx_ring(ring)))
put_page((struct page *)cb->priv);
memset(cb, 0, sizeof(*cb));

cb->priv = NULL;
}

static int hnae_map_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb)
Expand Down Expand Up @@ -197,6 +201,7 @@ hnae_init_ring(struct hnae_queue *q, struct hnae_ring *ring, int flags)

ring->q = q;
ring->flags = flags;
spin_lock_init(&ring->lock);
assert(!ring->desc && !ring->desc_cb && !ring->desc_dma_addr);

/* not matter for tx or rx ring, the ntc and ntc start from 0 */
Expand Down
47 changes: 43 additions & 4 deletions drivers/net/ethernet/hisilicon/hns/hnae.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ do { \
#define AE_IS_VER1(ver) ((ver) == AE_VERSION_1)
#define AE_NAME_SIZE 16

#define BD_SIZE_2048_MAX_MTU 6000

/* some said the RX and TX RCB format should not be the same in the future. But
* it is the same now...
*/
Expand Down Expand Up @@ -101,7 +103,6 @@ enum hnae_led_state {
#define HNS_RX_FLAG_L4ID_TCP 0x1
#define HNS_RX_FLAG_L4ID_SCTP 0x3


#define HNS_TXD_ASID_S 0
#define HNS_TXD_ASID_M (0xff << HNS_TXD_ASID_S)
#define HNS_TXD_BUFNUM_S 8
Expand Down Expand Up @@ -273,6 +274,9 @@ struct hnae_ring {
/* statistic */
struct ring_stats stats;

/* ring lock for poll one */
spinlock_t lock;

dma_addr_t desc_dma_addr;
u32 buf_size; /* size for hnae_desc->addr, preset by AE */
u16 desc_num; /* total number of desc */
Expand Down Expand Up @@ -483,11 +487,11 @@ struct hnae_ae_ops {
u32 auto_neg, u32 rx_en, u32 tx_en);
void (*get_coalesce_usecs)(struct hnae_handle *handle,
u32 *tx_usecs, u32 *rx_usecs);
void (*get_rx_max_coalesced_frames)(struct hnae_handle *handle,
u32 *tx_frames, u32 *rx_frames);
void (*get_max_coalesced_frames)(struct hnae_handle *handle,
u32 *tx_frames, u32 *rx_frames);
int (*set_coalesce_usecs)(struct hnae_handle *handle, u32 timeout);
int (*set_coalesce_frames)(struct hnae_handle *handle,
u32 coalesce_frames);
u32 tx_frames, u32 rx_frames);
void (*get_coalesce_range)(struct hnae_handle *handle,
u32 *tx_frames_low, u32 *rx_frames_low,
u32 *tx_frames_high, u32 *rx_frames_high,
Expand Down Expand Up @@ -646,6 +650,41 @@ static inline void hnae_reuse_buffer(struct hnae_ring *ring, int i)
ring->desc[i].rx.ipoff_bnum_pid_flag = 0;
}

/* when reinit buffer size, we should reinit buffer description */
static inline void hnae_reinit_all_ring_desc(struct hnae_handle *h)
{
int i, j;
struct hnae_ring *ring;

for (i = 0; i < h->q_num; i++) {
ring = &h->qs[i]->rx_ring;
for (j = 0; j < ring->desc_num; j++)
ring->desc[j].addr = cpu_to_le64(ring->desc_cb[j].dma);
}

wmb(); /* commit all data before submit */
}

/* when reinit buffer size, we should reinit page offset */
static inline void hnae_reinit_all_ring_page_off(struct hnae_handle *h)
{
int i, j;
struct hnae_ring *ring;

for (i = 0; i < h->q_num; i++) {
ring = &h->qs[i]->rx_ring;
for (j = 0; j < ring->desc_num; j++) {
ring->desc_cb[j].page_offset = 0;
if (ring->desc[j].addr !=
cpu_to_le64(ring->desc_cb[j].dma))
ring->desc[j].addr =
cpu_to_le64(ring->desc_cb[j].dma);
}
}

wmb(); /* commit all data before submit */
}

#define hnae_set_field(origin, mask, shift, val) \
do { \
(origin) &= (~(mask)); \
Expand Down
127 changes: 94 additions & 33 deletions drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,32 @@ static int hns_ae_clr_multicast(struct hnae_handle *handle)
static int hns_ae_set_mtu(struct hnae_handle *handle, int new_mtu)
{
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
struct hnae_queue *q;
u32 rx_buf_size;
int i, ret;

/* when buf_size is 2048, max mtu is 6K for rx ring max bd num is 3. */
if (!AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver)) {
if (new_mtu <= BD_SIZE_2048_MAX_MTU)
rx_buf_size = 2048;
else
rx_buf_size = 4096;
} else {
rx_buf_size = mac_cb->dsaf_dev->buf_size;
}

ret = hns_mac_set_mtu(mac_cb, new_mtu, rx_buf_size);

return hns_mac_set_mtu(mac_cb, new_mtu);
if (!ret) {
/* reinit ring buf_size */
for (i = 0; i < handle->q_num; i++) {
q = handle->qs[i];
q->rx_ring.buf_size = rx_buf_size;
hns_rcb_set_rx_ring_bs(q, rx_buf_size);
}
}

return ret;
}

static void hns_ae_set_tso_stats(struct hnae_handle *handle, int enable)
Expand Down Expand Up @@ -463,15 +487,21 @@ static void hns_ae_get_coalesce_usecs(struct hnae_handle *handle,
ring_pair->port_id_in_comm);
}

static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle *handle,
u32 *tx_frames, u32 *rx_frames)
static void hns_ae_get_max_coalesced_frames(struct hnae_handle *handle,
u32 *tx_frames, u32 *rx_frames)
{
struct ring_pair_cb *ring_pair =
container_of(handle->qs[0], struct ring_pair_cb, q);
struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);

*tx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
ring_pair->port_id_in_comm);
*rx_frames = hns_rcb_get_coalesced_frames(ring_pair->rcb_common,
if (AE_IS_VER1(dsaf_dev->dsaf_ver) ||
handle->port_type == HNAE_PORT_DEBUG)
*tx_frames = hns_rcb_get_rx_coalesced_frames(
ring_pair->rcb_common, ring_pair->port_id_in_comm);
else
*tx_frames = hns_rcb_get_tx_coalesced_frames(
ring_pair->rcb_common, ring_pair->port_id_in_comm);
*rx_frames = hns_rcb_get_rx_coalesced_frames(ring_pair->rcb_common,
ring_pair->port_id_in_comm);
}

Expand All @@ -485,15 +515,34 @@ static int hns_ae_set_coalesce_usecs(struct hnae_handle *handle,
ring_pair->rcb_common, ring_pair->port_id_in_comm, timeout);
}

static int hns_ae_set_coalesce_frames(struct hnae_handle *handle,
u32 coalesce_frames)
static int hns_ae_set_coalesce_frames(struct hnae_handle *handle,
u32 tx_frames, u32 rx_frames)
{
int ret;
struct ring_pair_cb *ring_pair =
container_of(handle->qs[0], struct ring_pair_cb, q);
struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);

return hns_rcb_set_coalesced_frames(
ring_pair->rcb_common,
ring_pair->port_id_in_comm, coalesce_frames);
if (AE_IS_VER1(dsaf_dev->dsaf_ver) ||
handle->port_type == HNAE_PORT_DEBUG) {
if (tx_frames != rx_frames)
return -EINVAL;
return hns_rcb_set_rx_coalesced_frames(
ring_pair->rcb_common,
ring_pair->port_id_in_comm, rx_frames);
} else {
if (tx_frames != 1)
return -EINVAL;
ret = hns_rcb_set_tx_coalesced_frames(
ring_pair->rcb_common,
ring_pair->port_id_in_comm, tx_frames);
if (ret)
return ret;

return hns_rcb_set_rx_coalesced_frames(
ring_pair->rcb_common,
ring_pair->port_id_in_comm, rx_frames);
}
}

static void hns_ae_get_coalesce_range(struct hnae_handle *handle,
Expand All @@ -504,20 +553,27 @@ static void hns_ae_get_coalesce_range(struct hnae_handle *handle,
{
struct dsaf_device *dsaf_dev;

assert(handle);

dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);

*tx_frames_low = HNS_RCB_MIN_COALESCED_FRAMES;
*rx_frames_low = HNS_RCB_MIN_COALESCED_FRAMES;
*tx_frames_high =
(dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
*rx_frames_high =
(dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
*tx_usecs_low = 0;
*rx_usecs_low = 0;
*tx_usecs_high = HNS_RCB_MAX_COALESCED_USECS;
*rx_usecs_high = HNS_RCB_MAX_COALESCED_USECS;
*tx_frames_low = HNS_RCB_TX_FRAMES_LOW;
*rx_frames_low = HNS_RCB_RX_FRAMES_LOW;

if (AE_IS_VER1(dsaf_dev->dsaf_ver) ||
handle->port_type == HNAE_PORT_DEBUG)
*tx_frames_high =
(dsaf_dev->desc_num - 1 > HNS_RCB_TX_FRAMES_HIGH) ?
HNS_RCB_TX_FRAMES_HIGH : dsaf_dev->desc_num - 1;
else
*tx_frames_high = 1;

*rx_frames_high = (dsaf_dev->desc_num - 1 > HNS_RCB_RX_FRAMES_HIGH) ?
HNS_RCB_RX_FRAMES_HIGH : dsaf_dev->desc_num - 1;
*tx_usecs_low = HNS_RCB_TX_USECS_LOW;
*rx_usecs_low = HNS_RCB_RX_USECS_LOW;
*tx_usecs_high = HNS_RCB_TX_USECS_HIGH;
*rx_usecs_high = HNS_RCB_RX_USECS_HIGH;
}

void hns_ae_update_stats(struct hnae_handle *handle,
Expand Down Expand Up @@ -802,8 +858,9 @@ static int hns_ae_get_rss(struct hnae_handle *handle, u32 *indir, u8 *key,
memcpy(key, ppe_cb->rss_key, HNS_PPEV2_RSS_KEY_SIZE);

/* update the current hash->queue mappings from the shadow RSS table */
memcpy(indir, ppe_cb->rss_indir_table,
HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
if (indir)
memcpy(indir, ppe_cb->rss_indir_table,
HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));

return 0;
}
Expand All @@ -814,15 +871,19 @@ static int hns_ae_set_rss(struct hnae_handle *handle, const u32 *indir,
struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle);

/* set the RSS Hash Key if specififed by the user */
if (key)
hns_ppe_set_rss_key(ppe_cb, (u32 *)key);
if (key) {
memcpy(ppe_cb->rss_key, key, HNS_PPEV2_RSS_KEY_SIZE);
hns_ppe_set_rss_key(ppe_cb, ppe_cb->rss_key);
}

/* update the shadow RSS table with user specified qids */
memcpy(ppe_cb->rss_indir_table, indir,
HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));
if (indir) {
/* update the shadow RSS table with user specified qids */
memcpy(ppe_cb->rss_indir_table, indir,
HNS_PPEV2_RSS_IND_TBL_SIZE * sizeof(*indir));

/* now update the hardware */
hns_ppe_set_indir_table(ppe_cb, ppe_cb->rss_indir_table);
/* now update the hardware */
hns_ppe_set_indir_table(ppe_cb, ppe_cb->rss_indir_table);
}

return 0;
}
Expand All @@ -846,7 +907,7 @@ static struct hnae_ae_ops hns_dsaf_ops = {
.get_autoneg = hns_ae_get_autoneg,
.set_pauseparam = hns_ae_set_pauseparam,
.get_coalesce_usecs = hns_ae_get_coalesce_usecs,
.get_rx_max_coalesced_frames = hns_ae_get_rx_max_coalesced_frames,
.get_max_coalesced_frames = hns_ae_get_max_coalesced_frames,
.set_coalesce_usecs = hns_ae_set_coalesce_usecs,
.set_coalesce_frames = hns_ae_set_coalesce_frames,
.get_coalesce_range = hns_ae_get_coalesce_range,
Expand Down
Loading

0 comments on commit cdccf74

Please sign in to comment.