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"
34 #define NXHAL_VERSION 1
37 netxen_poll_rsp(struct netxen_adapter
*adapter
)
39 u32 rsp
= NX_CDRP_RSP_OK
;
43 /* give atleast 1ms for firmware to respond */
46 if (++timeout
> NX_OS_CRB_RETRY_COUNT
)
47 return NX_CDRP_RSP_TIMEOUT
;
49 rsp
= NXRD32(adapter
, NX_CDRP_CRB_OFFSET
);
50 } while (!NX_CDRP_IS_RSP(rsp
));
56 netxen_issue_cmd(struct netxen_adapter
*adapter
,
57 u32 pci_fn
, u32 version
, u32 arg1
, u32 arg2
, u32 arg3
, u32 cmd
)
61 u32 rcode
= NX_RCODE_SUCCESS
;
63 signature
= NX_CDRP_SIGNATURE_MAKE(pci_fn
, version
);
65 /* Acquire semaphore before accessing CRB */
66 if (netxen_api_lock(adapter
))
67 return NX_RCODE_TIMEOUT
;
69 NXWR32(adapter
, NX_SIGN_CRB_OFFSET
, signature
);
71 NXWR32(adapter
, NX_ARG1_CRB_OFFSET
, arg1
);
73 NXWR32(adapter
, NX_ARG2_CRB_OFFSET
, arg2
);
75 NXWR32(adapter
, NX_ARG3_CRB_OFFSET
, arg3
);
77 NXWR32(adapter
, NX_CDRP_CRB_OFFSET
, NX_CDRP_FORM_CMD(cmd
));
79 rsp
= netxen_poll_rsp(adapter
);
81 if (rsp
== NX_CDRP_RSP_TIMEOUT
) {
82 printk(KERN_ERR
"%s: card response timeout.\n",
83 netxen_nic_driver_name
);
85 rcode
= NX_RCODE_TIMEOUT
;
86 } else if (rsp
== NX_CDRP_RSP_FAIL
) {
87 rcode
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
89 printk(KERN_ERR
"%s: failed card response code:0x%x\n",
90 netxen_nic_driver_name
, rcode
);
93 /* Release semaphore */
94 netxen_api_unlock(adapter
);
100 nx_fw_cmd_set_mtu(struct netxen_adapter
*adapter
, int mtu
)
102 u32 rcode
= NX_RCODE_SUCCESS
;
103 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
105 if (recv_ctx
->state
== NX_HOST_CTX_STATE_ACTIVE
)
106 rcode
= netxen_issue_cmd(adapter
,
107 adapter
->ahw
.pci_func
,
109 recv_ctx
->context_id
,
112 NX_CDRP_CMD_SET_MTU
);
114 if (rcode
!= NX_RCODE_SUCCESS
)
121 nx_fw_cmd_create_rx_ctx(struct netxen_adapter
*adapter
)
124 nx_hostrq_rx_ctx_t
*prq
;
125 nx_cardrsp_rx_ctx_t
*prsp
;
126 nx_hostrq_rds_ring_t
*prq_rds
;
127 nx_hostrq_sds_ring_t
*prq_sds
;
128 nx_cardrsp_rds_ring_t
*prsp_rds
;
129 nx_cardrsp_sds_ring_t
*prsp_sds
;
130 struct nx_host_rds_ring
*rds_ring
;
131 struct nx_host_sds_ring
*sds_ring
;
133 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
136 int i
, nrds_rings
, nsds_rings
;
137 size_t rq_size
, rsp_size
;
142 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
144 nrds_rings
= adapter
->max_rds_rings
;
145 nsds_rings
= adapter
->max_sds_rings
;
148 SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t
, nrds_rings
, nsds_rings
);
150 SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t
, nrds_rings
, nsds_rings
);
152 addr
= pci_alloc_consistent(adapter
->pdev
,
153 rq_size
, &hostrq_phys_addr
);
156 prq
= (nx_hostrq_rx_ctx_t
*)addr
;
158 addr
= pci_alloc_consistent(adapter
->pdev
,
159 rsp_size
, &cardrsp_phys_addr
);
164 prsp
= (nx_cardrsp_rx_ctx_t
*)addr
;
166 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
168 cap
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
);
169 cap
|= (NX_CAP0_JUMBO_CONTIGUOUS
| NX_CAP0_LRO_CONTIGUOUS
);
171 prq
->capabilities
[0] = cpu_to_le32(cap
);
172 prq
->host_int_crb_mode
=
173 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
174 prq
->host_rds_crb_mode
=
175 cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE
);
177 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
178 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
179 prq
->rds_ring_offset
= cpu_to_le32(0);
181 val
= le32_to_cpu(prq
->rds_ring_offset
) +
182 (sizeof(nx_hostrq_rds_ring_t
) * nrds_rings
);
183 prq
->sds_ring_offset
= cpu_to_le32(val
);
185 prq_rds
= (nx_hostrq_rds_ring_t
*)(prq
->data
+
186 le32_to_cpu(prq
->rds_ring_offset
));
188 for (i
= 0; i
< nrds_rings
; i
++) {
190 rds_ring
= &recv_ctx
->rds_rings
[i
];
192 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
193 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
194 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
195 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
198 prq_sds
= (nx_hostrq_sds_ring_t
*)(prq
->data
+
199 le32_to_cpu(prq
->sds_ring_offset
));
201 for (i
= 0; i
< nsds_rings
; i
++) {
203 sds_ring
= &recv_ctx
->sds_rings
[i
];
205 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
206 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
207 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
210 phys_addr
= hostrq_phys_addr
;
211 err
= netxen_issue_cmd(adapter
,
212 adapter
->ahw
.pci_func
,
214 (u32
)(phys_addr
>> 32),
215 (u32
)(phys_addr
& 0xffffffff),
217 NX_CDRP_CMD_CREATE_RX_CTX
);
220 "Failed to create rx ctx in firmware%d\n", err
);
225 prsp_rds
= ((nx_cardrsp_rds_ring_t
*)
226 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
228 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
229 rds_ring
= &recv_ctx
->rds_rings
[i
];
231 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
232 rds_ring
->crb_rcv_producer
= netxen_get_ioaddr(adapter
,
233 NETXEN_NIC_REG(reg
- 0x200));
236 prsp_sds
= ((nx_cardrsp_sds_ring_t
*)
237 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
239 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
240 sds_ring
= &recv_ctx
->sds_rings
[i
];
242 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
243 sds_ring
->crb_sts_consumer
= netxen_get_ioaddr(adapter
,
244 NETXEN_NIC_REG(reg
- 0x200));
246 reg
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
247 sds_ring
->crb_intr_mask
= netxen_get_ioaddr(adapter
,
248 NETXEN_NIC_REG(reg
- 0x200));
251 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
252 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
253 recv_ctx
->virt_port
= prsp
->virt_port
;
256 pci_free_consistent(adapter
->pdev
, rsp_size
, prsp
, cardrsp_phys_addr
);
258 pci_free_consistent(adapter
->pdev
, rq_size
, prq
, hostrq_phys_addr
);
263 nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter
*adapter
)
265 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
267 if (netxen_issue_cmd(adapter
,
268 adapter
->ahw
.pci_func
,
270 recv_ctx
->context_id
,
271 NX_DESTROY_CTX_RESET
,
273 NX_CDRP_CMD_DESTROY_RX_CTX
)) {
276 "%s: Failed to destroy rx ctx in firmware\n",
277 netxen_nic_driver_name
);
282 nx_fw_cmd_create_tx_ctx(struct netxen_adapter
*adapter
)
284 nx_hostrq_tx_ctx_t
*prq
;
285 nx_hostrq_cds_ring_t
*prq_cds
;
286 nx_cardrsp_tx_ctx_t
*prsp
;
287 void *rq_addr
, *rsp_addr
;
288 size_t rq_size
, rsp_size
;
291 u64 offset
, phys_addr
;
292 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
293 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
294 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
296 rq_size
= SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t
);
297 rq_addr
= pci_alloc_consistent(adapter
->pdev
,
298 rq_size
, &rq_phys_addr
);
302 rsp_size
= SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t
);
303 rsp_addr
= pci_alloc_consistent(adapter
->pdev
,
304 rsp_size
, &rsp_phys_addr
);
310 memset(rq_addr
, 0, rq_size
);
311 prq
= (nx_hostrq_tx_ctx_t
*)rq_addr
;
313 memset(rsp_addr
, 0, rsp_size
);
314 prsp
= (nx_cardrsp_tx_ctx_t
*)rsp_addr
;
316 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
318 temp
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
| NX_CAP0_LSO
);
319 prq
->capabilities
[0] = cpu_to_le32(temp
);
321 prq
->host_int_crb_mode
=
322 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
324 prq
->interrupt_ctl
= 0;
327 prq
->dummy_dma_addr
= cpu_to_le64(adapter
->dummy_dma
.phys_addr
);
329 offset
= recv_ctx
->phys_addr
+ sizeof(struct netxen_ring_ctx
);
330 prq
->cmd_cons_dma_addr
= cpu_to_le64(offset
);
332 prq_cds
= &prq
->cds_ring
;
334 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
335 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
337 phys_addr
= rq_phys_addr
;
338 err
= netxen_issue_cmd(adapter
,
339 adapter
->ahw
.pci_func
,
341 (u32
)(phys_addr
>> 32),
342 ((u32
)phys_addr
& 0xffffffff),
344 NX_CDRP_CMD_CREATE_TX_CTX
);
346 if (err
== NX_RCODE_SUCCESS
) {
347 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
348 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
349 NETXEN_NIC_REG(temp
- 0x200));
352 le32_to_cpu(prsp
->host_ctx_state
);
354 adapter
->tx_context_id
=
355 le16_to_cpu(prsp
->context_id
);
358 "Failed to create tx ctx in firmware%d\n", err
);
362 pci_free_consistent(adapter
->pdev
, rsp_size
, rsp_addr
, rsp_phys_addr
);
365 pci_free_consistent(adapter
->pdev
, rq_size
, rq_addr
, rq_phys_addr
);
371 nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter
*adapter
)
373 if (netxen_issue_cmd(adapter
,
374 adapter
->ahw
.pci_func
,
376 adapter
->tx_context_id
,
377 NX_DESTROY_CTX_RESET
,
379 NX_CDRP_CMD_DESTROY_TX_CTX
)) {
382 "%s: Failed to destroy tx ctx in firmware\n",
383 netxen_nic_driver_name
);
388 nx_fw_cmd_query_phy(struct netxen_adapter
*adapter
, u32 reg
, u32
*val
)
392 rcode
= netxen_issue_cmd(adapter
,
393 adapter
->ahw
.pci_func
,
398 NX_CDRP_CMD_READ_PHY
);
400 if (rcode
!= NX_RCODE_SUCCESS
)
403 return NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
407 nx_fw_cmd_set_phy(struct netxen_adapter
*adapter
, u32 reg
, u32 val
)
411 rcode
= netxen_issue_cmd(adapter
,
412 adapter
->ahw
.pci_func
,
417 NX_CDRP_CMD_WRITE_PHY
);
419 if (rcode
!= NX_RCODE_SUCCESS
)
425 static u64 ctx_addr_sig_regs
[][3] = {
426 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
427 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
428 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
429 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
432 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
433 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
434 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
436 #define lower32(x) ((u32)((x) & 0xffffffff))
437 #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
439 static struct netxen_recv_crb recv_crb_registers
[] = {
442 /* crb_rcv_producer: */
444 NETXEN_NIC_REG(0x100),
446 NETXEN_NIC_REG(0x110),
448 NETXEN_NIC_REG(0x120)
450 /* crb_sts_consumer: */
452 NETXEN_NIC_REG(0x138),
453 NETXEN_NIC_REG_2(0x000),
454 NETXEN_NIC_REG_2(0x004),
455 NETXEN_NIC_REG_2(0x008),
460 NETXEN_NIC_REG_2(0x044),
461 NETXEN_NIC_REG_2(0x048),
462 NETXEN_NIC_REG_2(0x04c),
467 /* crb_rcv_producer: */
469 NETXEN_NIC_REG(0x144),
471 NETXEN_NIC_REG(0x154),
473 NETXEN_NIC_REG(0x164)
475 /* crb_sts_consumer: */
477 NETXEN_NIC_REG(0x17c),
478 NETXEN_NIC_REG_2(0x020),
479 NETXEN_NIC_REG_2(0x024),
480 NETXEN_NIC_REG_2(0x028),
485 NETXEN_NIC_REG_2(0x064),
486 NETXEN_NIC_REG_2(0x068),
487 NETXEN_NIC_REG_2(0x06c),
492 /* crb_rcv_producer: */
494 NETXEN_NIC_REG(0x1d8),
496 NETXEN_NIC_REG(0x1f8),
498 NETXEN_NIC_REG(0x208)
500 /* crb_sts_consumer: */
502 NETXEN_NIC_REG(0x220),
503 NETXEN_NIC_REG_2(0x03c),
504 NETXEN_NIC_REG_2(0x03c),
505 NETXEN_NIC_REG_2(0x03c),
510 NETXEN_NIC_REG_2(0x03c),
511 NETXEN_NIC_REG_2(0x03c),
512 NETXEN_NIC_REG_2(0x03c),
517 /* crb_rcv_producer: */
519 NETXEN_NIC_REG(0x22c),
521 NETXEN_NIC_REG(0x23c),
523 NETXEN_NIC_REG(0x24c)
525 /* crb_sts_consumer: */
527 NETXEN_NIC_REG(0x264),
528 NETXEN_NIC_REG_2(0x03c),
529 NETXEN_NIC_REG_2(0x03c),
530 NETXEN_NIC_REG_2(0x03c),
535 NETXEN_NIC_REG_2(0x03c),
536 NETXEN_NIC_REG_2(0x03c),
537 NETXEN_NIC_REG_2(0x03c),
543 netxen_init_old_ctx(struct netxen_adapter
*adapter
)
545 struct netxen_recv_context
*recv_ctx
;
546 struct nx_host_rds_ring
*rds_ring
;
547 struct nx_host_sds_ring
*sds_ring
;
548 struct nx_host_tx_ring
*tx_ring
;
550 int port
= adapter
->portnum
;
551 struct netxen_ring_ctx
*hwctx
;
554 tx_ring
= adapter
->tx_ring
;
555 recv_ctx
= &adapter
->recv_ctx
;
556 hwctx
= recv_ctx
->hwctx
;
558 hwctx
->cmd_ring_addr
= cpu_to_le64(tx_ring
->phys_addr
);
559 hwctx
->cmd_ring_size
= cpu_to_le32(tx_ring
->num_desc
);
562 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
563 rds_ring
= &recv_ctx
->rds_rings
[ring
];
565 hwctx
->rcv_rings
[ring
].addr
=
566 cpu_to_le64(rds_ring
->phys_addr
);
567 hwctx
->rcv_rings
[ring
].size
=
568 cpu_to_le32(rds_ring
->num_desc
);
571 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
572 sds_ring
= &recv_ctx
->sds_rings
[ring
];
575 hwctx
->sts_ring_addr
= cpu_to_le64(sds_ring
->phys_addr
);
576 hwctx
->sts_ring_size
= cpu_to_le32(sds_ring
->num_desc
);
578 hwctx
->sts_rings
[ring
].addr
= cpu_to_le64(sds_ring
->phys_addr
);
579 hwctx
->sts_rings
[ring
].size
= cpu_to_le32(sds_ring
->num_desc
);
580 hwctx
->sts_rings
[ring
].msi_index
= cpu_to_le16(ring
);
582 hwctx
->sts_ring_count
= cpu_to_le32(adapter
->max_sds_rings
);
584 signature
= (adapter
->max_sds_rings
> 1) ?
585 NETXEN_CTX_SIGNATURE_V2
: NETXEN_CTX_SIGNATURE
;
587 NXWR32(adapter
, CRB_CTX_ADDR_REG_LO(port
),
588 lower32(recv_ctx
->phys_addr
));
589 NXWR32(adapter
, CRB_CTX_ADDR_REG_HI(port
),
590 upper32(recv_ctx
->phys_addr
));
591 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
596 int netxen_alloc_hw_resources(struct netxen_adapter
*adapter
)
601 struct netxen_recv_context
*recv_ctx
;
602 struct nx_host_rds_ring
*rds_ring
;
603 struct nx_host_sds_ring
*sds_ring
;
604 struct nx_host_tx_ring
*tx_ring
;
606 struct pci_dev
*pdev
= adapter
->pdev
;
607 struct net_device
*netdev
= adapter
->netdev
;
608 int port
= adapter
->portnum
;
610 recv_ctx
= &adapter
->recv_ctx
;
611 tx_ring
= adapter
->tx_ring
;
613 addr
= pci_alloc_consistent(pdev
,
614 sizeof(struct netxen_ring_ctx
) + sizeof(uint32_t),
615 &recv_ctx
->phys_addr
);
617 dev_err(&pdev
->dev
, "failed to allocate hw context\n");
621 memset(addr
, 0, sizeof(struct netxen_ring_ctx
));
622 recv_ctx
->hwctx
= (struct netxen_ring_ctx
*)addr
;
623 recv_ctx
->hwctx
->ctx_id
= cpu_to_le32(port
);
624 recv_ctx
->hwctx
->cmd_consumer_offset
=
625 cpu_to_le64(recv_ctx
->phys_addr
+
626 sizeof(struct netxen_ring_ctx
));
627 tx_ring
->hw_consumer
=
628 (__le32
*)(((char *)addr
) + sizeof(struct netxen_ring_ctx
));
631 addr
= pci_alloc_consistent(pdev
, TX_DESC_RINGSIZE(tx_ring
),
632 &tx_ring
->phys_addr
);
635 dev_err(&pdev
->dev
, "%s: failed to allocate tx desc ring\n",
640 tx_ring
->desc_head
= (struct cmd_desc_type0
*)addr
;
642 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
643 rds_ring
= &recv_ctx
->rds_rings
[ring
];
644 addr
= pci_alloc_consistent(adapter
->pdev
,
645 RCV_DESC_RINGSIZE(rds_ring
),
646 &rds_ring
->phys_addr
);
649 "%s: failed to allocate rds ring [%d]\n",
654 rds_ring
->desc_head
= (struct rcv_desc
*)addr
;
656 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
657 rds_ring
->crb_rcv_producer
=
658 netxen_get_ioaddr(adapter
,
659 recv_crb_registers
[port
].crb_rcv_producer
[ring
]);
662 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
663 sds_ring
= &recv_ctx
->sds_rings
[ring
];
665 addr
= pci_alloc_consistent(adapter
->pdev
,
666 STATUS_DESC_RINGSIZE(sds_ring
),
667 &sds_ring
->phys_addr
);
670 "%s: failed to allocate sds ring [%d]\n",
675 sds_ring
->desc_head
= (struct status_desc
*)addr
;
677 sds_ring
->crb_sts_consumer
=
678 netxen_get_ioaddr(adapter
,
679 recv_crb_registers
[port
].crb_sts_consumer
[ring
]);
681 sds_ring
->crb_intr_mask
=
682 netxen_get_ioaddr(adapter
,
683 recv_crb_registers
[port
].sw_int_mask
[ring
]);
687 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
688 if (test_and_set_bit(__NX_FW_ATTACHED
, &adapter
->state
))
691 err
= nx_fw_cmd_create_rx_ctx(adapter
);
694 err
= nx_fw_cmd_create_tx_ctx(adapter
);
698 err
= netxen_init_old_ctx(adapter
);
707 netxen_free_hw_resources(adapter
);
711 void netxen_free_hw_resources(struct netxen_adapter
*adapter
)
713 struct netxen_recv_context
*recv_ctx
;
714 struct nx_host_rds_ring
*rds_ring
;
715 struct nx_host_sds_ring
*sds_ring
;
716 struct nx_host_tx_ring
*tx_ring
;
719 int port
= adapter
->portnum
;
721 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
722 if (!test_and_clear_bit(__NX_FW_ATTACHED
, &adapter
->state
))
725 nx_fw_cmd_destroy_rx_ctx(adapter
);
726 nx_fw_cmd_destroy_tx_ctx(adapter
);
728 netxen_api_lock(adapter
);
729 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
730 NETXEN_CTX_D3_RESET
| port
);
731 netxen_api_unlock(adapter
);
734 /* Allow dma queues to drain after context reset */
738 recv_ctx
= &adapter
->recv_ctx
;
740 if (recv_ctx
->hwctx
!= NULL
) {
741 pci_free_consistent(adapter
->pdev
,
742 sizeof(struct netxen_ring_ctx
) +
745 recv_ctx
->phys_addr
);
746 recv_ctx
->hwctx
= NULL
;
749 tx_ring
= adapter
->tx_ring
;
750 if (tx_ring
->desc_head
!= NULL
) {
751 pci_free_consistent(adapter
->pdev
,
752 TX_DESC_RINGSIZE(tx_ring
),
753 tx_ring
->desc_head
, tx_ring
->phys_addr
);
754 tx_ring
->desc_head
= NULL
;
757 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
758 rds_ring
= &recv_ctx
->rds_rings
[ring
];
760 if (rds_ring
->desc_head
!= NULL
) {
761 pci_free_consistent(adapter
->pdev
,
762 RCV_DESC_RINGSIZE(rds_ring
),
764 rds_ring
->phys_addr
);
765 rds_ring
->desc_head
= NULL
;
769 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
770 sds_ring
= &recv_ctx
->sds_rings
[ring
];
772 if (sds_ring
->desc_head
!= NULL
) {
773 pci_free_consistent(adapter
->pdev
,
774 STATUS_DESC_RINGSIZE(sds_ring
),
776 sds_ring
->phys_addr
);
777 sds_ring
->desc_head
= NULL
;