1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2003 - 2009 NetXen, Inc.
4 * Copyright (C) 2009 - QLogic Corporation.
8 #include "netxen_nic_hw.h"
9 #include "netxen_nic.h"
11 #define NXHAL_VERSION 1
14 netxen_poll_rsp(struct netxen_adapter
*adapter
)
16 u32 rsp
= NX_CDRP_RSP_OK
;
20 /* give atleast 1ms for firmware to respond */
23 if (++timeout
> NX_OS_CRB_RETRY_COUNT
)
24 return NX_CDRP_RSP_TIMEOUT
;
26 rsp
= NXRD32(adapter
, NX_CDRP_CRB_OFFSET
);
27 } while (!NX_CDRP_IS_RSP(rsp
));
33 netxen_issue_cmd(struct netxen_adapter
*adapter
, struct netxen_cmd_args
*cmd
)
37 u32 rcode
= NX_RCODE_SUCCESS
;
39 signature
= NX_CDRP_SIGNATURE_MAKE(adapter
->ahw
.pci_func
,
41 /* Acquire semaphore before accessing CRB */
42 if (netxen_api_lock(adapter
))
43 return NX_RCODE_TIMEOUT
;
45 NXWR32(adapter
, NX_SIGN_CRB_OFFSET
, signature
);
47 NXWR32(adapter
, NX_ARG1_CRB_OFFSET
, cmd
->req
.arg1
);
49 NXWR32(adapter
, NX_ARG2_CRB_OFFSET
, cmd
->req
.arg2
);
51 NXWR32(adapter
, NX_ARG3_CRB_OFFSET
, cmd
->req
.arg3
);
53 NXWR32(adapter
, NX_CDRP_CRB_OFFSET
, NX_CDRP_FORM_CMD(cmd
->req
.cmd
));
55 rsp
= netxen_poll_rsp(adapter
);
57 if (rsp
== NX_CDRP_RSP_TIMEOUT
) {
58 printk(KERN_ERR
"%s: card response timeout.\n",
59 netxen_nic_driver_name
);
61 rcode
= NX_RCODE_TIMEOUT
;
62 } else if (rsp
== NX_CDRP_RSP_FAIL
) {
63 rcode
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
65 printk(KERN_ERR
"%s: failed card response code:0x%x\n",
66 netxen_nic_driver_name
, rcode
);
67 } else if (rsp
== NX_CDRP_RSP_OK
) {
68 cmd
->rsp
.cmd
= NX_RCODE_SUCCESS
;
70 cmd
->rsp
.arg2
= NXRD32(adapter
, NX_ARG2_CRB_OFFSET
);
72 cmd
->rsp
.arg3
= NXRD32(adapter
, NX_ARG3_CRB_OFFSET
);
76 cmd
->rsp
.arg1
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
77 /* Release semaphore */
78 netxen_api_unlock(adapter
);
84 netxen_get_minidump_template_size(struct netxen_adapter
*adapter
)
86 struct netxen_cmd_args cmd
;
87 memset(&cmd
, 0, sizeof(cmd
));
88 cmd
.req
.cmd
= NX_CDRP_CMD_TEMP_SIZE
;
89 memset(&cmd
.rsp
, 1, sizeof(struct _cdrp_cmd
));
90 netxen_issue_cmd(adapter
, &cmd
);
91 if (cmd
.rsp
.cmd
!= NX_RCODE_SUCCESS
) {
92 dev_info(&adapter
->pdev
->dev
,
93 "Can't get template size %d\n", cmd
.rsp
.cmd
);
96 adapter
->mdump
.md_template_size
= cmd
.rsp
.arg2
;
97 adapter
->mdump
.md_template_ver
= cmd
.rsp
.arg3
;
102 netxen_get_minidump_template(struct netxen_adapter
*adapter
)
104 dma_addr_t md_template_addr
;
107 struct netxen_cmd_args cmd
;
108 size
= adapter
->mdump
.md_template_size
;
111 dev_err(&adapter
->pdev
->dev
, "Can not capture Minidump "
112 "template. Invalid template size.\n");
113 return NX_RCODE_INVALID_ARGS
;
116 addr
= pci_zalloc_consistent(adapter
->pdev
, size
, &md_template_addr
);
118 dev_err(&adapter
->pdev
->dev
, "Unable to allocate dmable memory for template.\n");
122 memset(&cmd
, 0, sizeof(cmd
));
123 memset(&cmd
.rsp
, 1, sizeof(struct _cdrp_cmd
));
124 cmd
.req
.cmd
= NX_CDRP_CMD_GET_TEMP_HDR
;
125 cmd
.req
.arg1
= LSD(md_template_addr
);
126 cmd
.req
.arg2
= MSD(md_template_addr
);
127 cmd
.req
.arg3
|= size
;
128 netxen_issue_cmd(adapter
, &cmd
);
130 if ((cmd
.rsp
.cmd
== NX_RCODE_SUCCESS
) && (size
== cmd
.rsp
.arg2
)) {
131 memcpy(adapter
->mdump
.md_template
, addr
, size
);
133 dev_err(&adapter
->pdev
->dev
, "Failed to get minidump template, err_code : %d, requested_size : %d, actual_size : %d\n",
134 cmd
.rsp
.cmd
, size
, cmd
.rsp
.arg2
);
136 pci_free_consistent(adapter
->pdev
, size
, addr
, md_template_addr
);
141 netxen_check_template_checksum(struct netxen_adapter
*adapter
)
144 u32
*buff
= adapter
->mdump
.md_template
;
145 int count
= adapter
->mdump
.md_template_size
/sizeof(uint32_t) ;
150 sum
= (sum
& 0xFFFFFFFF) + (sum
>> 32) ;
156 netxen_setup_minidump(struct netxen_adapter
*adapter
)
159 u32
*template, *tmp_buf
;
160 err
= netxen_get_minidump_template_size(adapter
);
162 adapter
->mdump
.fw_supports_md
= 0;
163 if ((err
== NX_RCODE_CMD_INVALID
) ||
164 (err
== NX_RCODE_CMD_NOT_IMPL
)) {
165 dev_info(&adapter
->pdev
->dev
,
166 "Flashed firmware version does not support minidump, minimum version required is [ %u.%u.%u ]\n",
167 NX_MD_SUPPORT_MAJOR
, NX_MD_SUPPORT_MINOR
,
168 NX_MD_SUPPORT_SUBVERSION
);
173 if (!adapter
->mdump
.md_template_size
) {
174 dev_err(&adapter
->pdev
->dev
, "Error : Invalid template size "
175 ",should be non-zero.\n");
178 adapter
->mdump
.md_template
=
179 kmalloc(adapter
->mdump
.md_template_size
, GFP_KERNEL
);
181 if (!adapter
->mdump
.md_template
)
184 err
= netxen_get_minidump_template(adapter
);
186 if (err
== NX_RCODE_CMD_NOT_IMPL
)
187 adapter
->mdump
.fw_supports_md
= 0;
191 if (netxen_check_template_checksum(adapter
)) {
192 dev_err(&adapter
->pdev
->dev
, "Minidump template checksum Error\n");
197 adapter
->mdump
.md_capture_mask
= NX_DUMP_MASK_DEF
;
198 tmp_buf
= (u32
*) adapter
->mdump
.md_template
;
199 template = (u32
*) adapter
->mdump
.md_template
;
200 for (i
= 0; i
< adapter
->mdump
.md_template_size
/sizeof(u32
); i
++)
201 *template++ = __le32_to_cpu(*tmp_buf
++);
202 adapter
->mdump
.md_capture_buff
= NULL
;
203 adapter
->mdump
.fw_supports_md
= 1;
204 adapter
->mdump
.md_enabled
= 0;
209 kfree(adapter
->mdump
.md_template
);
210 adapter
->mdump
.md_template
= NULL
;
216 nx_fw_cmd_set_mtu(struct netxen_adapter
*adapter
, int mtu
)
218 u32 rcode
= NX_RCODE_SUCCESS
;
219 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
220 struct netxen_cmd_args cmd
;
222 memset(&cmd
, 0, sizeof(cmd
));
223 cmd
.req
.cmd
= NX_CDRP_CMD_SET_MTU
;
224 cmd
.req
.arg1
= recv_ctx
->context_id
;
228 if (recv_ctx
->state
== NX_HOST_CTX_STATE_ACTIVE
)
229 rcode
= netxen_issue_cmd(adapter
, &cmd
);
231 if (rcode
!= NX_RCODE_SUCCESS
)
238 nx_fw_cmd_set_gbe_port(struct netxen_adapter
*adapter
,
239 u32 speed
, u32 duplex
, u32 autoneg
)
241 struct netxen_cmd_args cmd
;
243 memset(&cmd
, 0, sizeof(cmd
));
244 cmd
.req
.cmd
= NX_CDRP_CMD_CONFIG_GBE_PORT
;
245 cmd
.req
.arg1
= speed
;
246 cmd
.req
.arg2
= duplex
;
247 cmd
.req
.arg3
= autoneg
;
248 return netxen_issue_cmd(adapter
, &cmd
);
252 nx_fw_cmd_create_rx_ctx(struct netxen_adapter
*adapter
)
255 nx_hostrq_rx_ctx_t
*prq
;
256 nx_cardrsp_rx_ctx_t
*prsp
;
257 nx_hostrq_rds_ring_t
*prq_rds
;
258 nx_hostrq_sds_ring_t
*prq_sds
;
259 nx_cardrsp_rds_ring_t
*prsp_rds
;
260 nx_cardrsp_sds_ring_t
*prsp_sds
;
261 struct nx_host_rds_ring
*rds_ring
;
262 struct nx_host_sds_ring
*sds_ring
;
263 struct netxen_cmd_args cmd
;
265 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
268 int i
, nrds_rings
, nsds_rings
;
269 size_t rq_size
, rsp_size
;
274 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
276 nrds_rings
= adapter
->max_rds_rings
;
277 nsds_rings
= adapter
->max_sds_rings
;
280 SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t
, nrds_rings
, nsds_rings
);
282 SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t
, nrds_rings
, nsds_rings
);
284 addr
= pci_alloc_consistent(adapter
->pdev
,
285 rq_size
, &hostrq_phys_addr
);
290 addr
= pci_alloc_consistent(adapter
->pdev
,
291 rsp_size
, &cardrsp_phys_addr
);
298 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
300 cap
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
);
301 cap
|= (NX_CAP0_JUMBO_CONTIGUOUS
| NX_CAP0_LRO_CONTIGUOUS
);
303 if (adapter
->flags
& NETXEN_FW_MSS_CAP
)
304 cap
|= NX_CAP0_HW_LRO_MSS
;
306 prq
->capabilities
[0] = cpu_to_le32(cap
);
307 prq
->host_int_crb_mode
=
308 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
309 prq
->host_rds_crb_mode
=
310 cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE
);
312 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
313 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
314 prq
->rds_ring_offset
= cpu_to_le32(0);
316 val
= le32_to_cpu(prq
->rds_ring_offset
) +
317 (sizeof(nx_hostrq_rds_ring_t
) * nrds_rings
);
318 prq
->sds_ring_offset
= cpu_to_le32(val
);
320 prq_rds
= (nx_hostrq_rds_ring_t
*)(prq
->data
+
321 le32_to_cpu(prq
->rds_ring_offset
));
323 for (i
= 0; i
< nrds_rings
; i
++) {
325 rds_ring
= &recv_ctx
->rds_rings
[i
];
327 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
328 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
329 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
330 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
333 prq_sds
= (nx_hostrq_sds_ring_t
*)(prq
->data
+
334 le32_to_cpu(prq
->sds_ring_offset
));
336 for (i
= 0; i
< nsds_rings
; i
++) {
338 sds_ring
= &recv_ctx
->sds_rings
[i
];
340 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
341 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
342 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
345 phys_addr
= hostrq_phys_addr
;
346 memset(&cmd
, 0, sizeof(cmd
));
347 cmd
.req
.arg1
= (u32
)(phys_addr
>> 32);
348 cmd
.req
.arg2
= (u32
)(phys_addr
& 0xffffffff);
349 cmd
.req
.arg3
= rq_size
;
350 cmd
.req
.cmd
= NX_CDRP_CMD_CREATE_RX_CTX
;
351 err
= netxen_issue_cmd(adapter
, &cmd
);
354 "Failed to create rx ctx in firmware%d\n", err
);
359 prsp_rds
= ((nx_cardrsp_rds_ring_t
*)
360 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
362 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
363 rds_ring
= &recv_ctx
->rds_rings
[i
];
365 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
366 rds_ring
->crb_rcv_producer
= netxen_get_ioaddr(adapter
,
367 NETXEN_NIC_REG(reg
- 0x200));
370 prsp_sds
= ((nx_cardrsp_sds_ring_t
*)
371 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
373 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
374 sds_ring
= &recv_ctx
->sds_rings
[i
];
376 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
377 sds_ring
->crb_sts_consumer
= netxen_get_ioaddr(adapter
,
378 NETXEN_NIC_REG(reg
- 0x200));
380 reg
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
381 sds_ring
->crb_intr_mask
= netxen_get_ioaddr(adapter
,
382 NETXEN_NIC_REG(reg
- 0x200));
385 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
386 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
387 recv_ctx
->virt_port
= prsp
->virt_port
;
390 pci_free_consistent(adapter
->pdev
, rsp_size
, prsp
, cardrsp_phys_addr
);
392 pci_free_consistent(adapter
->pdev
, rq_size
, prq
, hostrq_phys_addr
);
397 nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter
*adapter
)
399 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
400 struct netxen_cmd_args cmd
;
402 memset(&cmd
, 0, sizeof(cmd
));
403 cmd
.req
.arg1
= recv_ctx
->context_id
;
404 cmd
.req
.arg2
= NX_DESTROY_CTX_RESET
;
406 cmd
.req
.cmd
= NX_CDRP_CMD_DESTROY_RX_CTX
;
408 if (netxen_issue_cmd(adapter
, &cmd
)) {
410 "%s: Failed to destroy rx ctx in firmware\n",
411 netxen_nic_driver_name
);
416 nx_fw_cmd_create_tx_ctx(struct netxen_adapter
*adapter
)
418 nx_hostrq_tx_ctx_t
*prq
;
419 nx_hostrq_cds_ring_t
*prq_cds
;
420 nx_cardrsp_tx_ctx_t
*prsp
;
421 void *rq_addr
, *rsp_addr
;
422 size_t rq_size
, rsp_size
;
425 u64 offset
, phys_addr
;
426 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
427 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
428 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
429 struct netxen_cmd_args cmd
;
431 rq_size
= SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t
);
432 rq_addr
= pci_alloc_consistent(adapter
->pdev
,
433 rq_size
, &rq_phys_addr
);
437 rsp_size
= SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t
);
438 rsp_addr
= pci_alloc_consistent(adapter
->pdev
,
439 rsp_size
, &rsp_phys_addr
);
449 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
451 temp
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
| NX_CAP0_LSO
);
452 prq
->capabilities
[0] = cpu_to_le32(temp
);
454 prq
->host_int_crb_mode
=
455 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
457 prq
->interrupt_ctl
= 0;
460 prq
->dummy_dma_addr
= cpu_to_le64(adapter
->dummy_dma
.phys_addr
);
462 offset
= recv_ctx
->phys_addr
+ sizeof(struct netxen_ring_ctx
);
463 prq
->cmd_cons_dma_addr
= cpu_to_le64(offset
);
465 prq_cds
= &prq
->cds_ring
;
467 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
468 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
470 phys_addr
= rq_phys_addr
;
471 memset(&cmd
, 0, sizeof(cmd
));
472 cmd
.req
.arg1
= (u32
)(phys_addr
>> 32);
473 cmd
.req
.arg2
= ((u32
)phys_addr
& 0xffffffff);
474 cmd
.req
.arg3
= rq_size
;
475 cmd
.req
.cmd
= NX_CDRP_CMD_CREATE_TX_CTX
;
476 err
= netxen_issue_cmd(adapter
, &cmd
);
478 if (err
== NX_RCODE_SUCCESS
) {
479 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
480 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
481 NETXEN_NIC_REG(temp
- 0x200));
484 le32_to_cpu(prsp
->host_ctx_state
);
486 adapter
->tx_context_id
=
487 le16_to_cpu(prsp
->context_id
);
490 "Failed to create tx ctx in firmware%d\n", err
);
494 pci_free_consistent(adapter
->pdev
, rsp_size
, rsp_addr
, rsp_phys_addr
);
497 pci_free_consistent(adapter
->pdev
, rq_size
, rq_addr
, rq_phys_addr
);
503 nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter
*adapter
)
505 struct netxen_cmd_args cmd
;
507 memset(&cmd
, 0, sizeof(cmd
));
508 cmd
.req
.arg1
= adapter
->tx_context_id
;
509 cmd
.req
.arg2
= NX_DESTROY_CTX_RESET
;
511 cmd
.req
.cmd
= NX_CDRP_CMD_DESTROY_TX_CTX
;
512 if (netxen_issue_cmd(adapter
, &cmd
)) {
514 "%s: Failed to destroy tx ctx in firmware\n",
515 netxen_nic_driver_name
);
520 nx_fw_cmd_query_phy(struct netxen_adapter
*adapter
, u32 reg
, u32
*val
)
523 struct netxen_cmd_args cmd
;
525 memset(&cmd
, 0, sizeof(cmd
));
529 cmd
.req
.cmd
= NX_CDRP_CMD_READ_PHY
;
531 rcode
= netxen_issue_cmd(adapter
, &cmd
);
532 if (rcode
!= NX_RCODE_SUCCESS
)
543 nx_fw_cmd_set_phy(struct netxen_adapter
*adapter
, u32 reg
, u32 val
)
546 struct netxen_cmd_args cmd
;
548 memset(&cmd
, 0, sizeof(cmd
));
552 cmd
.req
.cmd
= NX_CDRP_CMD_WRITE_PHY
;
553 rcode
= netxen_issue_cmd(adapter
, &cmd
);
554 if (rcode
!= NX_RCODE_SUCCESS
)
560 static u64 ctx_addr_sig_regs
[][3] = {
561 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
562 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
563 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
564 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
567 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
568 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
569 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
571 #define lower32(x) ((u32)((x) & 0xffffffff))
572 #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
574 static struct netxen_recv_crb recv_crb_registers
[] = {
577 /* crb_rcv_producer: */
579 NETXEN_NIC_REG(0x100),
581 NETXEN_NIC_REG(0x110),
583 NETXEN_NIC_REG(0x120)
585 /* crb_sts_consumer: */
587 NETXEN_NIC_REG(0x138),
588 NETXEN_NIC_REG_2(0x000),
589 NETXEN_NIC_REG_2(0x004),
590 NETXEN_NIC_REG_2(0x008),
595 NETXEN_NIC_REG_2(0x044),
596 NETXEN_NIC_REG_2(0x048),
597 NETXEN_NIC_REG_2(0x04c),
602 /* crb_rcv_producer: */
604 NETXEN_NIC_REG(0x144),
606 NETXEN_NIC_REG(0x154),
608 NETXEN_NIC_REG(0x164)
610 /* crb_sts_consumer: */
612 NETXEN_NIC_REG(0x17c),
613 NETXEN_NIC_REG_2(0x020),
614 NETXEN_NIC_REG_2(0x024),
615 NETXEN_NIC_REG_2(0x028),
620 NETXEN_NIC_REG_2(0x064),
621 NETXEN_NIC_REG_2(0x068),
622 NETXEN_NIC_REG_2(0x06c),
627 /* crb_rcv_producer: */
629 NETXEN_NIC_REG(0x1d8),
631 NETXEN_NIC_REG(0x1f8),
633 NETXEN_NIC_REG(0x208)
635 /* crb_sts_consumer: */
637 NETXEN_NIC_REG(0x220),
638 NETXEN_NIC_REG_2(0x03c),
639 NETXEN_NIC_REG_2(0x03c),
640 NETXEN_NIC_REG_2(0x03c),
645 NETXEN_NIC_REG_2(0x03c),
646 NETXEN_NIC_REG_2(0x03c),
647 NETXEN_NIC_REG_2(0x03c),
652 /* crb_rcv_producer: */
654 NETXEN_NIC_REG(0x22c),
656 NETXEN_NIC_REG(0x23c),
658 NETXEN_NIC_REG(0x24c)
660 /* crb_sts_consumer: */
662 NETXEN_NIC_REG(0x264),
663 NETXEN_NIC_REG_2(0x03c),
664 NETXEN_NIC_REG_2(0x03c),
665 NETXEN_NIC_REG_2(0x03c),
670 NETXEN_NIC_REG_2(0x03c),
671 NETXEN_NIC_REG_2(0x03c),
672 NETXEN_NIC_REG_2(0x03c),
678 netxen_init_old_ctx(struct netxen_adapter
*adapter
)
680 struct netxen_recv_context
*recv_ctx
;
681 struct nx_host_rds_ring
*rds_ring
;
682 struct nx_host_sds_ring
*sds_ring
;
683 struct nx_host_tx_ring
*tx_ring
;
685 int port
= adapter
->portnum
;
686 struct netxen_ring_ctx
*hwctx
;
689 tx_ring
= adapter
->tx_ring
;
690 recv_ctx
= &adapter
->recv_ctx
;
691 hwctx
= recv_ctx
->hwctx
;
693 hwctx
->cmd_ring_addr
= cpu_to_le64(tx_ring
->phys_addr
);
694 hwctx
->cmd_ring_size
= cpu_to_le32(tx_ring
->num_desc
);
697 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
698 rds_ring
= &recv_ctx
->rds_rings
[ring
];
700 hwctx
->rcv_rings
[ring
].addr
=
701 cpu_to_le64(rds_ring
->phys_addr
);
702 hwctx
->rcv_rings
[ring
].size
=
703 cpu_to_le32(rds_ring
->num_desc
);
706 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
707 sds_ring
= &recv_ctx
->sds_rings
[ring
];
710 hwctx
->sts_ring_addr
= cpu_to_le64(sds_ring
->phys_addr
);
711 hwctx
->sts_ring_size
= cpu_to_le32(sds_ring
->num_desc
);
713 hwctx
->sts_rings
[ring
].addr
= cpu_to_le64(sds_ring
->phys_addr
);
714 hwctx
->sts_rings
[ring
].size
= cpu_to_le32(sds_ring
->num_desc
);
715 hwctx
->sts_rings
[ring
].msi_index
= cpu_to_le16(ring
);
717 hwctx
->sts_ring_count
= cpu_to_le32(adapter
->max_sds_rings
);
719 signature
= (adapter
->max_sds_rings
> 1) ?
720 NETXEN_CTX_SIGNATURE_V2
: NETXEN_CTX_SIGNATURE
;
722 NXWR32(adapter
, CRB_CTX_ADDR_REG_LO(port
),
723 lower32(recv_ctx
->phys_addr
));
724 NXWR32(adapter
, CRB_CTX_ADDR_REG_HI(port
),
725 upper32(recv_ctx
->phys_addr
));
726 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
731 int netxen_alloc_hw_resources(struct netxen_adapter
*adapter
)
736 struct netxen_recv_context
*recv_ctx
;
737 struct nx_host_rds_ring
*rds_ring
;
738 struct nx_host_sds_ring
*sds_ring
;
739 struct nx_host_tx_ring
*tx_ring
;
741 struct pci_dev
*pdev
= adapter
->pdev
;
742 struct net_device
*netdev
= adapter
->netdev
;
743 int port
= adapter
->portnum
;
745 recv_ctx
= &adapter
->recv_ctx
;
746 tx_ring
= adapter
->tx_ring
;
748 addr
= pci_alloc_consistent(pdev
,
749 sizeof(struct netxen_ring_ctx
) + sizeof(uint32_t),
750 &recv_ctx
->phys_addr
);
752 dev_err(&pdev
->dev
, "failed to allocate hw context\n");
756 recv_ctx
->hwctx
= addr
;
757 recv_ctx
->hwctx
->ctx_id
= cpu_to_le32(port
);
758 recv_ctx
->hwctx
->cmd_consumer_offset
=
759 cpu_to_le64(recv_ctx
->phys_addr
+
760 sizeof(struct netxen_ring_ctx
));
761 tx_ring
->hw_consumer
=
762 (__le32
*)(((char *)addr
) + sizeof(struct netxen_ring_ctx
));
765 addr
= pci_alloc_consistent(pdev
, TX_DESC_RINGSIZE(tx_ring
),
766 &tx_ring
->phys_addr
);
769 dev_err(&pdev
->dev
, "%s: failed to allocate tx desc ring\n",
775 tx_ring
->desc_head
= addr
;
777 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
778 rds_ring
= &recv_ctx
->rds_rings
[ring
];
779 addr
= pci_alloc_consistent(adapter
->pdev
,
780 RCV_DESC_RINGSIZE(rds_ring
),
781 &rds_ring
->phys_addr
);
784 "%s: failed to allocate rds ring [%d]\n",
789 rds_ring
->desc_head
= addr
;
791 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
792 rds_ring
->crb_rcv_producer
=
793 netxen_get_ioaddr(adapter
,
794 recv_crb_registers
[port
].crb_rcv_producer
[ring
]);
797 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
798 sds_ring
= &recv_ctx
->sds_rings
[ring
];
800 addr
= pci_alloc_consistent(adapter
->pdev
,
801 STATUS_DESC_RINGSIZE(sds_ring
),
802 &sds_ring
->phys_addr
);
805 "%s: failed to allocate sds ring [%d]\n",
810 sds_ring
->desc_head
= addr
;
812 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
813 sds_ring
->crb_sts_consumer
=
814 netxen_get_ioaddr(adapter
,
815 recv_crb_registers
[port
].crb_sts_consumer
[ring
]);
817 sds_ring
->crb_intr_mask
=
818 netxen_get_ioaddr(adapter
,
819 recv_crb_registers
[port
].sw_int_mask
[ring
]);
824 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
825 if (test_and_set_bit(__NX_FW_ATTACHED
, &adapter
->state
))
827 err
= nx_fw_cmd_create_rx_ctx(adapter
);
830 err
= nx_fw_cmd_create_tx_ctx(adapter
);
834 err
= netxen_init_old_ctx(adapter
);
843 netxen_free_hw_resources(adapter
);
847 void netxen_free_hw_resources(struct netxen_adapter
*adapter
)
849 struct netxen_recv_context
*recv_ctx
;
850 struct nx_host_rds_ring
*rds_ring
;
851 struct nx_host_sds_ring
*sds_ring
;
852 struct nx_host_tx_ring
*tx_ring
;
855 int port
= adapter
->portnum
;
857 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
858 if (!test_and_clear_bit(__NX_FW_ATTACHED
, &adapter
->state
))
861 nx_fw_cmd_destroy_rx_ctx(adapter
);
862 nx_fw_cmd_destroy_tx_ctx(adapter
);
864 netxen_api_lock(adapter
);
865 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
866 NETXEN_CTX_D3_RESET
| port
);
867 netxen_api_unlock(adapter
);
870 /* Allow dma queues to drain after context reset */
874 recv_ctx
= &adapter
->recv_ctx
;
876 if (recv_ctx
->hwctx
!= NULL
) {
877 pci_free_consistent(adapter
->pdev
,
878 sizeof(struct netxen_ring_ctx
) +
881 recv_ctx
->phys_addr
);
882 recv_ctx
->hwctx
= NULL
;
885 tx_ring
= adapter
->tx_ring
;
886 if (tx_ring
->desc_head
!= NULL
) {
887 pci_free_consistent(adapter
->pdev
,
888 TX_DESC_RINGSIZE(tx_ring
),
889 tx_ring
->desc_head
, tx_ring
->phys_addr
);
890 tx_ring
->desc_head
= NULL
;
893 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
894 rds_ring
= &recv_ctx
->rds_rings
[ring
];
896 if (rds_ring
->desc_head
!= NULL
) {
897 pci_free_consistent(adapter
->pdev
,
898 RCV_DESC_RINGSIZE(rds_ring
),
900 rds_ring
->phys_addr
);
901 rds_ring
->desc_head
= NULL
;
905 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
906 sds_ring
= &recv_ctx
->sds_rings
[ring
];
908 if (sds_ring
->desc_head
!= NULL
) {
909 pci_free_consistent(adapter
->pdev
,
910 STATUS_DESC_RINGSIZE(sds_ring
),
912 sds_ring
->phys_addr
);
913 sds_ring
->desc_head
= NULL
;