2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * The full GNU General Public License is included in this distribution
20 * in the file called "COPYING".
24 #include "netxen_nic_hw.h"
25 #include "netxen_nic.h"
27 #define NXHAL_VERSION 1
30 netxen_poll_rsp(struct netxen_adapter
*adapter
)
32 u32 rsp
= NX_CDRP_RSP_OK
;
36 /* give atleast 1ms for firmware to respond */
39 if (++timeout
> NX_OS_CRB_RETRY_COUNT
)
40 return NX_CDRP_RSP_TIMEOUT
;
42 rsp
= NXRD32(adapter
, NX_CDRP_CRB_OFFSET
);
43 } while (!NX_CDRP_IS_RSP(rsp
));
49 netxen_issue_cmd(struct netxen_adapter
*adapter
, struct netxen_cmd_args
*cmd
)
53 u32 rcode
= NX_RCODE_SUCCESS
;
55 signature
= NX_CDRP_SIGNATURE_MAKE(adapter
->ahw
.pci_func
,
57 /* Acquire semaphore before accessing CRB */
58 if (netxen_api_lock(adapter
))
59 return NX_RCODE_TIMEOUT
;
61 NXWR32(adapter
, NX_SIGN_CRB_OFFSET
, signature
);
63 NXWR32(adapter
, NX_ARG1_CRB_OFFSET
, cmd
->req
.arg1
);
65 NXWR32(adapter
, NX_ARG2_CRB_OFFSET
, cmd
->req
.arg2
);
67 NXWR32(adapter
, NX_ARG3_CRB_OFFSET
, cmd
->req
.arg3
);
69 NXWR32(adapter
, NX_CDRP_CRB_OFFSET
, NX_CDRP_FORM_CMD(cmd
->req
.cmd
));
71 rsp
= netxen_poll_rsp(adapter
);
73 if (rsp
== NX_CDRP_RSP_TIMEOUT
) {
74 printk(KERN_ERR
"%s: card response timeout.\n",
75 netxen_nic_driver_name
);
77 rcode
= NX_RCODE_TIMEOUT
;
78 } else if (rsp
== NX_CDRP_RSP_FAIL
) {
79 rcode
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
81 printk(KERN_ERR
"%s: failed card response code:0x%x\n",
82 netxen_nic_driver_name
, rcode
);
83 } else if (rsp
== NX_CDRP_RSP_OK
) {
84 cmd
->rsp
.cmd
= NX_RCODE_SUCCESS
;
86 cmd
->rsp
.arg2
= NXRD32(adapter
, NX_ARG2_CRB_OFFSET
);
88 cmd
->rsp
.arg3
= NXRD32(adapter
, NX_ARG3_CRB_OFFSET
);
92 cmd
->rsp
.arg1
= NXRD32(adapter
, NX_ARG1_CRB_OFFSET
);
93 /* Release semaphore */
94 netxen_api_unlock(adapter
);
100 netxen_get_minidump_template_size(struct netxen_adapter
*adapter
)
102 struct netxen_cmd_args cmd
;
103 memset(&cmd
, 0, sizeof(cmd
));
104 cmd
.req
.cmd
= NX_CDRP_CMD_TEMP_SIZE
;
105 memset(&cmd
.rsp
, 1, sizeof(struct _cdrp_cmd
));
106 netxen_issue_cmd(adapter
, &cmd
);
107 if (cmd
.rsp
.cmd
!= NX_RCODE_SUCCESS
) {
108 dev_info(&adapter
->pdev
->dev
,
109 "Can't get template size %d\n", cmd
.rsp
.cmd
);
112 adapter
->mdump
.md_template_size
= cmd
.rsp
.arg2
;
113 adapter
->mdump
.md_template_ver
= cmd
.rsp
.arg3
;
118 netxen_get_minidump_template(struct netxen_adapter
*adapter
)
120 dma_addr_t md_template_addr
;
123 struct netxen_cmd_args cmd
;
124 size
= adapter
->mdump
.md_template_size
;
127 dev_err(&adapter
->pdev
->dev
, "Can not capture Minidump "
128 "template. Invalid template size.\n");
129 return NX_RCODE_INVALID_ARGS
;
132 addr
= pci_zalloc_consistent(adapter
->pdev
, size
, &md_template_addr
);
134 dev_err(&adapter
->pdev
->dev
, "Unable to allocate dmable memory for template.\n");
138 memset(&cmd
, 0, sizeof(cmd
));
139 memset(&cmd
.rsp
, 1, sizeof(struct _cdrp_cmd
));
140 cmd
.req
.cmd
= NX_CDRP_CMD_GET_TEMP_HDR
;
141 cmd
.req
.arg1
= LSD(md_template_addr
);
142 cmd
.req
.arg2
= MSD(md_template_addr
);
143 cmd
.req
.arg3
|= size
;
144 netxen_issue_cmd(adapter
, &cmd
);
146 if ((cmd
.rsp
.cmd
== NX_RCODE_SUCCESS
) && (size
== cmd
.rsp
.arg2
)) {
147 memcpy(adapter
->mdump
.md_template
, addr
, size
);
149 dev_err(&adapter
->pdev
->dev
, "Failed to get minidump template, err_code : %d, requested_size : %d, actual_size : %d\n",
150 cmd
.rsp
.cmd
, size
, cmd
.rsp
.arg2
);
152 pci_free_consistent(adapter
->pdev
, size
, addr
, md_template_addr
);
157 netxen_check_template_checksum(struct netxen_adapter
*adapter
)
160 u32
*buff
= adapter
->mdump
.md_template
;
161 int count
= adapter
->mdump
.md_template_size
/sizeof(uint32_t) ;
166 sum
= (sum
& 0xFFFFFFFF) + (sum
>> 32) ;
172 netxen_setup_minidump(struct netxen_adapter
*adapter
)
175 u32
*template, *tmp_buf
;
176 err
= netxen_get_minidump_template_size(adapter
);
178 adapter
->mdump
.fw_supports_md
= 0;
179 if ((err
== NX_RCODE_CMD_INVALID
) ||
180 (err
== NX_RCODE_CMD_NOT_IMPL
)) {
181 dev_info(&adapter
->pdev
->dev
,
182 "Flashed firmware version does not support minidump, minimum version required is [ %u.%u.%u ]\n",
183 NX_MD_SUPPORT_MAJOR
, NX_MD_SUPPORT_MINOR
,
184 NX_MD_SUPPORT_SUBVERSION
);
189 if (!adapter
->mdump
.md_template_size
) {
190 dev_err(&adapter
->pdev
->dev
, "Error : Invalid template size "
191 ",should be non-zero.\n");
194 adapter
->mdump
.md_template
=
195 kmalloc(adapter
->mdump
.md_template_size
, GFP_KERNEL
);
197 if (!adapter
->mdump
.md_template
)
200 err
= netxen_get_minidump_template(adapter
);
202 if (err
== NX_RCODE_CMD_NOT_IMPL
)
203 adapter
->mdump
.fw_supports_md
= 0;
207 if (netxen_check_template_checksum(adapter
)) {
208 dev_err(&adapter
->pdev
->dev
, "Minidump template checksum Error\n");
213 adapter
->mdump
.md_capture_mask
= NX_DUMP_MASK_DEF
;
214 tmp_buf
= (u32
*) adapter
->mdump
.md_template
;
215 template = (u32
*) adapter
->mdump
.md_template
;
216 for (i
= 0; i
< adapter
->mdump
.md_template_size
/sizeof(u32
); i
++)
217 *template++ = __le32_to_cpu(*tmp_buf
++);
218 adapter
->mdump
.md_capture_buff
= NULL
;
219 adapter
->mdump
.fw_supports_md
= 1;
220 adapter
->mdump
.md_enabled
= 0;
225 kfree(adapter
->mdump
.md_template
);
226 adapter
->mdump
.md_template
= NULL
;
232 nx_fw_cmd_set_mtu(struct netxen_adapter
*adapter
, int mtu
)
234 u32 rcode
= NX_RCODE_SUCCESS
;
235 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
236 struct netxen_cmd_args cmd
;
238 memset(&cmd
, 0, sizeof(cmd
));
239 cmd
.req
.cmd
= NX_CDRP_CMD_SET_MTU
;
240 cmd
.req
.arg1
= recv_ctx
->context_id
;
244 if (recv_ctx
->state
== NX_HOST_CTX_STATE_ACTIVE
)
245 rcode
= netxen_issue_cmd(adapter
, &cmd
);
247 if (rcode
!= NX_RCODE_SUCCESS
)
254 nx_fw_cmd_set_gbe_port(struct netxen_adapter
*adapter
,
255 u32 speed
, u32 duplex
, u32 autoneg
)
257 struct netxen_cmd_args cmd
;
259 memset(&cmd
, 0, sizeof(cmd
));
260 cmd
.req
.cmd
= NX_CDRP_CMD_CONFIG_GBE_PORT
;
261 cmd
.req
.arg1
= speed
;
262 cmd
.req
.arg2
= duplex
;
263 cmd
.req
.arg3
= autoneg
;
264 return netxen_issue_cmd(adapter
, &cmd
);
268 nx_fw_cmd_create_rx_ctx(struct netxen_adapter
*adapter
)
271 nx_hostrq_rx_ctx_t
*prq
;
272 nx_cardrsp_rx_ctx_t
*prsp
;
273 nx_hostrq_rds_ring_t
*prq_rds
;
274 nx_hostrq_sds_ring_t
*prq_sds
;
275 nx_cardrsp_rds_ring_t
*prsp_rds
;
276 nx_cardrsp_sds_ring_t
*prsp_sds
;
277 struct nx_host_rds_ring
*rds_ring
;
278 struct nx_host_sds_ring
*sds_ring
;
279 struct netxen_cmd_args cmd
;
281 dma_addr_t hostrq_phys_addr
, cardrsp_phys_addr
;
284 int i
, nrds_rings
, nsds_rings
;
285 size_t rq_size
, rsp_size
;
290 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
292 nrds_rings
= adapter
->max_rds_rings
;
293 nsds_rings
= adapter
->max_sds_rings
;
296 SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t
, nrds_rings
, nsds_rings
);
298 SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t
, nrds_rings
, nsds_rings
);
300 addr
= pci_alloc_consistent(adapter
->pdev
,
301 rq_size
, &hostrq_phys_addr
);
306 addr
= pci_alloc_consistent(adapter
->pdev
,
307 rsp_size
, &cardrsp_phys_addr
);
314 prq
->host_rsp_dma_addr
= cpu_to_le64(cardrsp_phys_addr
);
316 cap
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
);
317 cap
|= (NX_CAP0_JUMBO_CONTIGUOUS
| NX_CAP0_LRO_CONTIGUOUS
);
319 if (adapter
->flags
& NETXEN_FW_MSS_CAP
)
320 cap
|= NX_CAP0_HW_LRO_MSS
;
322 prq
->capabilities
[0] = cpu_to_le32(cap
);
323 prq
->host_int_crb_mode
=
324 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
325 prq
->host_rds_crb_mode
=
326 cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE
);
328 prq
->num_rds_rings
= cpu_to_le16(nrds_rings
);
329 prq
->num_sds_rings
= cpu_to_le16(nsds_rings
);
330 prq
->rds_ring_offset
= cpu_to_le32(0);
332 val
= le32_to_cpu(prq
->rds_ring_offset
) +
333 (sizeof(nx_hostrq_rds_ring_t
) * nrds_rings
);
334 prq
->sds_ring_offset
= cpu_to_le32(val
);
336 prq_rds
= (nx_hostrq_rds_ring_t
*)(prq
->data
+
337 le32_to_cpu(prq
->rds_ring_offset
));
339 for (i
= 0; i
< nrds_rings
; i
++) {
341 rds_ring
= &recv_ctx
->rds_rings
[i
];
343 prq_rds
[i
].host_phys_addr
= cpu_to_le64(rds_ring
->phys_addr
);
344 prq_rds
[i
].ring_size
= cpu_to_le32(rds_ring
->num_desc
);
345 prq_rds
[i
].ring_kind
= cpu_to_le32(i
);
346 prq_rds
[i
].buff_size
= cpu_to_le64(rds_ring
->dma_size
);
349 prq_sds
= (nx_hostrq_sds_ring_t
*)(prq
->data
+
350 le32_to_cpu(prq
->sds_ring_offset
));
352 for (i
= 0; i
< nsds_rings
; i
++) {
354 sds_ring
= &recv_ctx
->sds_rings
[i
];
356 prq_sds
[i
].host_phys_addr
= cpu_to_le64(sds_ring
->phys_addr
);
357 prq_sds
[i
].ring_size
= cpu_to_le32(sds_ring
->num_desc
);
358 prq_sds
[i
].msi_index
= cpu_to_le16(i
);
361 phys_addr
= hostrq_phys_addr
;
362 memset(&cmd
, 0, sizeof(cmd
));
363 cmd
.req
.arg1
= (u32
)(phys_addr
>> 32);
364 cmd
.req
.arg2
= (u32
)(phys_addr
& 0xffffffff);
365 cmd
.req
.arg3
= rq_size
;
366 cmd
.req
.cmd
= NX_CDRP_CMD_CREATE_RX_CTX
;
367 err
= netxen_issue_cmd(adapter
, &cmd
);
370 "Failed to create rx ctx in firmware%d\n", err
);
375 prsp_rds
= ((nx_cardrsp_rds_ring_t
*)
376 &prsp
->data
[le32_to_cpu(prsp
->rds_ring_offset
)]);
378 for (i
= 0; i
< le16_to_cpu(prsp
->num_rds_rings
); i
++) {
379 rds_ring
= &recv_ctx
->rds_rings
[i
];
381 reg
= le32_to_cpu(prsp_rds
[i
].host_producer_crb
);
382 rds_ring
->crb_rcv_producer
= netxen_get_ioaddr(adapter
,
383 NETXEN_NIC_REG(reg
- 0x200));
386 prsp_sds
= ((nx_cardrsp_sds_ring_t
*)
387 &prsp
->data
[le32_to_cpu(prsp
->sds_ring_offset
)]);
389 for (i
= 0; i
< le16_to_cpu(prsp
->num_sds_rings
); i
++) {
390 sds_ring
= &recv_ctx
->sds_rings
[i
];
392 reg
= le32_to_cpu(prsp_sds
[i
].host_consumer_crb
);
393 sds_ring
->crb_sts_consumer
= netxen_get_ioaddr(adapter
,
394 NETXEN_NIC_REG(reg
- 0x200));
396 reg
= le32_to_cpu(prsp_sds
[i
].interrupt_crb
);
397 sds_ring
->crb_intr_mask
= netxen_get_ioaddr(adapter
,
398 NETXEN_NIC_REG(reg
- 0x200));
401 recv_ctx
->state
= le32_to_cpu(prsp
->host_ctx_state
);
402 recv_ctx
->context_id
= le16_to_cpu(prsp
->context_id
);
403 recv_ctx
->virt_port
= prsp
->virt_port
;
406 pci_free_consistent(adapter
->pdev
, rsp_size
, prsp
, cardrsp_phys_addr
);
408 pci_free_consistent(adapter
->pdev
, rq_size
, prq
, hostrq_phys_addr
);
413 nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter
*adapter
)
415 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
416 struct netxen_cmd_args cmd
;
418 memset(&cmd
, 0, sizeof(cmd
));
419 cmd
.req
.arg1
= recv_ctx
->context_id
;
420 cmd
.req
.arg2
= NX_DESTROY_CTX_RESET
;
422 cmd
.req
.cmd
= NX_CDRP_CMD_DESTROY_RX_CTX
;
424 if (netxen_issue_cmd(adapter
, &cmd
)) {
426 "%s: Failed to destroy rx ctx in firmware\n",
427 netxen_nic_driver_name
);
432 nx_fw_cmd_create_tx_ctx(struct netxen_adapter
*adapter
)
434 nx_hostrq_tx_ctx_t
*prq
;
435 nx_hostrq_cds_ring_t
*prq_cds
;
436 nx_cardrsp_tx_ctx_t
*prsp
;
437 void *rq_addr
, *rsp_addr
;
438 size_t rq_size
, rsp_size
;
441 u64 offset
, phys_addr
;
442 dma_addr_t rq_phys_addr
, rsp_phys_addr
;
443 struct nx_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
444 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
445 struct netxen_cmd_args cmd
;
447 rq_size
= SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t
);
448 rq_addr
= pci_alloc_consistent(adapter
->pdev
,
449 rq_size
, &rq_phys_addr
);
453 rsp_size
= SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t
);
454 rsp_addr
= pci_alloc_consistent(adapter
->pdev
,
455 rsp_size
, &rsp_phys_addr
);
461 memset(rq_addr
, 0, rq_size
);
464 memset(rsp_addr
, 0, rsp_size
);
467 prq
->host_rsp_dma_addr
= cpu_to_le64(rsp_phys_addr
);
469 temp
= (NX_CAP0_LEGACY_CONTEXT
| NX_CAP0_LEGACY_MN
| NX_CAP0_LSO
);
470 prq
->capabilities
[0] = cpu_to_le32(temp
);
472 prq
->host_int_crb_mode
=
473 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED
);
475 prq
->interrupt_ctl
= 0;
478 prq
->dummy_dma_addr
= cpu_to_le64(adapter
->dummy_dma
.phys_addr
);
480 offset
= recv_ctx
->phys_addr
+ sizeof(struct netxen_ring_ctx
);
481 prq
->cmd_cons_dma_addr
= cpu_to_le64(offset
);
483 prq_cds
= &prq
->cds_ring
;
485 prq_cds
->host_phys_addr
= cpu_to_le64(tx_ring
->phys_addr
);
486 prq_cds
->ring_size
= cpu_to_le32(tx_ring
->num_desc
);
488 phys_addr
= rq_phys_addr
;
489 memset(&cmd
, 0, sizeof(cmd
));
490 cmd
.req
.arg1
= (u32
)(phys_addr
>> 32);
491 cmd
.req
.arg2
= ((u32
)phys_addr
& 0xffffffff);
492 cmd
.req
.arg3
= rq_size
;
493 cmd
.req
.cmd
= NX_CDRP_CMD_CREATE_TX_CTX
;
494 err
= netxen_issue_cmd(adapter
, &cmd
);
496 if (err
== NX_RCODE_SUCCESS
) {
497 temp
= le32_to_cpu(prsp
->cds_ring
.host_producer_crb
);
498 tx_ring
->crb_cmd_producer
= netxen_get_ioaddr(adapter
,
499 NETXEN_NIC_REG(temp
- 0x200));
502 le32_to_cpu(prsp
->host_ctx_state
);
504 adapter
->tx_context_id
=
505 le16_to_cpu(prsp
->context_id
);
508 "Failed to create tx ctx in firmware%d\n", err
);
512 pci_free_consistent(adapter
->pdev
, rsp_size
, rsp_addr
, rsp_phys_addr
);
515 pci_free_consistent(adapter
->pdev
, rq_size
, rq_addr
, rq_phys_addr
);
521 nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter
*adapter
)
523 struct netxen_cmd_args cmd
;
525 memset(&cmd
, 0, sizeof(cmd
));
526 cmd
.req
.arg1
= adapter
->tx_context_id
;
527 cmd
.req
.arg2
= NX_DESTROY_CTX_RESET
;
529 cmd
.req
.cmd
= NX_CDRP_CMD_DESTROY_TX_CTX
;
530 if (netxen_issue_cmd(adapter
, &cmd
)) {
532 "%s: Failed to destroy tx ctx in firmware\n",
533 netxen_nic_driver_name
);
538 nx_fw_cmd_query_phy(struct netxen_adapter
*adapter
, u32 reg
, u32
*val
)
541 struct netxen_cmd_args cmd
;
543 memset(&cmd
, 0, sizeof(cmd
));
547 cmd
.req
.cmd
= NX_CDRP_CMD_READ_PHY
;
549 rcode
= netxen_issue_cmd(adapter
, &cmd
);
550 if (rcode
!= NX_RCODE_SUCCESS
)
561 nx_fw_cmd_set_phy(struct netxen_adapter
*adapter
, u32 reg
, u32 val
)
564 struct netxen_cmd_args cmd
;
566 memset(&cmd
, 0, sizeof(cmd
));
570 cmd
.req
.cmd
= NX_CDRP_CMD_WRITE_PHY
;
571 rcode
= netxen_issue_cmd(adapter
, &cmd
);
572 if (rcode
!= NX_RCODE_SUCCESS
)
578 static u64 ctx_addr_sig_regs
[][3] = {
579 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
580 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
581 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
582 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
585 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
586 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
587 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
589 #define lower32(x) ((u32)((x) & 0xffffffff))
590 #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
592 static struct netxen_recv_crb recv_crb_registers
[] = {
595 /* crb_rcv_producer: */
597 NETXEN_NIC_REG(0x100),
599 NETXEN_NIC_REG(0x110),
601 NETXEN_NIC_REG(0x120)
603 /* crb_sts_consumer: */
605 NETXEN_NIC_REG(0x138),
606 NETXEN_NIC_REG_2(0x000),
607 NETXEN_NIC_REG_2(0x004),
608 NETXEN_NIC_REG_2(0x008),
613 NETXEN_NIC_REG_2(0x044),
614 NETXEN_NIC_REG_2(0x048),
615 NETXEN_NIC_REG_2(0x04c),
620 /* crb_rcv_producer: */
622 NETXEN_NIC_REG(0x144),
624 NETXEN_NIC_REG(0x154),
626 NETXEN_NIC_REG(0x164)
628 /* crb_sts_consumer: */
630 NETXEN_NIC_REG(0x17c),
631 NETXEN_NIC_REG_2(0x020),
632 NETXEN_NIC_REG_2(0x024),
633 NETXEN_NIC_REG_2(0x028),
638 NETXEN_NIC_REG_2(0x064),
639 NETXEN_NIC_REG_2(0x068),
640 NETXEN_NIC_REG_2(0x06c),
645 /* crb_rcv_producer: */
647 NETXEN_NIC_REG(0x1d8),
649 NETXEN_NIC_REG(0x1f8),
651 NETXEN_NIC_REG(0x208)
653 /* crb_sts_consumer: */
655 NETXEN_NIC_REG(0x220),
656 NETXEN_NIC_REG_2(0x03c),
657 NETXEN_NIC_REG_2(0x03c),
658 NETXEN_NIC_REG_2(0x03c),
663 NETXEN_NIC_REG_2(0x03c),
664 NETXEN_NIC_REG_2(0x03c),
665 NETXEN_NIC_REG_2(0x03c),
670 /* crb_rcv_producer: */
672 NETXEN_NIC_REG(0x22c),
674 NETXEN_NIC_REG(0x23c),
676 NETXEN_NIC_REG(0x24c)
678 /* crb_sts_consumer: */
680 NETXEN_NIC_REG(0x264),
681 NETXEN_NIC_REG_2(0x03c),
682 NETXEN_NIC_REG_2(0x03c),
683 NETXEN_NIC_REG_2(0x03c),
688 NETXEN_NIC_REG_2(0x03c),
689 NETXEN_NIC_REG_2(0x03c),
690 NETXEN_NIC_REG_2(0x03c),
696 netxen_init_old_ctx(struct netxen_adapter
*adapter
)
698 struct netxen_recv_context
*recv_ctx
;
699 struct nx_host_rds_ring
*rds_ring
;
700 struct nx_host_sds_ring
*sds_ring
;
701 struct nx_host_tx_ring
*tx_ring
;
703 int port
= adapter
->portnum
;
704 struct netxen_ring_ctx
*hwctx
;
707 tx_ring
= adapter
->tx_ring
;
708 recv_ctx
= &adapter
->recv_ctx
;
709 hwctx
= recv_ctx
->hwctx
;
711 hwctx
->cmd_ring_addr
= cpu_to_le64(tx_ring
->phys_addr
);
712 hwctx
->cmd_ring_size
= cpu_to_le32(tx_ring
->num_desc
);
715 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
716 rds_ring
= &recv_ctx
->rds_rings
[ring
];
718 hwctx
->rcv_rings
[ring
].addr
=
719 cpu_to_le64(rds_ring
->phys_addr
);
720 hwctx
->rcv_rings
[ring
].size
=
721 cpu_to_le32(rds_ring
->num_desc
);
724 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
725 sds_ring
= &recv_ctx
->sds_rings
[ring
];
728 hwctx
->sts_ring_addr
= cpu_to_le64(sds_ring
->phys_addr
);
729 hwctx
->sts_ring_size
= cpu_to_le32(sds_ring
->num_desc
);
731 hwctx
->sts_rings
[ring
].addr
= cpu_to_le64(sds_ring
->phys_addr
);
732 hwctx
->sts_rings
[ring
].size
= cpu_to_le32(sds_ring
->num_desc
);
733 hwctx
->sts_rings
[ring
].msi_index
= cpu_to_le16(ring
);
735 hwctx
->sts_ring_count
= cpu_to_le32(adapter
->max_sds_rings
);
737 signature
= (adapter
->max_sds_rings
> 1) ?
738 NETXEN_CTX_SIGNATURE_V2
: NETXEN_CTX_SIGNATURE
;
740 NXWR32(adapter
, CRB_CTX_ADDR_REG_LO(port
),
741 lower32(recv_ctx
->phys_addr
));
742 NXWR32(adapter
, CRB_CTX_ADDR_REG_HI(port
),
743 upper32(recv_ctx
->phys_addr
));
744 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
749 int netxen_alloc_hw_resources(struct netxen_adapter
*adapter
)
754 struct netxen_recv_context
*recv_ctx
;
755 struct nx_host_rds_ring
*rds_ring
;
756 struct nx_host_sds_ring
*sds_ring
;
757 struct nx_host_tx_ring
*tx_ring
;
759 struct pci_dev
*pdev
= adapter
->pdev
;
760 struct net_device
*netdev
= adapter
->netdev
;
761 int port
= adapter
->portnum
;
763 recv_ctx
= &adapter
->recv_ctx
;
764 tx_ring
= adapter
->tx_ring
;
766 addr
= pci_alloc_consistent(pdev
,
767 sizeof(struct netxen_ring_ctx
) + sizeof(uint32_t),
768 &recv_ctx
->phys_addr
);
770 dev_err(&pdev
->dev
, "failed to allocate hw context\n");
774 memset(addr
, 0, sizeof(struct netxen_ring_ctx
));
775 recv_ctx
->hwctx
= addr
;
776 recv_ctx
->hwctx
->ctx_id
= cpu_to_le32(port
);
777 recv_ctx
->hwctx
->cmd_consumer_offset
=
778 cpu_to_le64(recv_ctx
->phys_addr
+
779 sizeof(struct netxen_ring_ctx
));
780 tx_ring
->hw_consumer
=
781 (__le32
*)(((char *)addr
) + sizeof(struct netxen_ring_ctx
));
784 addr
= pci_alloc_consistent(pdev
, TX_DESC_RINGSIZE(tx_ring
),
785 &tx_ring
->phys_addr
);
788 dev_err(&pdev
->dev
, "%s: failed to allocate tx desc ring\n",
794 tx_ring
->desc_head
= addr
;
796 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
797 rds_ring
= &recv_ctx
->rds_rings
[ring
];
798 addr
= pci_alloc_consistent(adapter
->pdev
,
799 RCV_DESC_RINGSIZE(rds_ring
),
800 &rds_ring
->phys_addr
);
803 "%s: failed to allocate rds ring [%d]\n",
808 rds_ring
->desc_head
= addr
;
810 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
811 rds_ring
->crb_rcv_producer
=
812 netxen_get_ioaddr(adapter
,
813 recv_crb_registers
[port
].crb_rcv_producer
[ring
]);
816 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
817 sds_ring
= &recv_ctx
->sds_rings
[ring
];
819 addr
= pci_alloc_consistent(adapter
->pdev
,
820 STATUS_DESC_RINGSIZE(sds_ring
),
821 &sds_ring
->phys_addr
);
824 "%s: failed to allocate sds ring [%d]\n",
829 sds_ring
->desc_head
= addr
;
831 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
832 sds_ring
->crb_sts_consumer
=
833 netxen_get_ioaddr(adapter
,
834 recv_crb_registers
[port
].crb_sts_consumer
[ring
]);
836 sds_ring
->crb_intr_mask
=
837 netxen_get_ioaddr(adapter
,
838 recv_crb_registers
[port
].sw_int_mask
[ring
]);
843 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
844 if (test_and_set_bit(__NX_FW_ATTACHED
, &adapter
->state
))
846 err
= nx_fw_cmd_create_rx_ctx(adapter
);
849 err
= nx_fw_cmd_create_tx_ctx(adapter
);
853 err
= netxen_init_old_ctx(adapter
);
862 netxen_free_hw_resources(adapter
);
866 void netxen_free_hw_resources(struct netxen_adapter
*adapter
)
868 struct netxen_recv_context
*recv_ctx
;
869 struct nx_host_rds_ring
*rds_ring
;
870 struct nx_host_sds_ring
*sds_ring
;
871 struct nx_host_tx_ring
*tx_ring
;
874 int port
= adapter
->portnum
;
876 if (!NX_IS_REVISION_P2(adapter
->ahw
.revision_id
)) {
877 if (!test_and_clear_bit(__NX_FW_ATTACHED
, &adapter
->state
))
880 nx_fw_cmd_destroy_rx_ctx(adapter
);
881 nx_fw_cmd_destroy_tx_ctx(adapter
);
883 netxen_api_lock(adapter
);
884 NXWR32(adapter
, CRB_CTX_SIGNATURE_REG(port
),
885 NETXEN_CTX_D3_RESET
| port
);
886 netxen_api_unlock(adapter
);
889 /* Allow dma queues to drain after context reset */
893 recv_ctx
= &adapter
->recv_ctx
;
895 if (recv_ctx
->hwctx
!= NULL
) {
896 pci_free_consistent(adapter
->pdev
,
897 sizeof(struct netxen_ring_ctx
) +
900 recv_ctx
->phys_addr
);
901 recv_ctx
->hwctx
= NULL
;
904 tx_ring
= adapter
->tx_ring
;
905 if (tx_ring
->desc_head
!= NULL
) {
906 pci_free_consistent(adapter
->pdev
,
907 TX_DESC_RINGSIZE(tx_ring
),
908 tx_ring
->desc_head
, tx_ring
->phys_addr
);
909 tx_ring
->desc_head
= NULL
;
912 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
913 rds_ring
= &recv_ctx
->rds_rings
[ring
];
915 if (rds_ring
->desc_head
!= NULL
) {
916 pci_free_consistent(adapter
->pdev
,
917 RCV_DESC_RINGSIZE(rds_ring
),
919 rds_ring
->phys_addr
);
920 rds_ring
->desc_head
= NULL
;
924 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
925 sds_ring
= &recv_ctx
->sds_rings
[ring
];
927 if (sds_ring
->desc_head
!= NULL
) {
928 pci_free_consistent(adapter
->pdev
,
929 STATUS_DESC_RINGSIZE(sds_ring
),
931 sds_ring
->phys_addr
);
932 sds_ring
->desc_head
= NULL
;