aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/netxen
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
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')
-rw-r--r--drivers/net/netxen/netxen_nic.h10
-rw-r--r--drivers/net/netxen/netxen_nic_ctx.c49
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c2
-rw-r--r--drivers/net/netxen/netxen_nic_init.c46
-rw-r--r--drivers/net/netxen/netxen_nic_main.c4
5 files changed, 71 insertions, 40 deletions
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index ebd6c2edc34..16f5e2267eb 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -775,8 +775,11 @@ struct netxen_recv_context {
775 u16 context_id; 775 u16 context_id;
776 u16 virt_port; 776 u16 virt_port;
777 777
778 struct nx_host_rds_ring rds_rings[NUM_RCV_DESC_RINGS]; 778 struct nx_host_rds_ring *rds_rings;
779 struct nx_host_sds_ring *sds_rings; 779 struct nx_host_sds_ring *sds_rings;
780
781 struct netxen_ring_ctx *hwctx;
782 dma_addr_t phys_addr;
780}; 783};
781 784
782/* New HW context creation */ 785/* New HW context creation */
@@ -1258,11 +1261,8 @@ struct netxen_adapter {
1258 struct netxen_adapter_stats stats; 1261 struct netxen_adapter_stats stats;
1259 1262
1260 struct netxen_recv_context recv_ctx; 1263 struct netxen_recv_context recv_ctx;
1261 struct nx_host_tx_ring tx_ring; 1264 struct nx_host_tx_ring *tx_ring;
1262 1265
1263 /* Context interface shared between card and host */
1264 struct netxen_ring_ctx *ctx_desc;
1265 dma_addr_t ctx_desc_phys_addr;
1266 int (*enable_phy_interrupts) (struct netxen_adapter *); 1266 int (*enable_phy_interrupts) (struct netxen_adapter *);
1267 int (*disable_phy_interrupts) (struct netxen_adapter *); 1267 int (*disable_phy_interrupts) (struct netxen_adapter *);
1268 int (*macaddr_set) (struct netxen_adapter *, netxen_ethernet_macaddr_t); 1268 int (*macaddr_set) (struct netxen_adapter *, netxen_ethernet_macaddr_t);
diff --git a/drivers/net/netxen/netxen_nic_ctx.c b/drivers/net/netxen/netxen_nic_ctx.c
index fd82adf4f87..4754f5cffad 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
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 3bb2b8c74d9..db53d9cfad0 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -521,7 +521,7 @@ netxen_send_cmd_descs(struct netxen_adapter *adapter,
521 521
522 i = 0; 522 i = 0;
523 523
524 tx_ring = &adapter->tx_ring; 524 tx_ring = adapter->tx_ring;
525 netif_tx_lock_bh(adapter->netdev); 525 netif_tx_lock_bh(adapter->netdev);
526 526
527 producer = tx_ring->producer; 527 producer = tx_ring->producer;
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index 8893a973399..363ef701e71 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -137,7 +137,7 @@ void netxen_release_tx_buffers(struct netxen_adapter *adapter)
137 struct netxen_cmd_buffer *cmd_buf; 137 struct netxen_cmd_buffer *cmd_buf;
138 struct netxen_skb_frag *buffrag; 138 struct netxen_skb_frag *buffrag;
139 int i, j; 139 int i, j;
140 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 140 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
141 141
142 cmd_buf = tx_ring->cmd_buf_arr; 142 cmd_buf = tx_ring->cmd_buf_arr;
143 for (i = 0; i < tx_ring->num_desc; i++) { 143 for (i = 0; i < tx_ring->num_desc; i++) {
@@ -172,6 +172,10 @@ void netxen_free_sw_resources(struct netxen_adapter *adapter)
172 int ring; 172 int ring;
173 173
174 recv_ctx = &adapter->recv_ctx; 174 recv_ctx = &adapter->recv_ctx;
175
176 if (recv_ctx->rds_rings == NULL)
177 goto skip_rds;
178
175 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 179 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
176 rds_ring = &recv_ctx->rds_rings[ring]; 180 rds_ring = &recv_ctx->rds_rings[ring];
177 if (rds_ring->rx_buf_arr) { 181 if (rds_ring->rx_buf_arr) {
@@ -179,11 +183,15 @@ void netxen_free_sw_resources(struct netxen_adapter *adapter)
179 rds_ring->rx_buf_arr = NULL; 183 rds_ring->rx_buf_arr = NULL;
180 } 184 }
181 } 185 }
186 kfree(recv_ctx->rds_rings);
187
188skip_rds:
189 if (adapter->tx_ring == NULL)
190 return;
182 191
183 tx_ring = &adapter->tx_ring; 192 tx_ring = adapter->tx_ring;
184 if (tx_ring->cmd_buf_arr) 193 if (tx_ring->cmd_buf_arr)
185 vfree(tx_ring->cmd_buf_arr); 194 vfree(tx_ring->cmd_buf_arr);
186 return;
187} 195}
188 196
189int netxen_alloc_sw_resources(struct netxen_adapter *adapter) 197int netxen_alloc_sw_resources(struct netxen_adapter *adapter)
@@ -191,17 +199,26 @@ int netxen_alloc_sw_resources(struct netxen_adapter *adapter)
191 struct netxen_recv_context *recv_ctx; 199 struct netxen_recv_context *recv_ctx;
192 struct nx_host_rds_ring *rds_ring; 200 struct nx_host_rds_ring *rds_ring;
193 struct nx_host_sds_ring *sds_ring; 201 struct nx_host_sds_ring *sds_ring;
194 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 202 struct nx_host_tx_ring *tx_ring;
195 struct netxen_rx_buffer *rx_buf; 203 struct netxen_rx_buffer *rx_buf;
196 int ring, i, num_rx_bufs; 204 int ring, i, size;
197 205
198 struct netxen_cmd_buffer *cmd_buf_arr; 206 struct netxen_cmd_buffer *cmd_buf_arr;
199 struct net_device *netdev = adapter->netdev; 207 struct net_device *netdev = adapter->netdev;
200 struct pci_dev *pdev = adapter->pdev; 208 struct pci_dev *pdev = adapter->pdev;
201 209
210 size = sizeof(struct nx_host_tx_ring);
211 tx_ring = kzalloc(size, GFP_KERNEL);
212 if (tx_ring == NULL) {
213 dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n",
214 netdev->name);
215 return -ENOMEM;
216 }
217 adapter->tx_ring = tx_ring;
218
202 tx_ring->num_desc = adapter->num_txd; 219 tx_ring->num_desc = adapter->num_txd;
203 cmd_buf_arr = 220
204 (struct netxen_cmd_buffer *)vmalloc(TX_BUFF_RINGSIZE(tx_ring)); 221 cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring));
205 if (cmd_buf_arr == NULL) { 222 if (cmd_buf_arr == NULL) {
206 dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", 223 dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n",
207 netdev->name); 224 netdev->name);
@@ -211,6 +228,16 @@ int netxen_alloc_sw_resources(struct netxen_adapter *adapter)
211 tx_ring->cmd_buf_arr = cmd_buf_arr; 228 tx_ring->cmd_buf_arr = cmd_buf_arr;
212 229
213 recv_ctx = &adapter->recv_ctx; 230 recv_ctx = &adapter->recv_ctx;
231
232 size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring);
233 rds_ring = kzalloc(size, GFP_KERNEL);
234 if (rds_ring == NULL) {
235 dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n",
236 netdev->name);
237 return -ENOMEM;
238 }
239 recv_ctx->rds_rings = rds_ring;
240
214 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 241 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
215 rds_ring = &recv_ctx->rds_rings[ring]; 242 rds_ring = &recv_ctx->rds_rings[ring];
216 switch (ring) { 243 switch (ring) {
@@ -262,9 +289,8 @@ int netxen_alloc_sw_resources(struct netxen_adapter *adapter)
262 * Now go through all of them, set reference handles 289 * Now go through all of them, set reference handles
263 * and put them in the queues. 290 * and put them in the queues.
264 */ 291 */
265 num_rx_bufs = rds_ring->num_desc;
266 rx_buf = rds_ring->rx_buf_arr; 292 rx_buf = rds_ring->rx_buf_arr;
267 for (i = 0; i < num_rx_bufs; i++) { 293 for (i = 0; i < rds_ring->num_desc; i++) {
268 list_add_tail(&rx_buf->list, 294 list_add_tail(&rx_buf->list,
269 &rds_ring->free_list); 295 &rds_ring->free_list);
270 rx_buf->ref_handle = i; 296 rx_buf->ref_handle = i;
@@ -1064,7 +1090,7 @@ int netxen_process_cmd_ring(struct netxen_adapter *adapter)
1064 struct net_device *netdev = adapter->netdev; 1090 struct net_device *netdev = adapter->netdev;
1065 struct netxen_skb_frag *frag; 1091 struct netxen_skb_frag *frag;
1066 int done = 0; 1092 int done = 0;
1067 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 1093 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
1068 1094
1069 if (!spin_trylock(&adapter->tx_clean_lock)) 1095 if (!spin_trylock(&adapter->tx_clean_lock))
1070 return 1; 1096 return 1;
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 8331580fe16..07959fe06f2 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -857,7 +857,7 @@ netxen_nic_attach(struct netxen_adapter *adapter)
857 } 857 }
858 858
859 if (adapter->fw_major < 4) { 859 if (adapter->fw_major < 4) {
860 tx_ring = &adapter->tx_ring; 860 tx_ring = adapter->tx_ring;
861 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum]; 861 tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum];
862 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum]; 862 tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum];
863 863
@@ -1315,7 +1315,7 @@ static int
1315netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 1315netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1316{ 1316{
1317 struct netxen_adapter *adapter = netdev_priv(netdev); 1317 struct netxen_adapter *adapter = netdev_priv(netdev);
1318 struct nx_host_tx_ring *tx_ring = &adapter->tx_ring; 1318 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
1319 unsigned int first_seg_len = skb->len - skb->data_len; 1319 unsigned int first_seg_len = skb->len - skb->data_len;
1320 struct netxen_cmd_buffer *pbuf; 1320 struct netxen_cmd_buffer *pbuf;
1321 struct netxen_skb_frag *buffrag; 1321 struct netxen_skb_frag *buffrag;