1d0ae6124SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2aa43c215SJeff Kirsher /*
3aa43c215SJeff Kirsher * Copyright (C) 2003 - 2009 NetXen, Inc.
4aa43c215SJeff Kirsher * Copyright (C) 2009 - QLogic Corporation.
5aa43c215SJeff Kirsher * All rights reserved.
6aa43c215SJeff Kirsher */
7aa43c215SJeff Kirsher
8aa43c215SJeff Kirsher #include "netxen_nic_hw.h"
9aa43c215SJeff Kirsher #include "netxen_nic.h"
10aa43c215SJeff Kirsher
11aa43c215SJeff Kirsher #define NXHAL_VERSION 1
12aa43c215SJeff Kirsher
13aa43c215SJeff Kirsher static u32
netxen_poll_rsp(struct netxen_adapter * adapter)14aa43c215SJeff Kirsher netxen_poll_rsp(struct netxen_adapter *adapter)
15aa43c215SJeff Kirsher {
16aa43c215SJeff Kirsher u32 rsp = NX_CDRP_RSP_OK;
17aa43c215SJeff Kirsher int timeout = 0;
18aa43c215SJeff Kirsher
19aa43c215SJeff Kirsher do {
20aa43c215SJeff Kirsher /* give atleast 1ms for firmware to respond */
21aa43c215SJeff Kirsher msleep(1);
22aa43c215SJeff Kirsher
23aa43c215SJeff Kirsher if (++timeout > NX_OS_CRB_RETRY_COUNT)
24aa43c215SJeff Kirsher return NX_CDRP_RSP_TIMEOUT;
25aa43c215SJeff Kirsher
26aa43c215SJeff Kirsher rsp = NXRD32(adapter, NX_CDRP_CRB_OFFSET);
27aa43c215SJeff Kirsher } while (!NX_CDRP_IS_RSP(rsp));
28aa43c215SJeff Kirsher
29aa43c215SJeff Kirsher return rsp;
30aa43c215SJeff Kirsher }
31aa43c215SJeff Kirsher
32aa43c215SJeff Kirsher static u32
netxen_issue_cmd(struct netxen_adapter * adapter,struct netxen_cmd_args * cmd)332dcd5d95SSritej Velaga netxen_issue_cmd(struct netxen_adapter *adapter, struct netxen_cmd_args *cmd)
34aa43c215SJeff Kirsher {
35aa43c215SJeff Kirsher u32 rsp;
36aa43c215SJeff Kirsher u32 signature = 0;
37aa43c215SJeff Kirsher u32 rcode = NX_RCODE_SUCCESS;
38aa43c215SJeff Kirsher
392dcd5d95SSritej Velaga signature = NX_CDRP_SIGNATURE_MAKE(adapter->ahw.pci_func,
402dcd5d95SSritej Velaga NXHAL_VERSION);
41aa43c215SJeff Kirsher /* Acquire semaphore before accessing CRB */
42aa43c215SJeff Kirsher if (netxen_api_lock(adapter))
43aa43c215SJeff Kirsher return NX_RCODE_TIMEOUT;
44aa43c215SJeff Kirsher
45aa43c215SJeff Kirsher NXWR32(adapter, NX_SIGN_CRB_OFFSET, signature);
46aa43c215SJeff Kirsher
472dcd5d95SSritej Velaga NXWR32(adapter, NX_ARG1_CRB_OFFSET, cmd->req.arg1);
48aa43c215SJeff Kirsher
492dcd5d95SSritej Velaga NXWR32(adapter, NX_ARG2_CRB_OFFSET, cmd->req.arg2);
50aa43c215SJeff Kirsher
512dcd5d95SSritej Velaga NXWR32(adapter, NX_ARG3_CRB_OFFSET, cmd->req.arg3);
52aa43c215SJeff Kirsher
532dcd5d95SSritej Velaga NXWR32(adapter, NX_CDRP_CRB_OFFSET, NX_CDRP_FORM_CMD(cmd->req.cmd));
54aa43c215SJeff Kirsher
55aa43c215SJeff Kirsher rsp = netxen_poll_rsp(adapter);
56aa43c215SJeff Kirsher
57aa43c215SJeff Kirsher if (rsp == NX_CDRP_RSP_TIMEOUT) {
58aa43c215SJeff Kirsher printk(KERN_ERR "%s: card response timeout.\n",
59aa43c215SJeff Kirsher netxen_nic_driver_name);
60aa43c215SJeff Kirsher
61aa43c215SJeff Kirsher rcode = NX_RCODE_TIMEOUT;
62aa43c215SJeff Kirsher } else if (rsp == NX_CDRP_RSP_FAIL) {
63aa43c215SJeff Kirsher rcode = NXRD32(adapter, NX_ARG1_CRB_OFFSET);
64aa43c215SJeff Kirsher
65aa43c215SJeff Kirsher printk(KERN_ERR "%s: failed card response code:0x%x\n",
66aa43c215SJeff Kirsher netxen_nic_driver_name, rcode);
672dcd5d95SSritej Velaga } else if (rsp == NX_CDRP_RSP_OK) {
6883f18a55SManish chopra cmd->rsp.cmd = NX_RCODE_SUCCESS;
692dcd5d95SSritej Velaga if (cmd->rsp.arg2)
702dcd5d95SSritej Velaga cmd->rsp.arg2 = NXRD32(adapter, NX_ARG2_CRB_OFFSET);
712dcd5d95SSritej Velaga if (cmd->rsp.arg3)
722dcd5d95SSritej Velaga cmd->rsp.arg3 = NXRD32(adapter, NX_ARG3_CRB_OFFSET);
73aa43c215SJeff Kirsher }
74aa43c215SJeff Kirsher
752dcd5d95SSritej Velaga if (cmd->rsp.arg1)
762dcd5d95SSritej Velaga cmd->rsp.arg1 = NXRD32(adapter, NX_ARG1_CRB_OFFSET);
77aa43c215SJeff Kirsher /* Release semaphore */
78aa43c215SJeff Kirsher netxen_api_unlock(adapter);
79aa43c215SJeff Kirsher
80aa43c215SJeff Kirsher return rcode;
81aa43c215SJeff Kirsher }
82aa43c215SJeff Kirsher
8383f18a55SManish chopra static int
netxen_get_minidump_template_size(struct netxen_adapter * adapter)8483f18a55SManish chopra netxen_get_minidump_template_size(struct netxen_adapter *adapter)
8583f18a55SManish chopra {
8683f18a55SManish chopra struct netxen_cmd_args cmd;
8783f18a55SManish chopra memset(&cmd, 0, sizeof(cmd));
8883f18a55SManish chopra cmd.req.cmd = NX_CDRP_CMD_TEMP_SIZE;
8983f18a55SManish chopra memset(&cmd.rsp, 1, sizeof(struct _cdrp_cmd));
9083f18a55SManish chopra netxen_issue_cmd(adapter, &cmd);
9183f18a55SManish chopra if (cmd.rsp.cmd != NX_RCODE_SUCCESS) {
9283f18a55SManish chopra dev_info(&adapter->pdev->dev,
9383f18a55SManish chopra "Can't get template size %d\n", cmd.rsp.cmd);
9483f18a55SManish chopra return -EIO;
9583f18a55SManish chopra }
9683f18a55SManish chopra adapter->mdump.md_template_size = cmd.rsp.arg2;
9783f18a55SManish chopra adapter->mdump.md_template_ver = cmd.rsp.arg3;
9883f18a55SManish chopra return 0;
9983f18a55SManish chopra }
10083f18a55SManish chopra
10183f18a55SManish chopra static int
netxen_get_minidump_template(struct netxen_adapter * adapter)10283f18a55SManish chopra netxen_get_minidump_template(struct netxen_adapter *adapter)
10383f18a55SManish chopra {
10483f18a55SManish chopra dma_addr_t md_template_addr;
10583f18a55SManish chopra void *addr;
10683f18a55SManish chopra u32 size;
10783f18a55SManish chopra struct netxen_cmd_args cmd;
10883f18a55SManish chopra size = adapter->mdump.md_template_size;
10983f18a55SManish chopra
11083f18a55SManish chopra if (size == 0) {
11183f18a55SManish chopra dev_err(&adapter->pdev->dev, "Can not capture Minidump "
11283f18a55SManish chopra "template. Invalid template size.\n");
11383f18a55SManish chopra return NX_RCODE_INVALID_ARGS;
11483f18a55SManish chopra }
11583f18a55SManish chopra
116*297af515SChristophe JAILLET addr = dma_alloc_coherent(&adapter->pdev->dev, size,
117*297af515SChristophe JAILLET &md_template_addr, GFP_KERNEL);
11883f18a55SManish chopra if (!addr) {
11983f18a55SManish chopra dev_err(&adapter->pdev->dev, "Unable to allocate dmable memory for template.\n");
12083f18a55SManish chopra return -ENOMEM;
12183f18a55SManish chopra }
12283f18a55SManish chopra
12383f18a55SManish chopra memset(&cmd, 0, sizeof(cmd));
12483f18a55SManish chopra memset(&cmd.rsp, 1, sizeof(struct _cdrp_cmd));
12583f18a55SManish chopra cmd.req.cmd = NX_CDRP_CMD_GET_TEMP_HDR;
12683f18a55SManish chopra cmd.req.arg1 = LSD(md_template_addr);
12783f18a55SManish chopra cmd.req.arg2 = MSD(md_template_addr);
12883f18a55SManish chopra cmd.req.arg3 |= size;
12983f18a55SManish chopra netxen_issue_cmd(adapter, &cmd);
13083f18a55SManish chopra
13183f18a55SManish chopra if ((cmd.rsp.cmd == NX_RCODE_SUCCESS) && (size == cmd.rsp.arg2)) {
13283f18a55SManish chopra memcpy(adapter->mdump.md_template, addr, size);
13383f18a55SManish chopra } else {
134d602de8eSJoe Perches dev_err(&adapter->pdev->dev, "Failed to get minidump template, err_code : %d, requested_size : %d, actual_size : %d\n",
13583f18a55SManish chopra cmd.rsp.cmd, size, cmd.rsp.arg2);
13683f18a55SManish chopra }
137*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev, size, addr, md_template_addr);
13883f18a55SManish chopra return 0;
13983f18a55SManish chopra }
14083f18a55SManish chopra
14183f18a55SManish chopra static u32
netxen_check_template_checksum(struct netxen_adapter * adapter)14283f18a55SManish chopra netxen_check_template_checksum(struct netxen_adapter *adapter)
14383f18a55SManish chopra {
14483f18a55SManish chopra u64 sum = 0 ;
14583f18a55SManish chopra u32 *buff = adapter->mdump.md_template;
14683f18a55SManish chopra int count = adapter->mdump.md_template_size/sizeof(uint32_t) ;
14783f18a55SManish chopra
14883f18a55SManish chopra while (count-- > 0)
14983f18a55SManish chopra sum += *buff++ ;
15083f18a55SManish chopra while (sum >> 32)
15183f18a55SManish chopra sum = (sum & 0xFFFFFFFF) + (sum >> 32) ;
15283f18a55SManish chopra
15383f18a55SManish chopra return ~sum;
15483f18a55SManish chopra }
15583f18a55SManish chopra
15683f18a55SManish chopra int
netxen_setup_minidump(struct netxen_adapter * adapter)15783f18a55SManish chopra netxen_setup_minidump(struct netxen_adapter *adapter)
15883f18a55SManish chopra {
15983f18a55SManish chopra int err = 0, i;
16083f18a55SManish chopra u32 *template, *tmp_buf;
16183f18a55SManish chopra err = netxen_get_minidump_template_size(adapter);
16283f18a55SManish chopra if (err) {
16383f18a55SManish chopra adapter->mdump.fw_supports_md = 0;
16483f18a55SManish chopra if ((err == NX_RCODE_CMD_INVALID) ||
16583f18a55SManish chopra (err == NX_RCODE_CMD_NOT_IMPL)) {
16683f18a55SManish chopra dev_info(&adapter->pdev->dev,
167d602de8eSJoe Perches "Flashed firmware version does not support minidump, minimum version required is [ %u.%u.%u ]\n",
16883f18a55SManish chopra NX_MD_SUPPORT_MAJOR, NX_MD_SUPPORT_MINOR,
16983f18a55SManish chopra NX_MD_SUPPORT_SUBVERSION);
17083f18a55SManish chopra }
17183f18a55SManish chopra return err;
17283f18a55SManish chopra }
17383f18a55SManish chopra
17483f18a55SManish chopra if (!adapter->mdump.md_template_size) {
17583f18a55SManish chopra dev_err(&adapter->pdev->dev, "Error : Invalid template size "
17683f18a55SManish chopra ",should be non-zero.\n");
17783f18a55SManish chopra return -EIO;
17883f18a55SManish chopra }
17983f18a55SManish chopra adapter->mdump.md_template =
18083f18a55SManish chopra kmalloc(adapter->mdump.md_template_size, GFP_KERNEL);
18183f18a55SManish chopra
182b2adaca9SJoe Perches if (!adapter->mdump.md_template)
18383f18a55SManish chopra return -ENOMEM;
18483f18a55SManish chopra
18583f18a55SManish chopra err = netxen_get_minidump_template(adapter);
18683f18a55SManish chopra if (err) {
18783f18a55SManish chopra if (err == NX_RCODE_CMD_NOT_IMPL)
18883f18a55SManish chopra adapter->mdump.fw_supports_md = 0;
18983f18a55SManish chopra goto free_template;
19083f18a55SManish chopra }
19183f18a55SManish chopra
19283f18a55SManish chopra if (netxen_check_template_checksum(adapter)) {
19383f18a55SManish chopra dev_err(&adapter->pdev->dev, "Minidump template checksum Error\n");
19483f18a55SManish chopra err = -EIO;
19583f18a55SManish chopra goto free_template;
19683f18a55SManish chopra }
19783f18a55SManish chopra
19883f18a55SManish chopra adapter->mdump.md_capture_mask = NX_DUMP_MASK_DEF;
19983f18a55SManish chopra tmp_buf = (u32 *) adapter->mdump.md_template;
20083f18a55SManish chopra template = (u32 *) adapter->mdump.md_template;
20183f18a55SManish chopra for (i = 0; i < adapter->mdump.md_template_size/sizeof(u32); i++)
20283f18a55SManish chopra *template++ = __le32_to_cpu(*tmp_buf++);
20383f18a55SManish chopra adapter->mdump.md_capture_buff = NULL;
20483f18a55SManish chopra adapter->mdump.fw_supports_md = 1;
205458c2858SSritej Velaga adapter->mdump.md_enabled = 0;
20683f18a55SManish chopra
20783f18a55SManish chopra return err;
20883f18a55SManish chopra
20983f18a55SManish chopra free_template:
21083f18a55SManish chopra kfree(adapter->mdump.md_template);
21183f18a55SManish chopra adapter->mdump.md_template = NULL;
21283f18a55SManish chopra return err;
21383f18a55SManish chopra }
21483f18a55SManish chopra
21583f18a55SManish chopra
216aa43c215SJeff Kirsher int
nx_fw_cmd_set_mtu(struct netxen_adapter * adapter,int mtu)217aa43c215SJeff Kirsher nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu)
218aa43c215SJeff Kirsher {
219aa43c215SJeff Kirsher u32 rcode = NX_RCODE_SUCCESS;
220aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
2212dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
2222dcd5d95SSritej Velaga
2232dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
2242dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_SET_MTU;
2252dcd5d95SSritej Velaga cmd.req.arg1 = recv_ctx->context_id;
2262dcd5d95SSritej Velaga cmd.req.arg2 = mtu;
2272dcd5d95SSritej Velaga cmd.req.arg3 = 0;
228aa43c215SJeff Kirsher
229aa43c215SJeff Kirsher if (recv_ctx->state == NX_HOST_CTX_STATE_ACTIVE)
2300fe20fafSColin Ian King rcode = netxen_issue_cmd(adapter, &cmd);
231aa43c215SJeff Kirsher
232aa43c215SJeff Kirsher if (rcode != NX_RCODE_SUCCESS)
233aa43c215SJeff Kirsher return -EIO;
234aa43c215SJeff Kirsher
235aa43c215SJeff Kirsher return 0;
236aa43c215SJeff Kirsher }
237aa43c215SJeff Kirsher
238aa43c215SJeff Kirsher int
nx_fw_cmd_set_gbe_port(struct netxen_adapter * adapter,u32 speed,u32 duplex,u32 autoneg)239aa43c215SJeff Kirsher nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter,
240aa43c215SJeff Kirsher u32 speed, u32 duplex, u32 autoneg)
241aa43c215SJeff Kirsher {
2422dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
243aa43c215SJeff Kirsher
2442dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
2452dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_CONFIG_GBE_PORT;
2462dcd5d95SSritej Velaga cmd.req.arg1 = speed;
2472dcd5d95SSritej Velaga cmd.req.arg2 = duplex;
2482dcd5d95SSritej Velaga cmd.req.arg3 = autoneg;
2492dcd5d95SSritej Velaga return netxen_issue_cmd(adapter, &cmd);
250aa43c215SJeff Kirsher }
251aa43c215SJeff Kirsher
252aa43c215SJeff Kirsher static int
nx_fw_cmd_create_rx_ctx(struct netxen_adapter * adapter)253aa43c215SJeff Kirsher nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter)
254aa43c215SJeff Kirsher {
255aa43c215SJeff Kirsher void *addr;
256aa43c215SJeff Kirsher nx_hostrq_rx_ctx_t *prq;
257aa43c215SJeff Kirsher nx_cardrsp_rx_ctx_t *prsp;
258aa43c215SJeff Kirsher nx_hostrq_rds_ring_t *prq_rds;
259aa43c215SJeff Kirsher nx_hostrq_sds_ring_t *prq_sds;
260aa43c215SJeff Kirsher nx_cardrsp_rds_ring_t *prsp_rds;
261aa43c215SJeff Kirsher nx_cardrsp_sds_ring_t *prsp_sds;
262aa43c215SJeff Kirsher struct nx_host_rds_ring *rds_ring;
263aa43c215SJeff Kirsher struct nx_host_sds_ring *sds_ring;
2642dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
265aa43c215SJeff Kirsher
266aa43c215SJeff Kirsher dma_addr_t hostrq_phys_addr, cardrsp_phys_addr;
267aa43c215SJeff Kirsher u64 phys_addr;
268aa43c215SJeff Kirsher
269aa43c215SJeff Kirsher int i, nrds_rings, nsds_rings;
270aa43c215SJeff Kirsher size_t rq_size, rsp_size;
271aa43c215SJeff Kirsher u32 cap, reg, val;
272aa43c215SJeff Kirsher
273aa43c215SJeff Kirsher int err;
274aa43c215SJeff Kirsher
275aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
276aa43c215SJeff Kirsher
277aa43c215SJeff Kirsher nrds_rings = adapter->max_rds_rings;
278aa43c215SJeff Kirsher nsds_rings = adapter->max_sds_rings;
279aa43c215SJeff Kirsher
280aa43c215SJeff Kirsher rq_size =
281aa43c215SJeff Kirsher SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t, nrds_rings, nsds_rings);
282aa43c215SJeff Kirsher rsp_size =
283aa43c215SJeff Kirsher SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t, nrds_rings, nsds_rings);
284aa43c215SJeff Kirsher
285*297af515SChristophe JAILLET addr = dma_alloc_coherent(&adapter->pdev->dev, rq_size,
286*297af515SChristophe JAILLET &hostrq_phys_addr, GFP_KERNEL);
287aa43c215SJeff Kirsher if (addr == NULL)
288aa43c215SJeff Kirsher return -ENOMEM;
289aa43c215SJeff Kirsher prq = addr;
290aa43c215SJeff Kirsher
291*297af515SChristophe JAILLET addr = dma_alloc_coherent(&adapter->pdev->dev, rsp_size,
292*297af515SChristophe JAILLET &cardrsp_phys_addr, GFP_KERNEL);
293aa43c215SJeff Kirsher if (addr == NULL) {
294aa43c215SJeff Kirsher err = -ENOMEM;
295aa43c215SJeff Kirsher goto out_free_rq;
296aa43c215SJeff Kirsher }
297aa43c215SJeff Kirsher prsp = addr;
298aa43c215SJeff Kirsher
299aa43c215SJeff Kirsher prq->host_rsp_dma_addr = cpu_to_le64(cardrsp_phys_addr);
300aa43c215SJeff Kirsher
301aa43c215SJeff Kirsher cap = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN);
302aa43c215SJeff Kirsher cap |= (NX_CAP0_JUMBO_CONTIGUOUS | NX_CAP0_LRO_CONTIGUOUS);
303aa43c215SJeff Kirsher
30401da0c2bSRajesh Borundia if (adapter->flags & NETXEN_FW_MSS_CAP)
30501da0c2bSRajesh Borundia cap |= NX_CAP0_HW_LRO_MSS;
30601da0c2bSRajesh Borundia
307aa43c215SJeff Kirsher prq->capabilities[0] = cpu_to_le32(cap);
308aa43c215SJeff Kirsher prq->host_int_crb_mode =
309aa43c215SJeff Kirsher cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED);
310aa43c215SJeff Kirsher prq->host_rds_crb_mode =
311aa43c215SJeff Kirsher cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE);
312aa43c215SJeff Kirsher
313aa43c215SJeff Kirsher prq->num_rds_rings = cpu_to_le16(nrds_rings);
314aa43c215SJeff Kirsher prq->num_sds_rings = cpu_to_le16(nsds_rings);
315aa43c215SJeff Kirsher prq->rds_ring_offset = cpu_to_le32(0);
316aa43c215SJeff Kirsher
317aa43c215SJeff Kirsher val = le32_to_cpu(prq->rds_ring_offset) +
318aa43c215SJeff Kirsher (sizeof(nx_hostrq_rds_ring_t) * nrds_rings);
319aa43c215SJeff Kirsher prq->sds_ring_offset = cpu_to_le32(val);
320aa43c215SJeff Kirsher
321aa43c215SJeff Kirsher prq_rds = (nx_hostrq_rds_ring_t *)(prq->data +
322aa43c215SJeff Kirsher le32_to_cpu(prq->rds_ring_offset));
323aa43c215SJeff Kirsher
324aa43c215SJeff Kirsher for (i = 0; i < nrds_rings; i++) {
325aa43c215SJeff Kirsher
326aa43c215SJeff Kirsher rds_ring = &recv_ctx->rds_rings[i];
327aa43c215SJeff Kirsher
328aa43c215SJeff Kirsher prq_rds[i].host_phys_addr = cpu_to_le64(rds_ring->phys_addr);
329aa43c215SJeff Kirsher prq_rds[i].ring_size = cpu_to_le32(rds_ring->num_desc);
330aa43c215SJeff Kirsher prq_rds[i].ring_kind = cpu_to_le32(i);
331aa43c215SJeff Kirsher prq_rds[i].buff_size = cpu_to_le64(rds_ring->dma_size);
332aa43c215SJeff Kirsher }
333aa43c215SJeff Kirsher
334aa43c215SJeff Kirsher prq_sds = (nx_hostrq_sds_ring_t *)(prq->data +
335aa43c215SJeff Kirsher le32_to_cpu(prq->sds_ring_offset));
336aa43c215SJeff Kirsher
337aa43c215SJeff Kirsher for (i = 0; i < nsds_rings; i++) {
338aa43c215SJeff Kirsher
339aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[i];
340aa43c215SJeff Kirsher
341aa43c215SJeff Kirsher prq_sds[i].host_phys_addr = cpu_to_le64(sds_ring->phys_addr);
342aa43c215SJeff Kirsher prq_sds[i].ring_size = cpu_to_le32(sds_ring->num_desc);
343aa43c215SJeff Kirsher prq_sds[i].msi_index = cpu_to_le16(i);
344aa43c215SJeff Kirsher }
345aa43c215SJeff Kirsher
346aa43c215SJeff Kirsher phys_addr = hostrq_phys_addr;
3472dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
3482dcd5d95SSritej Velaga cmd.req.arg1 = (u32)(phys_addr >> 32);
3492dcd5d95SSritej Velaga cmd.req.arg2 = (u32)(phys_addr & 0xffffffff);
3502dcd5d95SSritej Velaga cmd.req.arg3 = rq_size;
3512dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_CREATE_RX_CTX;
3522dcd5d95SSritej Velaga err = netxen_issue_cmd(adapter, &cmd);
353aa43c215SJeff Kirsher if (err) {
354aa43c215SJeff Kirsher printk(KERN_WARNING
355aa43c215SJeff Kirsher "Failed to create rx ctx in firmware%d\n", err);
356aa43c215SJeff Kirsher goto out_free_rsp;
357aa43c215SJeff Kirsher }
358aa43c215SJeff Kirsher
359aa43c215SJeff Kirsher
360aa43c215SJeff Kirsher prsp_rds = ((nx_cardrsp_rds_ring_t *)
361aa43c215SJeff Kirsher &prsp->data[le32_to_cpu(prsp->rds_ring_offset)]);
362aa43c215SJeff Kirsher
363aa43c215SJeff Kirsher for (i = 0; i < le16_to_cpu(prsp->num_rds_rings); i++) {
364aa43c215SJeff Kirsher rds_ring = &recv_ctx->rds_rings[i];
365aa43c215SJeff Kirsher
366aa43c215SJeff Kirsher reg = le32_to_cpu(prsp_rds[i].host_producer_crb);
367aa43c215SJeff Kirsher rds_ring->crb_rcv_producer = netxen_get_ioaddr(adapter,
368aa43c215SJeff Kirsher NETXEN_NIC_REG(reg - 0x200));
369aa43c215SJeff Kirsher }
370aa43c215SJeff Kirsher
371aa43c215SJeff Kirsher prsp_sds = ((nx_cardrsp_sds_ring_t *)
372aa43c215SJeff Kirsher &prsp->data[le32_to_cpu(prsp->sds_ring_offset)]);
373aa43c215SJeff Kirsher
374aa43c215SJeff Kirsher for (i = 0; i < le16_to_cpu(prsp->num_sds_rings); i++) {
375aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[i];
376aa43c215SJeff Kirsher
377aa43c215SJeff Kirsher reg = le32_to_cpu(prsp_sds[i].host_consumer_crb);
378aa43c215SJeff Kirsher sds_ring->crb_sts_consumer = netxen_get_ioaddr(adapter,
379aa43c215SJeff Kirsher NETXEN_NIC_REG(reg - 0x200));
380aa43c215SJeff Kirsher
381aa43c215SJeff Kirsher reg = le32_to_cpu(prsp_sds[i].interrupt_crb);
382aa43c215SJeff Kirsher sds_ring->crb_intr_mask = netxen_get_ioaddr(adapter,
383aa43c215SJeff Kirsher NETXEN_NIC_REG(reg - 0x200));
384aa43c215SJeff Kirsher }
385aa43c215SJeff Kirsher
386aa43c215SJeff Kirsher recv_ctx->state = le32_to_cpu(prsp->host_ctx_state);
387aa43c215SJeff Kirsher recv_ctx->context_id = le16_to_cpu(prsp->context_id);
388aa43c215SJeff Kirsher recv_ctx->virt_port = prsp->virt_port;
389aa43c215SJeff Kirsher
390aa43c215SJeff Kirsher out_free_rsp:
391*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev, rsp_size, prsp,
392*297af515SChristophe JAILLET cardrsp_phys_addr);
393aa43c215SJeff Kirsher out_free_rq:
394*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev, rq_size, prq, hostrq_phys_addr);
395aa43c215SJeff Kirsher return err;
396aa43c215SJeff Kirsher }
397aa43c215SJeff Kirsher
398aa43c215SJeff Kirsher static void
nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter * adapter)399aa43c215SJeff Kirsher nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter)
400aa43c215SJeff Kirsher {
401aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
4022dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
403aa43c215SJeff Kirsher
4042dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
4052dcd5d95SSritej Velaga cmd.req.arg1 = recv_ctx->context_id;
4062dcd5d95SSritej Velaga cmd.req.arg2 = NX_DESTROY_CTX_RESET;
4072dcd5d95SSritej Velaga cmd.req.arg3 = 0;
4082dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_DESTROY_RX_CTX;
409aa43c215SJeff Kirsher
4102dcd5d95SSritej Velaga if (netxen_issue_cmd(adapter, &cmd)) {
411aa43c215SJeff Kirsher printk(KERN_WARNING
412aa43c215SJeff Kirsher "%s: Failed to destroy rx ctx in firmware\n",
413aa43c215SJeff Kirsher netxen_nic_driver_name);
414aa43c215SJeff Kirsher }
415aa43c215SJeff Kirsher }
416aa43c215SJeff Kirsher
417aa43c215SJeff Kirsher static int
nx_fw_cmd_create_tx_ctx(struct netxen_adapter * adapter)418aa43c215SJeff Kirsher nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter)
419aa43c215SJeff Kirsher {
420aa43c215SJeff Kirsher nx_hostrq_tx_ctx_t *prq;
421aa43c215SJeff Kirsher nx_hostrq_cds_ring_t *prq_cds;
422aa43c215SJeff Kirsher nx_cardrsp_tx_ctx_t *prsp;
423aa43c215SJeff Kirsher void *rq_addr, *rsp_addr;
424aa43c215SJeff Kirsher size_t rq_size, rsp_size;
425aa43c215SJeff Kirsher u32 temp;
426aa43c215SJeff Kirsher int err = 0;
427aa43c215SJeff Kirsher u64 offset, phys_addr;
428aa43c215SJeff Kirsher dma_addr_t rq_phys_addr, rsp_phys_addr;
429aa43c215SJeff Kirsher struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
430aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
4312dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
432aa43c215SJeff Kirsher
433aa43c215SJeff Kirsher rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t);
434*297af515SChristophe JAILLET rq_addr = dma_alloc_coherent(&adapter->pdev->dev, rq_size,
435*297af515SChristophe JAILLET &rq_phys_addr, GFP_KERNEL);
436aa43c215SJeff Kirsher if (!rq_addr)
437aa43c215SJeff Kirsher return -ENOMEM;
438aa43c215SJeff Kirsher
439aa43c215SJeff Kirsher rsp_size = SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t);
440*297af515SChristophe JAILLET rsp_addr = dma_alloc_coherent(&adapter->pdev->dev, rsp_size,
441*297af515SChristophe JAILLET &rsp_phys_addr, GFP_KERNEL);
442aa43c215SJeff Kirsher if (!rsp_addr) {
443aa43c215SJeff Kirsher err = -ENOMEM;
444aa43c215SJeff Kirsher goto out_free_rq;
445aa43c215SJeff Kirsher }
446aa43c215SJeff Kirsher
447aa43c215SJeff Kirsher prq = rq_addr;
448aa43c215SJeff Kirsher
449aa43c215SJeff Kirsher prsp = rsp_addr;
450aa43c215SJeff Kirsher
451aa43c215SJeff Kirsher prq->host_rsp_dma_addr = cpu_to_le64(rsp_phys_addr);
452aa43c215SJeff Kirsher
453aa43c215SJeff Kirsher temp = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN | NX_CAP0_LSO);
454aa43c215SJeff Kirsher prq->capabilities[0] = cpu_to_le32(temp);
455aa43c215SJeff Kirsher
456aa43c215SJeff Kirsher prq->host_int_crb_mode =
457aa43c215SJeff Kirsher cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED);
458aa43c215SJeff Kirsher
459aa43c215SJeff Kirsher prq->interrupt_ctl = 0;
460aa43c215SJeff Kirsher prq->msi_index = 0;
461aa43c215SJeff Kirsher
462aa43c215SJeff Kirsher prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr);
463aa43c215SJeff Kirsher
464aa43c215SJeff Kirsher offset = recv_ctx->phys_addr + sizeof(struct netxen_ring_ctx);
465aa43c215SJeff Kirsher prq->cmd_cons_dma_addr = cpu_to_le64(offset);
466aa43c215SJeff Kirsher
467aa43c215SJeff Kirsher prq_cds = &prq->cds_ring;
468aa43c215SJeff Kirsher
469aa43c215SJeff Kirsher prq_cds->host_phys_addr = cpu_to_le64(tx_ring->phys_addr);
470aa43c215SJeff Kirsher prq_cds->ring_size = cpu_to_le32(tx_ring->num_desc);
471aa43c215SJeff Kirsher
472aa43c215SJeff Kirsher phys_addr = rq_phys_addr;
4732dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
4742dcd5d95SSritej Velaga cmd.req.arg1 = (u32)(phys_addr >> 32);
4752dcd5d95SSritej Velaga cmd.req.arg2 = ((u32)phys_addr & 0xffffffff);
4762dcd5d95SSritej Velaga cmd.req.arg3 = rq_size;
4772dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_CREATE_TX_CTX;
4782dcd5d95SSritej Velaga err = netxen_issue_cmd(adapter, &cmd);
479aa43c215SJeff Kirsher
480aa43c215SJeff Kirsher if (err == NX_RCODE_SUCCESS) {
481aa43c215SJeff Kirsher temp = le32_to_cpu(prsp->cds_ring.host_producer_crb);
482aa43c215SJeff Kirsher tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
483aa43c215SJeff Kirsher NETXEN_NIC_REG(temp - 0x200));
484aa43c215SJeff Kirsher #if 0
485aa43c215SJeff Kirsher adapter->tx_state =
486aa43c215SJeff Kirsher le32_to_cpu(prsp->host_ctx_state);
487aa43c215SJeff Kirsher #endif
488aa43c215SJeff Kirsher adapter->tx_context_id =
489aa43c215SJeff Kirsher le16_to_cpu(prsp->context_id);
490aa43c215SJeff Kirsher } else {
491aa43c215SJeff Kirsher printk(KERN_WARNING
492aa43c215SJeff Kirsher "Failed to create tx ctx in firmware%d\n", err);
493aa43c215SJeff Kirsher err = -EIO;
494aa43c215SJeff Kirsher }
495aa43c215SJeff Kirsher
496*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev, rsp_size, rsp_addr,
497*297af515SChristophe JAILLET rsp_phys_addr);
498aa43c215SJeff Kirsher
499aa43c215SJeff Kirsher out_free_rq:
500*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev, rq_size, rq_addr, rq_phys_addr);
501aa43c215SJeff Kirsher
502aa43c215SJeff Kirsher return err;
503aa43c215SJeff Kirsher }
504aa43c215SJeff Kirsher
505aa43c215SJeff Kirsher static void
nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter * adapter)506aa43c215SJeff Kirsher nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter *adapter)
507aa43c215SJeff Kirsher {
5082dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
509aa43c215SJeff Kirsher
5102dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
5112dcd5d95SSritej Velaga cmd.req.arg1 = adapter->tx_context_id;
5122dcd5d95SSritej Velaga cmd.req.arg2 = NX_DESTROY_CTX_RESET;
5132dcd5d95SSritej Velaga cmd.req.arg3 = 0;
5142dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_DESTROY_TX_CTX;
5152dcd5d95SSritej Velaga if (netxen_issue_cmd(adapter, &cmd)) {
516aa43c215SJeff Kirsher printk(KERN_WARNING
517aa43c215SJeff Kirsher "%s: Failed to destroy tx ctx in firmware\n",
518aa43c215SJeff Kirsher netxen_nic_driver_name);
519aa43c215SJeff Kirsher }
520aa43c215SJeff Kirsher }
521aa43c215SJeff Kirsher
522aa43c215SJeff Kirsher int
nx_fw_cmd_query_phy(struct netxen_adapter * adapter,u32 reg,u32 * val)523aa43c215SJeff Kirsher nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val)
524aa43c215SJeff Kirsher {
525aa43c215SJeff Kirsher u32 rcode;
5262dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
527aa43c215SJeff Kirsher
5282dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
5292dcd5d95SSritej Velaga cmd.req.arg1 = reg;
5302dcd5d95SSritej Velaga cmd.req.arg2 = 0;
5312dcd5d95SSritej Velaga cmd.req.arg3 = 0;
5322dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_READ_PHY;
5332dcd5d95SSritej Velaga cmd.rsp.arg1 = 1;
5342dcd5d95SSritej Velaga rcode = netxen_issue_cmd(adapter, &cmd);
535aa43c215SJeff Kirsher if (rcode != NX_RCODE_SUCCESS)
536aa43c215SJeff Kirsher return -EIO;
537aa43c215SJeff Kirsher
538db608c12SSritej Velaga if (val == NULL)
539db608c12SSritej Velaga return -EIO;
540db608c12SSritej Velaga
541db608c12SSritej Velaga *val = cmd.rsp.arg1;
542db608c12SSritej Velaga return 0;
543aa43c215SJeff Kirsher }
544aa43c215SJeff Kirsher
545aa43c215SJeff Kirsher int
nx_fw_cmd_set_phy(struct netxen_adapter * adapter,u32 reg,u32 val)546aa43c215SJeff Kirsher nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val)
547aa43c215SJeff Kirsher {
548aa43c215SJeff Kirsher u32 rcode;
5492dcd5d95SSritej Velaga struct netxen_cmd_args cmd;
550aa43c215SJeff Kirsher
5512dcd5d95SSritej Velaga memset(&cmd, 0, sizeof(cmd));
5522dcd5d95SSritej Velaga cmd.req.arg1 = reg;
5532dcd5d95SSritej Velaga cmd.req.arg2 = val;
5542dcd5d95SSritej Velaga cmd.req.arg3 = 0;
5552dcd5d95SSritej Velaga cmd.req.cmd = NX_CDRP_CMD_WRITE_PHY;
5562dcd5d95SSritej Velaga rcode = netxen_issue_cmd(adapter, &cmd);
557aa43c215SJeff Kirsher if (rcode != NX_RCODE_SUCCESS)
558aa43c215SJeff Kirsher return -EIO;
559aa43c215SJeff Kirsher
560aa43c215SJeff Kirsher return 0;
561aa43c215SJeff Kirsher }
562aa43c215SJeff Kirsher
563aa43c215SJeff Kirsher static u64 ctx_addr_sig_regs[][3] = {
564aa43c215SJeff Kirsher {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
565aa43c215SJeff Kirsher {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
566aa43c215SJeff Kirsher {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
567aa43c215SJeff Kirsher {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
568aa43c215SJeff Kirsher };
569aa43c215SJeff Kirsher
570aa43c215SJeff Kirsher #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
571aa43c215SJeff Kirsher #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
572aa43c215SJeff Kirsher #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
573aa43c215SJeff Kirsher
574aa43c215SJeff Kirsher #define lower32(x) ((u32)((x) & 0xffffffff))
575aa43c215SJeff Kirsher #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
576aa43c215SJeff Kirsher
577aa43c215SJeff Kirsher static struct netxen_recv_crb recv_crb_registers[] = {
578aa43c215SJeff Kirsher /* Instance 0 */
579aa43c215SJeff Kirsher {
580aa43c215SJeff Kirsher /* crb_rcv_producer: */
581aa43c215SJeff Kirsher {
582aa43c215SJeff Kirsher NETXEN_NIC_REG(0x100),
583aa43c215SJeff Kirsher /* Jumbo frames */
584aa43c215SJeff Kirsher NETXEN_NIC_REG(0x110),
585aa43c215SJeff Kirsher /* LRO */
586aa43c215SJeff Kirsher NETXEN_NIC_REG(0x120)
587aa43c215SJeff Kirsher },
588aa43c215SJeff Kirsher /* crb_sts_consumer: */
589aa43c215SJeff Kirsher {
590aa43c215SJeff Kirsher NETXEN_NIC_REG(0x138),
591aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x000),
592aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x004),
593aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x008),
594aa43c215SJeff Kirsher },
595aa43c215SJeff Kirsher /* sw_int_mask */
596aa43c215SJeff Kirsher {
597aa43c215SJeff Kirsher CRB_SW_INT_MASK_0,
598aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x044),
599aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x048),
600aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x04c),
601aa43c215SJeff Kirsher },
602aa43c215SJeff Kirsher },
603aa43c215SJeff Kirsher /* Instance 1 */
604aa43c215SJeff Kirsher {
605aa43c215SJeff Kirsher /* crb_rcv_producer: */
606aa43c215SJeff Kirsher {
607aa43c215SJeff Kirsher NETXEN_NIC_REG(0x144),
608aa43c215SJeff Kirsher /* Jumbo frames */
609aa43c215SJeff Kirsher NETXEN_NIC_REG(0x154),
610aa43c215SJeff Kirsher /* LRO */
611aa43c215SJeff Kirsher NETXEN_NIC_REG(0x164)
612aa43c215SJeff Kirsher },
613aa43c215SJeff Kirsher /* crb_sts_consumer: */
614aa43c215SJeff Kirsher {
615aa43c215SJeff Kirsher NETXEN_NIC_REG(0x17c),
616aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x020),
617aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x024),
618aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x028),
619aa43c215SJeff Kirsher },
620aa43c215SJeff Kirsher /* sw_int_mask */
621aa43c215SJeff Kirsher {
622aa43c215SJeff Kirsher CRB_SW_INT_MASK_1,
623aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x064),
624aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x068),
625aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x06c),
626aa43c215SJeff Kirsher },
627aa43c215SJeff Kirsher },
628aa43c215SJeff Kirsher /* Instance 2 */
629aa43c215SJeff Kirsher {
630aa43c215SJeff Kirsher /* crb_rcv_producer: */
631aa43c215SJeff Kirsher {
632aa43c215SJeff Kirsher NETXEN_NIC_REG(0x1d8),
633aa43c215SJeff Kirsher /* Jumbo frames */
634aa43c215SJeff Kirsher NETXEN_NIC_REG(0x1f8),
635aa43c215SJeff Kirsher /* LRO */
636aa43c215SJeff Kirsher NETXEN_NIC_REG(0x208)
637aa43c215SJeff Kirsher },
638aa43c215SJeff Kirsher /* crb_sts_consumer: */
639aa43c215SJeff Kirsher {
640aa43c215SJeff Kirsher NETXEN_NIC_REG(0x220),
641aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
642aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
643aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
644aa43c215SJeff Kirsher },
645aa43c215SJeff Kirsher /* sw_int_mask */
646aa43c215SJeff Kirsher {
647aa43c215SJeff Kirsher CRB_SW_INT_MASK_2,
648aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
649aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
650aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
651aa43c215SJeff Kirsher },
652aa43c215SJeff Kirsher },
653aa43c215SJeff Kirsher /* Instance 3 */
654aa43c215SJeff Kirsher {
655aa43c215SJeff Kirsher /* crb_rcv_producer: */
656aa43c215SJeff Kirsher {
657aa43c215SJeff Kirsher NETXEN_NIC_REG(0x22c),
658aa43c215SJeff Kirsher /* Jumbo frames */
659aa43c215SJeff Kirsher NETXEN_NIC_REG(0x23c),
660aa43c215SJeff Kirsher /* LRO */
661aa43c215SJeff Kirsher NETXEN_NIC_REG(0x24c)
662aa43c215SJeff Kirsher },
663aa43c215SJeff Kirsher /* crb_sts_consumer: */
664aa43c215SJeff Kirsher {
665aa43c215SJeff Kirsher NETXEN_NIC_REG(0x264),
666aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
667aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
668aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
669aa43c215SJeff Kirsher },
670aa43c215SJeff Kirsher /* sw_int_mask */
671aa43c215SJeff Kirsher {
672aa43c215SJeff Kirsher CRB_SW_INT_MASK_3,
673aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
674aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
675aa43c215SJeff Kirsher NETXEN_NIC_REG_2(0x03c),
676aa43c215SJeff Kirsher },
677aa43c215SJeff Kirsher },
678aa43c215SJeff Kirsher };
679aa43c215SJeff Kirsher
680aa43c215SJeff Kirsher static int
netxen_init_old_ctx(struct netxen_adapter * adapter)681aa43c215SJeff Kirsher netxen_init_old_ctx(struct netxen_adapter *adapter)
682aa43c215SJeff Kirsher {
683aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx;
684aa43c215SJeff Kirsher struct nx_host_rds_ring *rds_ring;
685aa43c215SJeff Kirsher struct nx_host_sds_ring *sds_ring;
686aa43c215SJeff Kirsher struct nx_host_tx_ring *tx_ring;
687aa43c215SJeff Kirsher int ring;
688aa43c215SJeff Kirsher int port = adapter->portnum;
689aa43c215SJeff Kirsher struct netxen_ring_ctx *hwctx;
690aa43c215SJeff Kirsher u32 signature;
691aa43c215SJeff Kirsher
692aa43c215SJeff Kirsher tx_ring = adapter->tx_ring;
693aa43c215SJeff Kirsher recv_ctx = &adapter->recv_ctx;
694aa43c215SJeff Kirsher hwctx = recv_ctx->hwctx;
695aa43c215SJeff Kirsher
696aa43c215SJeff Kirsher hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr);
697aa43c215SJeff Kirsher hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc);
698aa43c215SJeff Kirsher
699aa43c215SJeff Kirsher
700aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) {
701aa43c215SJeff Kirsher rds_ring = &recv_ctx->rds_rings[ring];
702aa43c215SJeff Kirsher
703aa43c215SJeff Kirsher hwctx->rcv_rings[ring].addr =
704aa43c215SJeff Kirsher cpu_to_le64(rds_ring->phys_addr);
705aa43c215SJeff Kirsher hwctx->rcv_rings[ring].size =
706aa43c215SJeff Kirsher cpu_to_le32(rds_ring->num_desc);
707aa43c215SJeff Kirsher }
708aa43c215SJeff Kirsher
709aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) {
710aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring];
711aa43c215SJeff Kirsher
712aa43c215SJeff Kirsher if (ring == 0) {
713aa43c215SJeff Kirsher hwctx->sts_ring_addr = cpu_to_le64(sds_ring->phys_addr);
714aa43c215SJeff Kirsher hwctx->sts_ring_size = cpu_to_le32(sds_ring->num_desc);
715aa43c215SJeff Kirsher }
716aa43c215SJeff Kirsher hwctx->sts_rings[ring].addr = cpu_to_le64(sds_ring->phys_addr);
717aa43c215SJeff Kirsher hwctx->sts_rings[ring].size = cpu_to_le32(sds_ring->num_desc);
718aa43c215SJeff Kirsher hwctx->sts_rings[ring].msi_index = cpu_to_le16(ring);
719aa43c215SJeff Kirsher }
720aa43c215SJeff Kirsher hwctx->sts_ring_count = cpu_to_le32(adapter->max_sds_rings);
721aa43c215SJeff Kirsher
722aa43c215SJeff Kirsher signature = (adapter->max_sds_rings > 1) ?
723aa43c215SJeff Kirsher NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE;
724aa43c215SJeff Kirsher
725aa43c215SJeff Kirsher NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port),
726aa43c215SJeff Kirsher lower32(recv_ctx->phys_addr));
727aa43c215SJeff Kirsher NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port),
728aa43c215SJeff Kirsher upper32(recv_ctx->phys_addr));
729aa43c215SJeff Kirsher NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port),
730aa43c215SJeff Kirsher signature | port);
731aa43c215SJeff Kirsher return 0;
732aa43c215SJeff Kirsher }
733aa43c215SJeff Kirsher
netxen_alloc_hw_resources(struct netxen_adapter * adapter)734aa43c215SJeff Kirsher int netxen_alloc_hw_resources(struct netxen_adapter *adapter)
735aa43c215SJeff Kirsher {
736aa43c215SJeff Kirsher void *addr;
737aa43c215SJeff Kirsher int err = 0;
738aa43c215SJeff Kirsher int ring;
739aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx;
740aa43c215SJeff Kirsher struct nx_host_rds_ring *rds_ring;
741aa43c215SJeff Kirsher struct nx_host_sds_ring *sds_ring;
742aa43c215SJeff Kirsher struct nx_host_tx_ring *tx_ring;
743aa43c215SJeff Kirsher
744aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev;
745aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev;
746aa43c215SJeff Kirsher int port = adapter->portnum;
747aa43c215SJeff Kirsher
748aa43c215SJeff Kirsher recv_ctx = &adapter->recv_ctx;
749aa43c215SJeff Kirsher tx_ring = adapter->tx_ring;
750aa43c215SJeff Kirsher
751*297af515SChristophe JAILLET addr = dma_alloc_coherent(&pdev->dev,
752aa43c215SJeff Kirsher sizeof(struct netxen_ring_ctx) + sizeof(uint32_t),
753*297af515SChristophe JAILLET &recv_ctx->phys_addr, GFP_KERNEL);
754aa43c215SJeff Kirsher if (addr == NULL) {
755aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to allocate hw context\n");
756aa43c215SJeff Kirsher return -ENOMEM;
757aa43c215SJeff Kirsher }
758aa43c215SJeff Kirsher
759aa43c215SJeff Kirsher recv_ctx->hwctx = addr;
760aa43c215SJeff Kirsher recv_ctx->hwctx->ctx_id = cpu_to_le32(port);
761aa43c215SJeff Kirsher recv_ctx->hwctx->cmd_consumer_offset =
762aa43c215SJeff Kirsher cpu_to_le64(recv_ctx->phys_addr +
763aa43c215SJeff Kirsher sizeof(struct netxen_ring_ctx));
764aa43c215SJeff Kirsher tx_ring->hw_consumer =
765aa43c215SJeff Kirsher (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx));
766aa43c215SJeff Kirsher
767aa43c215SJeff Kirsher /* cmd desc ring */
768*297af515SChristophe JAILLET addr = dma_alloc_coherent(&pdev->dev, TX_DESC_RINGSIZE(tx_ring),
769*297af515SChristophe JAILLET &tx_ring->phys_addr, GFP_KERNEL);
770aa43c215SJeff Kirsher
771aa43c215SJeff Kirsher if (addr == NULL) {
772aa43c215SJeff Kirsher dev_err(&pdev->dev, "%s: failed to allocate tx desc ring\n",
773aa43c215SJeff Kirsher netdev->name);
774aa43c215SJeff Kirsher err = -ENOMEM;
775aa43c215SJeff Kirsher goto err_out_free;
776aa43c215SJeff Kirsher }
777aa43c215SJeff Kirsher
778aa43c215SJeff Kirsher tx_ring->desc_head = addr;
779aa43c215SJeff Kirsher
780aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) {
781aa43c215SJeff Kirsher rds_ring = &recv_ctx->rds_rings[ring];
782*297af515SChristophe JAILLET addr = dma_alloc_coherent(&adapter->pdev->dev,
783aa43c215SJeff Kirsher RCV_DESC_RINGSIZE(rds_ring),
784*297af515SChristophe JAILLET &rds_ring->phys_addr, GFP_KERNEL);
785aa43c215SJeff Kirsher if (addr == NULL) {
786aa43c215SJeff Kirsher dev_err(&pdev->dev,
787aa43c215SJeff Kirsher "%s: failed to allocate rds ring [%d]\n",
788aa43c215SJeff Kirsher netdev->name, ring);
789aa43c215SJeff Kirsher err = -ENOMEM;
790aa43c215SJeff Kirsher goto err_out_free;
791aa43c215SJeff Kirsher }
792aa43c215SJeff Kirsher rds_ring->desc_head = addr;
793aa43c215SJeff Kirsher
794aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
795aa43c215SJeff Kirsher rds_ring->crb_rcv_producer =
796aa43c215SJeff Kirsher netxen_get_ioaddr(adapter,
797aa43c215SJeff Kirsher recv_crb_registers[port].crb_rcv_producer[ring]);
798aa43c215SJeff Kirsher }
799aa43c215SJeff Kirsher
800aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) {
801aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring];
802aa43c215SJeff Kirsher
803*297af515SChristophe JAILLET addr = dma_alloc_coherent(&adapter->pdev->dev,
804aa43c215SJeff Kirsher STATUS_DESC_RINGSIZE(sds_ring),
805*297af515SChristophe JAILLET &sds_ring->phys_addr, GFP_KERNEL);
806aa43c215SJeff Kirsher if (addr == NULL) {
807aa43c215SJeff Kirsher dev_err(&pdev->dev,
808aa43c215SJeff Kirsher "%s: failed to allocate sds ring [%d]\n",
809aa43c215SJeff Kirsher netdev->name, ring);
810aa43c215SJeff Kirsher err = -ENOMEM;
811aa43c215SJeff Kirsher goto err_out_free;
812aa43c215SJeff Kirsher }
813aa43c215SJeff Kirsher sds_ring->desc_head = addr;
814aa43c215SJeff Kirsher
815aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
816aa43c215SJeff Kirsher sds_ring->crb_sts_consumer =
817aa43c215SJeff Kirsher netxen_get_ioaddr(adapter,
818aa43c215SJeff Kirsher recv_crb_registers[port].crb_sts_consumer[ring]);
819aa43c215SJeff Kirsher
820aa43c215SJeff Kirsher sds_ring->crb_intr_mask =
821aa43c215SJeff Kirsher netxen_get_ioaddr(adapter,
822aa43c215SJeff Kirsher recv_crb_registers[port].sw_int_mask[ring]);
823aa43c215SJeff Kirsher }
824aa43c215SJeff Kirsher }
825aa43c215SJeff Kirsher
826aa43c215SJeff Kirsher
827aa43c215SJeff Kirsher if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
828aa43c215SJeff Kirsher if (test_and_set_bit(__NX_FW_ATTACHED, &adapter->state))
829aa43c215SJeff Kirsher goto done;
830aa43c215SJeff Kirsher err = nx_fw_cmd_create_rx_ctx(adapter);
831aa43c215SJeff Kirsher if (err)
832aa43c215SJeff Kirsher goto err_out_free;
833aa43c215SJeff Kirsher err = nx_fw_cmd_create_tx_ctx(adapter);
834aa43c215SJeff Kirsher if (err)
835aa43c215SJeff Kirsher goto err_out_free;
836aa43c215SJeff Kirsher } else {
837aa43c215SJeff Kirsher err = netxen_init_old_ctx(adapter);
838aa43c215SJeff Kirsher if (err)
839aa43c215SJeff Kirsher goto err_out_free;
840aa43c215SJeff Kirsher }
841aa43c215SJeff Kirsher
842aa43c215SJeff Kirsher done:
843aa43c215SJeff Kirsher return 0;
844aa43c215SJeff Kirsher
845aa43c215SJeff Kirsher err_out_free:
846aa43c215SJeff Kirsher netxen_free_hw_resources(adapter);
847aa43c215SJeff Kirsher return err;
848aa43c215SJeff Kirsher }
849aa43c215SJeff Kirsher
netxen_free_hw_resources(struct netxen_adapter * adapter)850aa43c215SJeff Kirsher void netxen_free_hw_resources(struct netxen_adapter *adapter)
851aa43c215SJeff Kirsher {
852aa43c215SJeff Kirsher struct netxen_recv_context *recv_ctx;
853aa43c215SJeff Kirsher struct nx_host_rds_ring *rds_ring;
854aa43c215SJeff Kirsher struct nx_host_sds_ring *sds_ring;
855aa43c215SJeff Kirsher struct nx_host_tx_ring *tx_ring;
856aa43c215SJeff Kirsher int ring;
857aa43c215SJeff Kirsher
858aa43c215SJeff Kirsher int port = adapter->portnum;
859aa43c215SJeff Kirsher
860aa43c215SJeff Kirsher if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
861aa43c215SJeff Kirsher if (!test_and_clear_bit(__NX_FW_ATTACHED, &adapter->state))
862aa43c215SJeff Kirsher goto done;
863aa43c215SJeff Kirsher
864aa43c215SJeff Kirsher nx_fw_cmd_destroy_rx_ctx(adapter);
865aa43c215SJeff Kirsher nx_fw_cmd_destroy_tx_ctx(adapter);
866aa43c215SJeff Kirsher } else {
867aa43c215SJeff Kirsher netxen_api_lock(adapter);
868aa43c215SJeff Kirsher NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port),
869aa43c215SJeff Kirsher NETXEN_CTX_D3_RESET | port);
870aa43c215SJeff Kirsher netxen_api_unlock(adapter);
871aa43c215SJeff Kirsher }
872aa43c215SJeff Kirsher
873aa43c215SJeff Kirsher /* Allow dma queues to drain after context reset */
874aa43c215SJeff Kirsher msleep(20);
875aa43c215SJeff Kirsher
876aa43c215SJeff Kirsher done:
877aa43c215SJeff Kirsher recv_ctx = &adapter->recv_ctx;
878aa43c215SJeff Kirsher
879aa43c215SJeff Kirsher if (recv_ctx->hwctx != NULL) {
880*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev,
881*297af515SChristophe JAILLET sizeof(struct netxen_ring_ctx) + sizeof(uint32_t),
882*297af515SChristophe JAILLET recv_ctx->hwctx, recv_ctx->phys_addr);
883aa43c215SJeff Kirsher recv_ctx->hwctx = NULL;
884aa43c215SJeff Kirsher }
885aa43c215SJeff Kirsher
886aa43c215SJeff Kirsher tx_ring = adapter->tx_ring;
887aa43c215SJeff Kirsher if (tx_ring->desc_head != NULL) {
888*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev,
889aa43c215SJeff Kirsher TX_DESC_RINGSIZE(tx_ring),
890aa43c215SJeff Kirsher tx_ring->desc_head, tx_ring->phys_addr);
891aa43c215SJeff Kirsher tx_ring->desc_head = NULL;
892aa43c215SJeff Kirsher }
893aa43c215SJeff Kirsher
894aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) {
895aa43c215SJeff Kirsher rds_ring = &recv_ctx->rds_rings[ring];
896aa43c215SJeff Kirsher
897aa43c215SJeff Kirsher if (rds_ring->desc_head != NULL) {
898*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev,
899aa43c215SJeff Kirsher RCV_DESC_RINGSIZE(rds_ring),
900aa43c215SJeff Kirsher rds_ring->desc_head,
901aa43c215SJeff Kirsher rds_ring->phys_addr);
902aa43c215SJeff Kirsher rds_ring->desc_head = NULL;
903aa43c215SJeff Kirsher }
904aa43c215SJeff Kirsher }
905aa43c215SJeff Kirsher
906aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) {
907aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring];
908aa43c215SJeff Kirsher
909aa43c215SJeff Kirsher if (sds_ring->desc_head != NULL) {
910*297af515SChristophe JAILLET dma_free_coherent(&adapter->pdev->dev,
911aa43c215SJeff Kirsher STATUS_DESC_RINGSIZE(sds_ring),
912aa43c215SJeff Kirsher sds_ring->desc_head,
913aa43c215SJeff Kirsher sds_ring->phys_addr);
914aa43c215SJeff Kirsher sds_ring->desc_head = NULL;
915aa43c215SJeff Kirsher }
916aa43c215SJeff Kirsher }
917aa43c215SJeff Kirsher }
918aa43c215SJeff Kirsher
919