Commit 1b33341e authored by Jie Wang's avatar Jie Wang Committed by David S. Miller

net: hns3: refactor function hns3_get_vector_ring_chain()

Currently  hns3_get_vector_ring_chain() is a bit long. Refactor it by
extracting sub process to improve the readability.
Signed-off-by: default avatarJie Wang <wangjie125@huawei.com>
Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 358e3edb
...@@ -4342,87 +4342,70 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget) ...@@ -4342,87 +4342,70 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
return rx_pkt_total; return rx_pkt_total;
} }
static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, static int hns3_create_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
struct hnae3_ring_chain_node *head) struct hnae3_ring_chain_node **head,
bool is_tx)
{ {
u32 bit_value = is_tx ? HNAE3_RING_TYPE_TX : HNAE3_RING_TYPE_RX;
u32 field_value = is_tx ? HNAE3_RING_GL_TX : HNAE3_RING_GL_RX;
struct hnae3_ring_chain_node *cur_chain = *head;
struct pci_dev *pdev = tqp_vector->handle->pdev; struct pci_dev *pdev = tqp_vector->handle->pdev;
struct hnae3_ring_chain_node *cur_chain = head;
struct hnae3_ring_chain_node *chain; struct hnae3_ring_chain_node *chain;
struct hns3_enet_ring *tx_ring; struct hns3_enet_ring *ring;
struct hns3_enet_ring *rx_ring;
tx_ring = tqp_vector->tx_group.ring;
if (tx_ring) {
cur_chain->tqp_index = tx_ring->tqp->tqp_index;
hnae3_set_bit(cur_chain->flag, HNAE3_RING_TYPE_B,
HNAE3_RING_TYPE_TX);
hnae3_set_field(cur_chain->int_gl_idx, HNAE3_RING_GL_IDX_M,
HNAE3_RING_GL_IDX_S, HNAE3_RING_GL_TX);
cur_chain->next = NULL;
while (tx_ring->next) {
tx_ring = tx_ring->next;
chain = devm_kzalloc(&pdev->dev, sizeof(*chain),
GFP_KERNEL);
if (!chain)
goto err_free_chain;
cur_chain->next = chain;
chain->tqp_index = tx_ring->tqp->tqp_index;
hnae3_set_bit(chain->flag, HNAE3_RING_TYPE_B,
HNAE3_RING_TYPE_TX);
hnae3_set_field(chain->int_gl_idx,
HNAE3_RING_GL_IDX_M,
HNAE3_RING_GL_IDX_S,
HNAE3_RING_GL_TX);
cur_chain = chain;
}
}
rx_ring = tqp_vector->rx_group.ring; ring = is_tx ? tqp_vector->tx_group.ring : tqp_vector->rx_group.ring;
if (!tx_ring && rx_ring) {
cur_chain->next = NULL;
cur_chain->tqp_index = rx_ring->tqp->tqp_index;
hnae3_set_bit(cur_chain->flag, HNAE3_RING_TYPE_B,
HNAE3_RING_TYPE_RX);
hnae3_set_field(cur_chain->int_gl_idx, HNAE3_RING_GL_IDX_M,
HNAE3_RING_GL_IDX_S, HNAE3_RING_GL_RX);
rx_ring = rx_ring->next; if (cur_chain) {
while (cur_chain->next)
cur_chain = cur_chain->next;
} }
while (rx_ring) { while (ring) {
chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL); chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL);
if (!chain) if (!chain)
goto err_free_chain; return -ENOMEM;
if (cur_chain)
cur_chain->next = chain; cur_chain->next = chain;
chain->tqp_index = rx_ring->tqp->tqp_index; else
*head = chain;
chain->tqp_index = ring->tqp->tqp_index;
hnae3_set_bit(chain->flag, HNAE3_RING_TYPE_B, hnae3_set_bit(chain->flag, HNAE3_RING_TYPE_B,
HNAE3_RING_TYPE_RX); bit_value);
hnae3_set_field(chain->int_gl_idx, HNAE3_RING_GL_IDX_M, hnae3_set_field(chain->int_gl_idx,
HNAE3_RING_GL_IDX_S, HNAE3_RING_GL_RX); HNAE3_RING_GL_IDX_M,
HNAE3_RING_GL_IDX_S, field_value);
cur_chain = chain; cur_chain = chain;
rx_ring = rx_ring->next; ring = ring->next;
} }
return 0; return 0;
}
static struct hnae3_ring_chain_node *
hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector)
{
struct pci_dev *pdev = tqp_vector->handle->pdev;
struct hnae3_ring_chain_node *cur_chain = NULL;
struct hnae3_ring_chain_node *chain;
if (hns3_create_ring_chain(tqp_vector, &cur_chain, true))
goto err_free_chain;
if (hns3_create_ring_chain(tqp_vector, &cur_chain, false))
goto err_free_chain;
return cur_chain;
err_free_chain: err_free_chain:
cur_chain = head->next;
while (cur_chain) { while (cur_chain) {
chain = cur_chain->next; chain = cur_chain->next;
devm_kfree(&pdev->dev, cur_chain); devm_kfree(&pdev->dev, cur_chain);
cur_chain = chain; cur_chain = chain;
} }
head->next = NULL;
return -ENOMEM; return NULL;
} }
static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
...@@ -4431,7 +4414,7 @@ static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector, ...@@ -4431,7 +4414,7 @@ static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
struct pci_dev *pdev = tqp_vector->handle->pdev; struct pci_dev *pdev = tqp_vector->handle->pdev;
struct hnae3_ring_chain_node *chain_tmp, *chain; struct hnae3_ring_chain_node *chain_tmp, *chain;
chain = head->next; chain = head;
while (chain) { while (chain) {
chain_tmp = chain->next; chain_tmp = chain->next;
...@@ -4546,7 +4529,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv) ...@@ -4546,7 +4529,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv)
} }
for (i = 0; i < priv->vector_num; i++) { for (i = 0; i < priv->vector_num; i++) {
struct hnae3_ring_chain_node vector_ring_chain; struct hnae3_ring_chain_node *vector_ring_chain;
tqp_vector = &priv->tqp_vector[i]; tqp_vector = &priv->tqp_vector[i];
...@@ -4556,15 +4539,16 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv) ...@@ -4556,15 +4539,16 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv)
tqp_vector->tx_group.total_packets = 0; tqp_vector->tx_group.total_packets = 0;
tqp_vector->handle = h; tqp_vector->handle = h;
ret = hns3_get_vector_ring_chain(tqp_vector, vector_ring_chain = hns3_get_vector_ring_chain(tqp_vector);
&vector_ring_chain); if (!vector_ring_chain) {
if (ret) ret = -ENOMEM;
goto map_ring_fail; goto map_ring_fail;
}
ret = h->ae_algo->ops->map_ring_to_vector(h, ret = h->ae_algo->ops->map_ring_to_vector(h,
tqp_vector->vector_irq, &vector_ring_chain); tqp_vector->vector_irq, vector_ring_chain);
hns3_free_vector_ring_chain(tqp_vector, &vector_ring_chain); hns3_free_vector_ring_chain(tqp_vector, vector_ring_chain);
if (ret) if (ret)
goto map_ring_fail; goto map_ring_fail;
...@@ -4663,7 +4647,7 @@ static void hns3_clear_ring_group(struct hns3_enet_ring_group *group) ...@@ -4663,7 +4647,7 @@ static void hns3_clear_ring_group(struct hns3_enet_ring_group *group)
static void hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv) static void hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv)
{ {
struct hnae3_ring_chain_node vector_ring_chain; struct hnae3_ring_chain_node *vector_ring_chain;
struct hnae3_handle *h = priv->ae_handle; struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_tqp_vector *tqp_vector; struct hns3_enet_tqp_vector *tqp_vector;
int i; int i;
...@@ -4678,13 +4662,14 @@ static void hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv) ...@@ -4678,13 +4662,14 @@ static void hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv)
* chain between vector and ring, we should go on to deal with * chain between vector and ring, we should go on to deal with
* the remaining options. * the remaining options.
*/ */
if (hns3_get_vector_ring_chain(tqp_vector, &vector_ring_chain)) vector_ring_chain = hns3_get_vector_ring_chain(tqp_vector);
if (!vector_ring_chain)
dev_warn(priv->dev, "failed to get ring chain\n"); dev_warn(priv->dev, "failed to get ring chain\n");
h->ae_algo->ops->unmap_ring_from_vector(h, h->ae_algo->ops->unmap_ring_from_vector(h,
tqp_vector->vector_irq, &vector_ring_chain); tqp_vector->vector_irq, vector_ring_chain);
hns3_free_vector_ring_chain(tqp_vector, &vector_ring_chain); hns3_free_vector_ring_chain(tqp_vector, vector_ring_chain);
hns3_clear_ring_group(&tqp_vector->rx_group); hns3_clear_ring_group(&tqp_vector->rx_group);
hns3_clear_ring_group(&tqp_vector->tx_group); hns3_clear_ring_group(&tqp_vector->tx_group);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment