aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/netxen/netxen_nic_ctx.c
diff options
context:
space:
mode:
authorDhananjay Phadke <dhananjay@netxen.com>2009-04-28 11:29:10 -0400
committerDavid S. Miller <davem@davemloft.net>2009-04-29 01:44:31 -0400
commit4ea528a151549df795c984649d75860ea40390bd (patch)
treeea537e0b07f8f301d7a6ad9f785be3021ead9b29 /drivers/net/netxen/netxen_nic_ctx.c
parent5103c9f7874506cb40fc3c8d3f22486d3c4d91aa (diff)
netxen: refactor netxen_recv_context struct
o move related fields into netxen_recv_context struct. o allocate rx buffer and descriptor rings dynamically. Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netxen/netxen_nic_ctx.c')
-rw-r--r--drivers/net/netxen/netxen_nic_ctx.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/drivers/net/netxen/netxen_nic_ctx.c b/drivers/net/netxen/netxen_nic_ctx.c
index fd82adf4f876..4754f5cffad0 100644
--- a/drivers/net/netxen/netxen_nic_ctx.c
+++ b/drivers/net/netxen/netxen_nic_ctx.c
@@ -323,7 +323,8 @@ nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter)
323 int err = 0; 323 int err = 0;
324 u64 offset, phys_addr; 324 u64 offset, phys_addr;
325 dma_addr_t rq_phys_addr, rsp_phys_addr; 325 dma_addr_t rq_phys_addr, rsp_phys_addr;
326 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 326 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
327 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
327 328
328 rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t); 329 rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t);
329 rq_addr = pci_alloc_consistent(adapter->pdev, 330 rq_addr = pci_alloc_consistent(adapter->pdev,
@@ -358,7 +359,7 @@ nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter)
358 359
359 prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr); 360 prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr);
360 361
361 offset = adapter->ctx_desc_phys_addr+sizeof(struct netxen_ring_ctx); 362 offset = recv_ctx->phys_addr + sizeof(struct netxen_ring_ctx);
362 prq->cmd_cons_dma_addr = cpu_to_le64(offset); 363 prq->cmd_cons_dma_addr = cpu_to_le64(offset);
363 364
364 prq_cds = &prq->cds_ring; 365 prq_cds = &prq->cds_ring;
@@ -541,14 +542,16 @@ netxen_init_old_ctx(struct netxen_adapter *adapter)
541 struct nx_host_tx_ring *tx_ring; 542 struct nx_host_tx_ring *tx_ring;
542 int ring; 543 int ring;
543 int port = adapter->portnum; 544 int port = adapter->portnum;
544 struct netxen_ring_ctx *hwctx = adapter->ctx_desc; 545 struct netxen_ring_ctx *hwctx;
545 u32 signature; 546 u32 signature;
546 547
547 tx_ring = &adapter->tx_ring; 548 tx_ring = adapter->tx_ring;
549 recv_ctx = &adapter->recv_ctx;
550 hwctx = recv_ctx->hwctx;
551
548 hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr); 552 hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr);
549 hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc); 553 hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc);
550 554
551 recv_ctx = &adapter->recv_ctx;
552 555
553 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 556 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
554 rds_ring = &recv_ctx->rds_rings[ring]; 557 rds_ring = &recv_ctx->rds_rings[ring];
@@ -576,9 +579,9 @@ netxen_init_old_ctx(struct netxen_adapter *adapter)
576 NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE; 579 NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE;
577 580
578 NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port), 581 NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port),
579 lower32(adapter->ctx_desc_phys_addr)); 582 lower32(recv_ctx->phys_addr));
580 NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port), 583 NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port),
581 upper32(adapter->ctx_desc_phys_addr)); 584 upper32(recv_ctx->phys_addr));
582 NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port), 585 NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port),
583 signature | port); 586 signature | port);
584 return 0; 587 return 0;
@@ -592,25 +595,28 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter)
592 struct netxen_recv_context *recv_ctx; 595 struct netxen_recv_context *recv_ctx;
593 struct nx_host_rds_ring *rds_ring; 596 struct nx_host_rds_ring *rds_ring;
594 struct nx_host_sds_ring *sds_ring; 597 struct nx_host_sds_ring *sds_ring;
595 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 598 struct nx_host_tx_ring *tx_ring;
596 599
597 struct pci_dev *pdev = adapter->pdev; 600 struct pci_dev *pdev = adapter->pdev;
598 struct net_device *netdev = adapter->netdev; 601 struct net_device *netdev = adapter->netdev;
599 int port = adapter->portnum; 602 int port = adapter->portnum;
600 603
604 recv_ctx = &adapter->recv_ctx;
605 tx_ring = adapter->tx_ring;
606
601 addr = pci_alloc_consistent(pdev, 607 addr = pci_alloc_consistent(pdev,
602 sizeof(struct netxen_ring_ctx) + sizeof(uint32_t), 608 sizeof(struct netxen_ring_ctx) + sizeof(uint32_t),
603 &adapter->ctx_desc_phys_addr); 609 &recv_ctx->phys_addr);
604
605 if (addr == NULL) { 610 if (addr == NULL) {
606 dev_err(&pdev->dev, "failed to allocate hw context\n"); 611 dev_err(&pdev->dev, "failed to allocate hw context\n");
607 return -ENOMEM; 612 return -ENOMEM;
608 } 613 }
614
609 memset(addr, 0, sizeof(struct netxen_ring_ctx)); 615 memset(addr, 0, sizeof(struct netxen_ring_ctx));
610 adapter->ctx_desc = (struct netxen_ring_ctx *)addr; 616 recv_ctx->hwctx = (struct netxen_ring_ctx *)addr;
611 adapter->ctx_desc->ctx_id = cpu_to_le32(port); 617 recv_ctx->hwctx->ctx_id = cpu_to_le32(port);
612 adapter->ctx_desc->cmd_consumer_offset = 618 recv_ctx->hwctx->cmd_consumer_offset =
613 cpu_to_le64(adapter->ctx_desc_phys_addr + 619 cpu_to_le64(recv_ctx->phys_addr +
614 sizeof(struct netxen_ring_ctx)); 620 sizeof(struct netxen_ring_ctx));
615 tx_ring->hw_consumer = 621 tx_ring->hw_consumer =
616 (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx)); 622 (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx));
@@ -627,8 +633,6 @@ int netxen_alloc_hw_resources(struct netxen_adapter *adapter)
627 633
628 tx_ring->desc_head = (struct cmd_desc_type0 *)addr; 634 tx_ring->desc_head = (struct cmd_desc_type0 *)addr;
629 635
630 recv_ctx = &adapter->recv_ctx;
631
632 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 636 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
633 rds_ring = &recv_ctx->rds_rings[ring]; 637 rds_ring = &recv_ctx->rds_rings[ring];
634 addr = pci_alloc_consistent(adapter->pdev, 638 addr = pci_alloc_consistent(adapter->pdev,
@@ -713,16 +717,18 @@ void netxen_free_hw_resources(struct netxen_adapter *adapter)
713 netxen_api_unlock(adapter); 717 netxen_api_unlock(adapter);
714 } 718 }
715 719
716 if (adapter->ctx_desc != NULL) { 720 recv_ctx = &adapter->recv_ctx;
721
722 if (recv_ctx->hwctx != NULL) {
717 pci_free_consistent(adapter->pdev, 723 pci_free_consistent(adapter->pdev,
718 sizeof(struct netxen_ring_ctx) + 724 sizeof(struct netxen_ring_ctx) +
719 sizeof(uint32_t), 725 sizeof(uint32_t),
720 adapter->ctx_desc, 726 recv_ctx->hwctx,
721 adapter->ctx_desc_phys_addr); 727 recv_ctx->phys_addr);
722 adapter->ctx_desc = NULL; 728 recv_ctx->hwctx = NULL;
723 } 729 }
724 730
725 tx_ring = &adapter->tx_ring; 731 tx_ring = adapter->tx_ring;
726 if (tx_ring->desc_head != NULL) { 732 if (tx_ring->desc_head != NULL) {
727 pci_free_consistent(adapter->pdev, 733 pci_free_consistent(adapter->pdev,
728 TX_DESC_RINGSIZE(tx_ring), 734 TX_DESC_RINGSIZE(tx_ring),
@@ -730,7 +736,6 @@ void netxen_free_hw_resources(struct netxen_adapter *adapter)
730 tx_ring->desc_head = NULL; 736 tx_ring->desc_head = NULL;
731 } 737 }
732 738
733 recv_ctx = &adapter->recv_ctx;
734 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 739 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
735 rds_ring = &recv_ctx->rds_rings[ring]; 740 rds_ring = &recv_ctx->rds_rings[ring];
736 741