2 * Copyright (C) 2003 - 2009 NetXen, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
27 * Cupertino, CA 95014-0701
31 #include "netxen_nic_hw.h"
32 #include "netxen_nic.h"
33 #include "netxen_nic_phan_reg.h"
35 #define NXHAL_VERSION 1
38 netxen_api_lock(struct netxen_adapter
*adapter
)
40 u32 done
= 0, timeout
= 0;
43 /* Acquire PCIE HW semaphore5 */
44 done
= NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM5_LOCK
));
49 if (++timeout
>= NX_OS_CRB_RETRY_COUNT
) {
50 printk(KERN_ERR
"%s: lock timeout.\n", __func__
);
59 NETXEN_API_LOCK_ID
, NX_OS_API_LOCK_DRIVER
);
65 netxen_api_unlock(struct netxen_adapter
*adapter
)
67 /* Release PCIE HW semaphore5 */
68 NXRD32(adapter
, NETXEN_PCIE_REG(PCIE_SEM5_UNLOCK
));
73 netxen_poll_rsp(struct netxen_adapter
*adapter
)
75 u32 rsp
= NX_CDRP_RSP_OK
;
79 /* give atleast 1ms for firmware to respond */
82 if (++timeout
> NX_OS_CRB_RETRY_COUNT
)
83 return NX_CDRP_RSP_TIMEOUT
;
85 rsp
= NXRD32(adapter
, NX_CDRP_CRB_OFFSET
);
86 } while (!NX_CDRP_IS_RSP(rsp
));
92 netxen_issue_cmd(struct netxen_adapter
*adapter
,
93 u32 pci_fn
, u32 version
, u32 arg1
, u32 arg2
, u32 arg3
, u32 cmd
)
97 u32 rcode
= NX_RCODE_SUCCESS
;
99 signature
= NX_CDRP_SIGNATURE_MAKE(pci_fn
, version
);
101 /* Acquire semaphore before accessing CRB */
102 if (netxen_api_lock(adapter
))
103 return NX_RCODE_TIMEOUT
;
105 NXWR32(adapter
, NX_SIGN_CRB_OFFSET
, signature
);
107 NXWR32(adapter
, NX_ARG1_CRB_OFFSET
, arg1
);
109 NXWR32(adapter
, NX_ARG2_CRB_OFFSET
, arg2
);
111 NXWR32(adapter
, NX_ARG3_CRB_OFFSET
, arg3
);
113 NXWR32(adapter
, NX_CDRP_CRB_OFFSET
, NX_CDRP_FORM_CMD(cmd
));
115 rsp
= netxen_poll_rsp(adapter
);
117 if (rsp
== NX_CDRP_RSP_TIMEOUT
) {
118 printk(KERN_ERR
"%s: card response timeout.\n",
119 netxen_nic_driver_name
);
121 rcode
= NX_RCODE_TIMEOUT
;
122 } else if (rsp
== NX_CDRP_RSP_FAIL
) {
123 rcode
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
125 printk(KERN_ERR
"%s: failed card response code:0x%x\n",
126 netxen_nic_driver_name
, rcode
);
129 /* Release semaphore */
130 netxen_api_unlock(adapter
);
136 nx_fw_cmd_set_mtu(struct netxen_adapter
*adapter
, int mtu
)
138 u32 rcode
= NX_RCODE_SUCCESS
;
139 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
141 if (recv_ctx
->state
== NX_HOST_CTX_STATE_ACTIVE
)
142 rcode
= netxen_issue_cmd(adapter
,
143 adapter
->ahw
.pci_func
,
145 recv_ctx
->context_id
,
148 NX_CDRP_CMD_SET_MTU
);
150 if (rcode
!= NX_RCODE_SUCCESS
)
157 nx_fw_cmd_create_rx_ctx(struct netxen_adapter
*adapter
)
160 nx_hostrq_rx_ctx_t
*prq
;
161 nx_cardrsp_rx_ctx_t
*prsp
;
162 nx_hostrq_rds_ring_t
*prq_rds
;
163 nx_hostrq_sds_ring_t
*prq_sds
;
164 nx_cardrsp_rds_ring_t
*prsp_rds
;
165 nx_cardrsp_sds_ring_t
*prsp_sds
;
166 struct nx_host_rds_ring
*rds_ring
;
167 struct nx_host_sds_ring
*sds_ring
;
169 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
172 int i
, nrds_rings
, nsds_rings
;
173 size_t rq_size
, rsp_size
;
178 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
180 nrds_rings
= adapter
->max_rds_rings
;
181 nsds_rings
= adapter
->max_sds_rings
;
184 SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t
, nrds_rings
, nsds_rings
);
186 SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t
, nrds_rings
, nsds_rings
);
188 addr
= pci_alloc_consistent(adapter
->pdev
,
189 rq_size
, &hostrq_phys_addr
);
192 prq
= (nx_hostrq_rx_ctx_t
*)addr
;
194 addr
= pci_alloc_consistent(adapter
->pdev
,
195 rsp_size
, &cardrsp_phys_addr
);
200 prsp
= (nx_cardrsp_rx_ctx_t
*)addr
;
202 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
204 cap
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
);
205 cap
|= (NX_CAP0_JUMBO_CONTIGUOUS
| NX_CAP0_LRO_CONTIGUOUS
);
207 prq
->capabilities
[0] = cpu_to_le32(cap
);
208 prq
->host_int_crb_mode
=
209 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
210 prq
->host_rds_crb_mode
=
211 cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE
);
213 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
214 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
215 prq
->rds_ring_offset
= cpu_to_le32(0);
217 val
= le32_to_cpu(prq
->rds_ring_offset
) +
218 (sizeof(nx_hostrq_rds_ring_t
) * nrds_rings
);
219 prq
->sds_ring_offset
= cpu_to_le32(val
);
221 prq_rds
= (nx_hostrq_rds_ring_t
*)(prq
->data
+
222 le32_to_cpu(prq
->rds_ring_offset
));
224 for (i
= 0; i
< nrds_rings
; i
++) {
226 rds_ring
= &recv_ctx
->rds_rings
[i
];
228 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
229 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
230 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
231 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
234 prq_sds
= (nx_hostrq_sds_ring_t
*)(prq
->data
+
235 le32_to_cpu(prq
->sds_ring_offset
));
237 for (i
= 0; i
< nsds_rings
; i
++) {
239 sds_ring
= &recv_ctx
->sds_rings
[i
];
241 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
242 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
243 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
246 phys_addr
= hostrq_phys_addr
;
247 err
= netxen_issue_cmd(adapter
,
248 adapter
->ahw
.pci_func
,
250 (u32
)(phys_addr
>> 32),
251 (u32
)(phys_addr
& 0xffffffff),
253 NX_CDRP_CMD_CREATE_RX_CTX
);
256 "Failed to create rx ctx in firmware%d\n", err
);
261 prsp_rds
= ((nx_cardrsp_rds_ring_t
*)
262 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
264 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
265 rds_ring
= &recv_ctx
->rds_rings
[i
];
267 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
268 rds_ring
->crb_rcv_producer
= NETXEN_NIC_REG(reg
- 0x200);
271 prsp_sds
= ((nx_cardrsp_sds_ring_t
*)
272 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
274 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
275 sds_ring
= &recv_ctx
->sds_rings
[i
];
277 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
278 sds_ring
->crb_sts_consumer
= NETXEN_NIC_REG(reg
- 0x200);
280 reg
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
281 sds_ring
->crb_intr_mask
= NETXEN_NIC_REG(reg
- 0x200);
284 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
285 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
286 recv_ctx
->virt_port
= prsp
->virt_port
;
289 pci_free_consistent(adapter
->pdev
, rsp_size
, prsp
, cardrsp_phys_addr
);
291 pci_free_consistent(adapter
->pdev
, rq_size
, prq
, hostrq_phys_addr
);
296 nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter
*adapter
)
298 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
300 if (netxen_issue_cmd(adapter
,
301 adapter
->ahw
.pci_func
,
303 recv_ctx
->context_id
,
304 NX_DESTROY_CTX_RESET
,
306 NX_CDRP_CMD_DESTROY_RX_CTX
)) {
309 "%s: Failed to destroy rx ctx in firmware\n",
310 netxen_nic_driver_name
);
315 nx_fw_cmd_create_tx_ctx(struct netxen_adapter
*adapter
)
317 nx_hostrq_tx_ctx_t
*prq
;
318 nx_hostrq_cds_ring_t
*prq_cds
;
319 nx_cardrsp_tx_ctx_t
*prsp
;
320 void *rq_addr
, *rsp_addr
;
321 size_t rq_size
, rsp_size
;
324 u64 offset
, phys_addr
;
325 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
326 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
327 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
329 rq_size
= SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t
);
330 rq_addr
= pci_alloc_consistent(adapter
->pdev
,
331 rq_size
, &rq_phys_addr
);
335 rsp_size
= SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t
);
336 rsp_addr
= pci_alloc_consistent(adapter
->pdev
,
337 rsp_size
, &rsp_phys_addr
);
343 memset(rq_addr
, 0, rq_size
);
344 prq
= (nx_hostrq_tx_ctx_t
*)rq_addr
;
346 memset(rsp_addr
, 0, rsp_size
);
347 prsp
= (nx_cardrsp_tx_ctx_t
*)rsp_addr
;
349 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
351 temp
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
| NX_CAP0_LSO
);
352 prq
->capabilities
[0] = cpu_to_le32(temp
);
354 prq
->host_int_crb_mode
=
355 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
357 prq
->interrupt_ctl
= 0;
360 prq
->dummy_dma_addr
= cpu_to_le64(adapter
->dummy_dma
.phys_addr
);
362 offset
= recv_ctx
->phys_addr
+ sizeof(struct netxen_ring_ctx
);
363 prq
->cmd_cons_dma_addr
= cpu_to_le64(offset
);
365 prq_cds
= &prq
->cds_ring
;
367 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
368 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
370 phys_addr
= rq_phys_addr
;
371 err
= netxen_issue_cmd(adapter
,
372 adapter
->ahw
.pci_func
,
374 (u32
)(phys_addr
>> 32),
375 ((u32
)phys_addr
& 0xffffffff),
377 NX_CDRP_CMD_CREATE_TX_CTX
);
379 if (err
== NX_RCODE_SUCCESS
) {
380 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
381 tx_ring
->crb_cmd_producer
= NETXEN_NIC_REG(temp
- 0x200);
384 le32_to_cpu(prsp
->host_ctx_state
);
386 adapter
->tx_context_id
=
387 le16_to_cpu(prsp
->context_id
);
390 "Failed to create tx ctx in firmware%d\n", err
);
394 pci_free_consistent(adapter
->pdev
, rsp_size
, rsp_addr
, rsp_phys_addr
);
397 pci_free_consistent(adapter
->pdev
, rq_size
, rq_addr
, rq_phys_addr
);
403 nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter
*adapter
)
405 if (netxen_issue_cmd(adapter
,
406 adapter
->ahw
.pci_func
,
408 adapter
->tx_context_id
,
409 NX_DESTROY_CTX_RESET
,
411 NX_CDRP_CMD_DESTROY_TX_CTX
)) {
414 "%s: Failed to destroy tx ctx in firmware\n",
415 netxen_nic_driver_name
);
419 static u64 ctx_addr_sig_regs
[][3] = {
420 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
421 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
422 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
423 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
426 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
427 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
428 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
430 #define lower32(x) ((u32)((x) & 0xffffffff))
431 #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
433 static struct netxen_recv_crb recv_crb_registers
[] = {
436 /* crb_rcv_producer: */
438 NETXEN_NIC_REG(0x100),
440 NETXEN_NIC_REG(0x110),
442 NETXEN_NIC_REG(0x120)
444 /* crb_sts_consumer: */
446 NETXEN_NIC_REG(0x138),
447 NETXEN_NIC_REG_2(0x000),
448 NETXEN_NIC_REG_2(0x004),
449 NETXEN_NIC_REG_2(0x008),
454 NETXEN_NIC_REG_2(0x044),
455 NETXEN_NIC_REG_2(0x048),
456 NETXEN_NIC_REG_2(0x04c),
461 /* crb_rcv_producer: */
463 NETXEN_NIC_REG(0x144),
465 NETXEN_NIC_REG(0x154),
467 NETXEN_NIC_REG(0x164)
469 /* crb_sts_consumer: */
471 NETXEN_NIC_REG(0x17c),
472 NETXEN_NIC_REG_2(0x020),
473 NETXEN_NIC_REG_2(0x024),
474 NETXEN_NIC_REG_2(0x028),
479 NETXEN_NIC_REG_2(0x064),
480 NETXEN_NIC_REG_2(0x068),
481 NETXEN_NIC_REG_2(0x06c),
486 /* crb_rcv_producer: */
488 NETXEN_NIC_REG(0x1d8),
490 NETXEN_NIC_REG(0x1f8),
492 NETXEN_NIC_REG(0x208)
494 /* crb_sts_consumer: */
496 NETXEN_NIC_REG(0x220),
497 NETXEN_NIC_REG_2(0x03c),
498 NETXEN_NIC_REG_2(0x03c),
499 NETXEN_NIC_REG_2(0x03c),
504 NETXEN_NIC_REG_2(0x03c),
505 NETXEN_NIC_REG_2(0x03c),
506 NETXEN_NIC_REG_2(0x03c),
511 /* crb_rcv_producer: */
513 NETXEN_NIC_REG(0x22c),
515 NETXEN_NIC_REG(0x23c),
517 NETXEN_NIC_REG(0x24c)
519 /* crb_sts_consumer: */
521 NETXEN_NIC_REG(0x264),
522 NETXEN_NIC_REG_2(0x03c),
523 NETXEN_NIC_REG_2(0x03c),
524 NETXEN_NIC_REG_2(0x03c),
529 NETXEN_NIC_REG_2(0x03c),
530 NETXEN_NIC_REG_2(0x03c),
531 NETXEN_NIC_REG_2(0x03c),
537 netxen_init_old_ctx(struct netxen_adapter
*adapter
)
539 struct netxen_recv_context
*recv_ctx
;
540 struct nx_host_rds_ring
*rds_ring
;
541 struct nx_host_sds_ring
*sds_ring
;
542 struct nx_host_tx_ring
*tx_ring
;
544 int port
= adapter
->portnum
;
545 struct netxen_ring_ctx
*hwctx
;
548 tx_ring
= adapter
->tx_ring
;
549 recv_ctx
= &adapter
->recv_ctx
;
550 hwctx
= recv_ctx
->hwctx
;
552 hwctx
->cmd_ring_addr
= cpu_to_le64(tx_ring
->phys_addr
);
553 hwctx
->cmd_ring_size
= cpu_to_le32(tx_ring
->num_desc
);
556 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
557 rds_ring
= &recv_ctx
->rds_rings
[ring
];
559 hwctx
->rcv_rings
[ring
].addr
=
560 cpu_to_le64(rds_ring
->phys_addr
);
561 hwctx
->rcv_rings
[ring
].size
=
562 cpu_to_le32(rds_ring
->num_desc
);
565 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
566 sds_ring
= &recv_ctx
->sds_rings
[ring
];
569 hwctx
->sts_ring_addr
= cpu_to_le64(sds_ring
->phys_addr
);
570 hwctx
->sts_ring_size
= cpu_to_le32(sds_ring
->num_desc
);
572 hwctx
->sts_rings
[ring
].addr
= cpu_to_le64(sds_ring
->phys_addr
);
573 hwctx
->sts_rings
[ring
].size
= cpu_to_le32(sds_ring
->num_desc
);
574 hwctx
->sts_rings
[ring
].msi_index
= cpu_to_le16(ring
);
576 hwctx
->sts_ring_count
= cpu_to_le32(adapter
->max_sds_rings
);
578 signature
= (adapter
->max_sds_rings
> 1) ?
579 NETXEN_CTX_SIGNATURE_V2
: NETXEN_CTX_SIGNATURE
;
581 NXWR32(adapter
, CRB_CTX_ADDR_REG_LO(port
),
582 lower32(recv_ctx
->phys_addr
));
583 NXWR32(adapter
, CRB_CTX_ADDR_REG_HI(port
),
584 upper32(recv_ctx
->phys_addr
));
585 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
590 int netxen_alloc_hw_resources(struct netxen_adapter
*adapter
)
595 struct netxen_recv_context
*recv_ctx
;
596 struct nx_host_rds_ring
*rds_ring
;
597 struct nx_host_sds_ring
*sds_ring
;
598 struct nx_host_tx_ring
*tx_ring
;
600 struct pci_dev
*pdev
= adapter
->pdev
;
601 struct net_device
*netdev
= adapter
->netdev
;
602 int port
= adapter
->portnum
;
604 recv_ctx
= &adapter
->recv_ctx
;
605 tx_ring
= adapter
->tx_ring
;
607 addr
= pci_alloc_consistent(pdev
,
608 sizeof(struct netxen_ring_ctx
) + sizeof(uint32_t),
609 &recv_ctx
->phys_addr
);
611 dev_err(&pdev
->dev
, "failed to allocate hw context\n");
615 memset(addr
, 0, sizeof(struct netxen_ring_ctx
));
616 recv_ctx
->hwctx
= (struct netxen_ring_ctx
*)addr
;
617 recv_ctx
->hwctx
->ctx_id
= cpu_to_le32(port
);
618 recv_ctx
->hwctx
->cmd_consumer_offset
=
619 cpu_to_le64(recv_ctx
->phys_addr
+
620 sizeof(struct netxen_ring_ctx
));
621 tx_ring
->hw_consumer
=
622 (__le32
*)(((char *)addr
) + sizeof(struct netxen_ring_ctx
));
625 addr
= pci_alloc_consistent(pdev
, TX_DESC_RINGSIZE(tx_ring
),
626 &tx_ring
->phys_addr
);
629 dev_err(&pdev
->dev
, "%s: failed to allocate tx desc ring\n",
634 tx_ring
->desc_head
= (struct cmd_desc_type0
*)addr
;
636 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
637 rds_ring
= &recv_ctx
->rds_rings
[ring
];
638 addr
= pci_alloc_consistent(adapter
->pdev
,
639 RCV_DESC_RINGSIZE(rds_ring
),
640 &rds_ring
->phys_addr
);
643 "%s: failed to allocate rds ring [%d]\n",
648 rds_ring
->desc_head
= (struct rcv_desc
*)addr
;
650 if (adapter
->fw_major
< 4)
651 rds_ring
->crb_rcv_producer
=
652 recv_crb_registers
[port
].crb_rcv_producer
[ring
];
655 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
656 sds_ring
= &recv_ctx
->sds_rings
[ring
];
658 addr
= pci_alloc_consistent(adapter
->pdev
,
659 STATUS_DESC_RINGSIZE(sds_ring
),
660 &sds_ring
->phys_addr
);
663 "%s: failed to allocate sds ring [%d]\n",
668 sds_ring
->desc_head
= (struct status_desc
*)addr
;
670 sds_ring
->crb_sts_consumer
=
671 recv_crb_registers
[port
].crb_sts_consumer
[ring
];
673 sds_ring
->crb_intr_mask
=
674 recv_crb_registers
[port
].sw_int_mask
[ring
];
678 if (adapter
->fw_major
>= 4) {
679 err
= nx_fw_cmd_create_rx_ctx(adapter
);
682 err
= nx_fw_cmd_create_tx_ctx(adapter
);
686 err
= netxen_init_old_ctx(adapter
);
688 netxen_free_hw_resources(adapter
);
696 netxen_free_hw_resources(adapter
);
700 void netxen_free_hw_resources(struct netxen_adapter
*adapter
)
702 struct netxen_recv_context
*recv_ctx
;
703 struct nx_host_rds_ring
*rds_ring
;
704 struct nx_host_sds_ring
*sds_ring
;
705 struct nx_host_tx_ring
*tx_ring
;
708 int port
= adapter
->portnum
;
710 if (adapter
->fw_major
>= 4) {
711 nx_fw_cmd_destroy_tx_ctx(adapter
);
712 nx_fw_cmd_destroy_rx_ctx(adapter
);
714 netxen_api_lock(adapter
);
715 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
716 NETXEN_CTX_RESET
| port
);
717 netxen_api_unlock(adapter
);
720 recv_ctx
= &adapter
->recv_ctx
;
722 if (recv_ctx
->hwctx
!= NULL
) {
723 pci_free_consistent(adapter
->pdev
,
724 sizeof(struct netxen_ring_ctx
) +
727 recv_ctx
->phys_addr
);
728 recv_ctx
->hwctx
= NULL
;
731 tx_ring
= adapter
->tx_ring
;
732 if (tx_ring
->desc_head
!= NULL
) {
733 pci_free_consistent(adapter
->pdev
,
734 TX_DESC_RINGSIZE(tx_ring
),
735 tx_ring
->desc_head
, tx_ring
->phys_addr
);
736 tx_ring
->desc_head
= NULL
;
739 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
740 rds_ring
= &recv_ctx
->rds_rings
[ring
];
742 if (rds_ring
->desc_head
!= NULL
) {
743 pci_free_consistent(adapter
->pdev
,
744 RCV_DESC_RINGSIZE(rds_ring
),
746 rds_ring
->phys_addr
);
747 rds_ring
->desc_head
= NULL
;
751 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
752 sds_ring
= &recv_ctx
->sds_rings
[ring
];
754 if (sds_ring
->desc_head
!= NULL
) {
755 pci_free_consistent(adapter
->pdev
,
756 STATUS_DESC_RINGSIZE(sds_ring
),
758 sds_ring
->phys_addr
);
759 sds_ring
->desc_head
= NULL
;