nfsd41: minor set_forechannel_maxreqs cleanup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / netxen / netxen_nic_ctx.c
blob4754f5cffad078ce53436b26330b6a0623ee4749
1 /*
2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * All rights reserved.
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,
18 * MA 02111-1307, USA.
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
24 * info@netxen.com
25 * NetXen Inc,
26 * 18922 Forge Drive
27 * Cupertino, CA 95014-0701
31 #include "netxen_nic_hw.h"
32 #include "netxen_nic.h"
33 #include "netxen_nic_phan_reg.h"
35 #define NXHAL_VERSION 1
37 static int
38 netxen_api_lock(struct netxen_adapter *adapter)
40 u32 done = 0, timeout = 0;
42 for (;;) {
43 /* Acquire PCIE HW semaphore5 */
44 done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM5_LOCK));
46 if (done == 1)
47 break;
49 if (++timeout >= NX_OS_CRB_RETRY_COUNT) {
50 printk(KERN_ERR "%s: lock timeout.\n", __func__);
51 return -1;
54 msleep(1);
57 #if 0
58 NXWR32(adapter,
59 NETXEN_API_LOCK_ID, NX_OS_API_LOCK_DRIVER);
60 #endif
61 return 0;
64 static int
65 netxen_api_unlock(struct netxen_adapter *adapter)
67 /* Release PCIE HW semaphore5 */
68 NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM5_UNLOCK));
69 return 0;
72 static u32
73 netxen_poll_rsp(struct netxen_adapter *adapter)
75 u32 rsp = NX_CDRP_RSP_OK;
76 int timeout = 0;
78 do {
79 /* give atleast 1ms for firmware to respond */
80 msleep(1);
82 if (++timeout > NX_OS_CRB_RETRY_COUNT)
83 return NX_CDRP_RSP_TIMEOUT;
85 rsp = NXRD32(adapter, NX_CDRP_CRB_OFFSET);
86 } while (!NX_CDRP_IS_RSP(rsp));
88 return rsp;
91 static u32
92 netxen_issue_cmd(struct netxen_adapter *adapter,
93 u32 pci_fn, u32 version, u32 arg1, u32 arg2, u32 arg3, u32 cmd)
95 u32 rsp;
96 u32 signature = 0;
97 u32 rcode = NX_RCODE_SUCCESS;
99 signature = NX_CDRP_SIGNATURE_MAKE(pci_fn, version);
101 /* Acquire semaphore before accessing CRB */
102 if (netxen_api_lock(adapter))
103 return NX_RCODE_TIMEOUT;
105 NXWR32(adapter, NX_SIGN_CRB_OFFSET, signature);
107 NXWR32(adapter, NX_ARG1_CRB_OFFSET, arg1);
109 NXWR32(adapter, NX_ARG2_CRB_OFFSET, arg2);
111 NXWR32(adapter, NX_ARG3_CRB_OFFSET, arg3);
113 NXWR32(adapter, NX_CDRP_CRB_OFFSET, NX_CDRP_FORM_CMD(cmd));
115 rsp = netxen_poll_rsp(adapter);
117 if (rsp == NX_CDRP_RSP_TIMEOUT) {
118 printk(KERN_ERR "%s: card response timeout.\n",
119 netxen_nic_driver_name);
121 rcode = NX_RCODE_TIMEOUT;
122 } else if (rsp == NX_CDRP_RSP_FAIL) {
123 rcode = NXRD32(adapter, NX_ARG1_CRB_OFFSET);
125 printk(KERN_ERR "%s: failed card response code:0x%x\n",
126 netxen_nic_driver_name, rcode);
129 /* Release semaphore */
130 netxen_api_unlock(adapter);
132 return rcode;
136 nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu)
138 u32 rcode = NX_RCODE_SUCCESS;
139 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
141 if (recv_ctx->state == NX_HOST_CTX_STATE_ACTIVE)
142 rcode = netxen_issue_cmd(adapter,
143 adapter->ahw.pci_func,
144 NXHAL_VERSION,
145 recv_ctx->context_id,
146 mtu,
148 NX_CDRP_CMD_SET_MTU);
150 if (rcode != NX_RCODE_SUCCESS)
151 return -EIO;
153 return 0;
156 static int
157 nx_fw_cmd_create_rx_ctx(struct netxen_adapter *adapter)
159 void *addr;
160 nx_hostrq_rx_ctx_t *prq;
161 nx_cardrsp_rx_ctx_t *prsp;
162 nx_hostrq_rds_ring_t *prq_rds;
163 nx_hostrq_sds_ring_t *prq_sds;
164 nx_cardrsp_rds_ring_t *prsp_rds;
165 nx_cardrsp_sds_ring_t *prsp_sds;
166 struct nx_host_rds_ring *rds_ring;
167 struct nx_host_sds_ring *sds_ring;
169 dma_addr_t hostrq_phys_addr, cardrsp_phys_addr;
170 u64 phys_addr;
172 int i, nrds_rings, nsds_rings;
173 size_t rq_size, rsp_size;
174 u32 cap, reg, val;
176 int err;
178 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
180 nrds_rings = adapter->max_rds_rings;
181 nsds_rings = adapter->max_sds_rings;
183 rq_size =
184 SIZEOF_HOSTRQ_RX(nx_hostrq_rx_ctx_t, nrds_rings, nsds_rings);
185 rsp_size =
186 SIZEOF_CARDRSP_RX(nx_cardrsp_rx_ctx_t, nrds_rings, nsds_rings);
188 addr = pci_alloc_consistent(adapter->pdev,
189 rq_size, &hostrq_phys_addr);
190 if (addr == NULL)
191 return -ENOMEM;
192 prq = (nx_hostrq_rx_ctx_t *)addr;
194 addr = pci_alloc_consistent(adapter->pdev,
195 rsp_size, &cardrsp_phys_addr);
196 if (addr == NULL) {
197 err = -ENOMEM;
198 goto out_free_rq;
200 prsp = (nx_cardrsp_rx_ctx_t *)addr;
202 prq->host_rsp_dma_addr = cpu_to_le64(cardrsp_phys_addr);
204 cap = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN);
205 cap |= (NX_CAP0_JUMBO_CONTIGUOUS | NX_CAP0_LRO_CONTIGUOUS);
207 prq->capabilities[0] = cpu_to_le32(cap);
208 prq->host_int_crb_mode =
209 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED);
210 prq->host_rds_crb_mode =
211 cpu_to_le32(NX_HOST_RDS_CRB_MODE_UNIQUE);
213 prq->num_rds_rings = cpu_to_le16(nrds_rings);
214 prq->num_sds_rings = cpu_to_le16(nsds_rings);
215 prq->rds_ring_offset = cpu_to_le32(0);
217 val = le32_to_cpu(prq->rds_ring_offset) +
218 (sizeof(nx_hostrq_rds_ring_t) * nrds_rings);
219 prq->sds_ring_offset = cpu_to_le32(val);
221 prq_rds = (nx_hostrq_rds_ring_t *)(prq->data +
222 le32_to_cpu(prq->rds_ring_offset));
224 for (i = 0; i < nrds_rings; i++) {
226 rds_ring = &recv_ctx->rds_rings[i];
228 prq_rds[i].host_phys_addr = cpu_to_le64(rds_ring->phys_addr);
229 prq_rds[i].ring_size = cpu_to_le32(rds_ring->num_desc);
230 prq_rds[i].ring_kind = cpu_to_le32(i);
231 prq_rds[i].buff_size = cpu_to_le64(rds_ring->dma_size);
234 prq_sds = (nx_hostrq_sds_ring_t *)(prq->data +
235 le32_to_cpu(prq->sds_ring_offset));
237 for (i = 0; i < nsds_rings; i++) {
239 sds_ring = &recv_ctx->sds_rings[i];
241 prq_sds[i].host_phys_addr = cpu_to_le64(sds_ring->phys_addr);
242 prq_sds[i].ring_size = cpu_to_le32(sds_ring->num_desc);
243 prq_sds[i].msi_index = cpu_to_le16(i);
246 phys_addr = hostrq_phys_addr;
247 err = netxen_issue_cmd(adapter,
248 adapter->ahw.pci_func,
249 NXHAL_VERSION,
250 (u32)(phys_addr >> 32),
251 (u32)(phys_addr & 0xffffffff),
252 rq_size,
253 NX_CDRP_CMD_CREATE_RX_CTX);
254 if (err) {
255 printk(KERN_WARNING
256 "Failed to create rx ctx in firmware%d\n", err);
257 goto out_free_rsp;
261 prsp_rds = ((nx_cardrsp_rds_ring_t *)
262 &prsp->data[le32_to_cpu(prsp->rds_ring_offset)]);
264 for (i = 0; i < le16_to_cpu(prsp->num_rds_rings); i++) {
265 rds_ring = &recv_ctx->rds_rings[i];
267 reg = le32_to_cpu(prsp_rds[i].host_producer_crb);
268 rds_ring->crb_rcv_producer = NETXEN_NIC_REG(reg - 0x200);
271 prsp_sds = ((nx_cardrsp_sds_ring_t *)
272 &prsp->data[le32_to_cpu(prsp->sds_ring_offset)]);
274 for (i = 0; i < le16_to_cpu(prsp->num_sds_rings); i++) {
275 sds_ring = &recv_ctx->sds_rings[i];
277 reg = le32_to_cpu(prsp_sds[i].host_consumer_crb);
278 sds_ring->crb_sts_consumer = NETXEN_NIC_REG(reg - 0x200);
280 reg = le32_to_cpu(prsp_sds[i].interrupt_crb);
281 sds_ring->crb_intr_mask = NETXEN_NIC_REG(reg - 0x200);
284 recv_ctx->state = le32_to_cpu(prsp->host_ctx_state);
285 recv_ctx->context_id = le16_to_cpu(prsp->context_id);
286 recv_ctx->virt_port = prsp->virt_port;
288 out_free_rsp:
289 pci_free_consistent(adapter->pdev, rsp_size, prsp, cardrsp_phys_addr);
290 out_free_rq:
291 pci_free_consistent(adapter->pdev, rq_size, prq, hostrq_phys_addr);
292 return err;
295 static void
296 nx_fw_cmd_destroy_rx_ctx(struct netxen_adapter *adapter)
298 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
300 if (netxen_issue_cmd(adapter,
301 adapter->ahw.pci_func,
302 NXHAL_VERSION,
303 recv_ctx->context_id,
304 NX_DESTROY_CTX_RESET,
306 NX_CDRP_CMD_DESTROY_RX_CTX)) {
308 printk(KERN_WARNING
309 "%s: Failed to destroy rx ctx in firmware\n",
310 netxen_nic_driver_name);
314 static int
315 nx_fw_cmd_create_tx_ctx(struct netxen_adapter *adapter)
317 nx_hostrq_tx_ctx_t *prq;
318 nx_hostrq_cds_ring_t *prq_cds;
319 nx_cardrsp_tx_ctx_t *prsp;
320 void *rq_addr, *rsp_addr;
321 size_t rq_size, rsp_size;
322 u32 temp;
323 int err = 0;
324 u64 offset, phys_addr;
325 dma_addr_t rq_phys_addr, rsp_phys_addr;
326 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
327 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
329 rq_size = SIZEOF_HOSTRQ_TX(nx_hostrq_tx_ctx_t);
330 rq_addr = pci_alloc_consistent(adapter->pdev,
331 rq_size, &rq_phys_addr);
332 if (!rq_addr)
333 return -ENOMEM;
335 rsp_size = SIZEOF_CARDRSP_TX(nx_cardrsp_tx_ctx_t);
336 rsp_addr = pci_alloc_consistent(adapter->pdev,
337 rsp_size, &rsp_phys_addr);
338 if (!rsp_addr) {
339 err = -ENOMEM;
340 goto out_free_rq;
343 memset(rq_addr, 0, rq_size);
344 prq = (nx_hostrq_tx_ctx_t *)rq_addr;
346 memset(rsp_addr, 0, rsp_size);
347 prsp = (nx_cardrsp_tx_ctx_t *)rsp_addr;
349 prq->host_rsp_dma_addr = cpu_to_le64(rsp_phys_addr);
351 temp = (NX_CAP0_LEGACY_CONTEXT | NX_CAP0_LEGACY_MN | NX_CAP0_LSO);
352 prq->capabilities[0] = cpu_to_le32(temp);
354 prq->host_int_crb_mode =
355 cpu_to_le32(NX_HOST_INT_CRB_MODE_SHARED);
357 prq->interrupt_ctl = 0;
358 prq->msi_index = 0;
360 prq->dummy_dma_addr = cpu_to_le64(adapter->dummy_dma.phys_addr);
362 offset = recv_ctx->phys_addr + sizeof(struct netxen_ring_ctx);
363 prq->cmd_cons_dma_addr = cpu_to_le64(offset);
365 prq_cds = &prq->cds_ring;
367 prq_cds->host_phys_addr = cpu_to_le64(tx_ring->phys_addr);
368 prq_cds->ring_size = cpu_to_le32(tx_ring->num_desc);
370 phys_addr = rq_phys_addr;
371 err = netxen_issue_cmd(adapter,
372 adapter->ahw.pci_func,
373 NXHAL_VERSION,
374 (u32)(phys_addr >> 32),
375 ((u32)phys_addr & 0xffffffff),
376 rq_size,
377 NX_CDRP_CMD_CREATE_TX_CTX);
379 if (err == NX_RCODE_SUCCESS) {
380 temp = le32_to_cpu(prsp->cds_ring.host_producer_crb);
381 tx_ring->crb_cmd_producer = NETXEN_NIC_REG(temp - 0x200);
382 #if 0
383 adapter->tx_state =
384 le32_to_cpu(prsp->host_ctx_state);
385 #endif
386 adapter->tx_context_id =
387 le16_to_cpu(prsp->context_id);
388 } else {
389 printk(KERN_WARNING
390 "Failed to create tx ctx in firmware%d\n", err);
391 err = -EIO;
394 pci_free_consistent(adapter->pdev, rsp_size, rsp_addr, rsp_phys_addr);
396 out_free_rq:
397 pci_free_consistent(adapter->pdev, rq_size, rq_addr, rq_phys_addr);
399 return err;
402 static void
403 nx_fw_cmd_destroy_tx_ctx(struct netxen_adapter *adapter)
405 if (netxen_issue_cmd(adapter,
406 adapter->ahw.pci_func,
407 NXHAL_VERSION,
408 adapter->tx_context_id,
409 NX_DESTROY_CTX_RESET,
411 NX_CDRP_CMD_DESTROY_TX_CTX)) {
413 printk(KERN_WARNING
414 "%s: Failed to destroy tx ctx in firmware\n",
415 netxen_nic_driver_name);
419 static u64 ctx_addr_sig_regs[][3] = {
420 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
421 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
422 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
423 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
426 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
427 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
428 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
430 #define lower32(x) ((u32)((x) & 0xffffffff))
431 #define upper32(x) ((u32)(((u64)(x) >> 32) & 0xffffffff))
433 static struct netxen_recv_crb recv_crb_registers[] = {
434 /* Instance 0 */
436 /* crb_rcv_producer: */
438 NETXEN_NIC_REG(0x100),
439 /* Jumbo frames */
440 NETXEN_NIC_REG(0x110),
441 /* LRO */
442 NETXEN_NIC_REG(0x120)
444 /* crb_sts_consumer: */
446 NETXEN_NIC_REG(0x138),
447 NETXEN_NIC_REG_2(0x000),
448 NETXEN_NIC_REG_2(0x004),
449 NETXEN_NIC_REG_2(0x008),
451 /* sw_int_mask */
453 CRB_SW_INT_MASK_0,
454 NETXEN_NIC_REG_2(0x044),
455 NETXEN_NIC_REG_2(0x048),
456 NETXEN_NIC_REG_2(0x04c),
459 /* Instance 1 */
461 /* crb_rcv_producer: */
463 NETXEN_NIC_REG(0x144),
464 /* Jumbo frames */
465 NETXEN_NIC_REG(0x154),
466 /* LRO */
467 NETXEN_NIC_REG(0x164)
469 /* crb_sts_consumer: */
471 NETXEN_NIC_REG(0x17c),
472 NETXEN_NIC_REG_2(0x020),
473 NETXEN_NIC_REG_2(0x024),
474 NETXEN_NIC_REG_2(0x028),
476 /* sw_int_mask */
478 CRB_SW_INT_MASK_1,
479 NETXEN_NIC_REG_2(0x064),
480 NETXEN_NIC_REG_2(0x068),
481 NETXEN_NIC_REG_2(0x06c),
484 /* Instance 2 */
486 /* crb_rcv_producer: */
488 NETXEN_NIC_REG(0x1d8),
489 /* Jumbo frames */
490 NETXEN_NIC_REG(0x1f8),
491 /* LRO */
492 NETXEN_NIC_REG(0x208)
494 /* crb_sts_consumer: */
496 NETXEN_NIC_REG(0x220),
497 NETXEN_NIC_REG_2(0x03c),
498 NETXEN_NIC_REG_2(0x03c),
499 NETXEN_NIC_REG_2(0x03c),
501 /* sw_int_mask */
503 CRB_SW_INT_MASK_2,
504 NETXEN_NIC_REG_2(0x03c),
505 NETXEN_NIC_REG_2(0x03c),
506 NETXEN_NIC_REG_2(0x03c),
509 /* Instance 3 */
511 /* crb_rcv_producer: */
513 NETXEN_NIC_REG(0x22c),
514 /* Jumbo frames */
515 NETXEN_NIC_REG(0x23c),
516 /* LRO */
517 NETXEN_NIC_REG(0x24c)
519 /* crb_sts_consumer: */
521 NETXEN_NIC_REG(0x264),
522 NETXEN_NIC_REG_2(0x03c),
523 NETXEN_NIC_REG_2(0x03c),
524 NETXEN_NIC_REG_2(0x03c),
526 /* sw_int_mask */
528 CRB_SW_INT_MASK_3,
529 NETXEN_NIC_REG_2(0x03c),
530 NETXEN_NIC_REG_2(0x03c),
531 NETXEN_NIC_REG_2(0x03c),
536 static int
537 netxen_init_old_ctx(struct netxen_adapter *adapter)
539 struct netxen_recv_context *recv_ctx;
540 struct nx_host_rds_ring *rds_ring;
541 struct nx_host_sds_ring *sds_ring;
542 struct nx_host_tx_ring *tx_ring;
543 int ring;
544 int port = adapter->portnum;
545 struct netxen_ring_ctx *hwctx;
546 u32 signature;
548 tx_ring = adapter->tx_ring;
549 recv_ctx = &adapter->recv_ctx;
550 hwctx = recv_ctx->hwctx;
552 hwctx->cmd_ring_addr = cpu_to_le64(tx_ring->phys_addr);
553 hwctx->cmd_ring_size = cpu_to_le32(tx_ring->num_desc);
556 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
557 rds_ring = &recv_ctx->rds_rings[ring];
559 hwctx->rcv_rings[ring].addr =
560 cpu_to_le64(rds_ring->phys_addr);
561 hwctx->rcv_rings[ring].size =
562 cpu_to_le32(rds_ring->num_desc);
565 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
566 sds_ring = &recv_ctx->sds_rings[ring];
568 if (ring == 0) {
569 hwctx->sts_ring_addr = cpu_to_le64(sds_ring->phys_addr);
570 hwctx->sts_ring_size = cpu_to_le32(sds_ring->num_desc);
572 hwctx->sts_rings[ring].addr = cpu_to_le64(sds_ring->phys_addr);
573 hwctx->sts_rings[ring].size = cpu_to_le32(sds_ring->num_desc);
574 hwctx->sts_rings[ring].msi_index = cpu_to_le16(ring);
576 hwctx->sts_ring_count = cpu_to_le32(adapter->max_sds_rings);
578 signature = (adapter->max_sds_rings > 1) ?
579 NETXEN_CTX_SIGNATURE_V2 : NETXEN_CTX_SIGNATURE;
581 NXWR32(adapter, CRB_CTX_ADDR_REG_LO(port),
582 lower32(recv_ctx->phys_addr));
583 NXWR32(adapter, CRB_CTX_ADDR_REG_HI(port),
584 upper32(recv_ctx->phys_addr));
585 NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port),
586 signature | port);
587 return 0;
590 int netxen_alloc_hw_resources(struct netxen_adapter *adapter)
592 void *addr;
593 int err = 0;
594 int ring;
595 struct netxen_recv_context *recv_ctx;
596 struct nx_host_rds_ring *rds_ring;
597 struct nx_host_sds_ring *sds_ring;
598 struct nx_host_tx_ring *tx_ring;
600 struct pci_dev *pdev = adapter->pdev;
601 struct net_device *netdev = adapter->netdev;
602 int port = adapter->portnum;
604 recv_ctx = &adapter->recv_ctx;
605 tx_ring = adapter->tx_ring;
607 addr = pci_alloc_consistent(pdev,
608 sizeof(struct netxen_ring_ctx) + sizeof(uint32_t),
609 &recv_ctx->phys_addr);
610 if (addr == NULL) {
611 dev_err(&pdev->dev, "failed to allocate hw context\n");
612 return -ENOMEM;
615 memset(addr, 0, sizeof(struct netxen_ring_ctx));
616 recv_ctx->hwctx = (struct netxen_ring_ctx *)addr;
617 recv_ctx->hwctx->ctx_id = cpu_to_le32(port);
618 recv_ctx->hwctx->cmd_consumer_offset =
619 cpu_to_le64(recv_ctx->phys_addr +
620 sizeof(struct netxen_ring_ctx));
621 tx_ring->hw_consumer =
622 (__le32 *)(((char *)addr) + sizeof(struct netxen_ring_ctx));
624 /* cmd desc ring */
625 addr = pci_alloc_consistent(pdev, TX_DESC_RINGSIZE(tx_ring),
626 &tx_ring->phys_addr);
628 if (addr == NULL) {
629 dev_err(&pdev->dev, "%s: failed to allocate tx desc ring\n",
630 netdev->name);
631 return -ENOMEM;
634 tx_ring->desc_head = (struct cmd_desc_type0 *)addr;
636 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
637 rds_ring = &recv_ctx->rds_rings[ring];
638 addr = pci_alloc_consistent(adapter->pdev,
639 RCV_DESC_RINGSIZE(rds_ring),
640 &rds_ring->phys_addr);
641 if (addr == NULL) {
642 dev_err(&pdev->dev,
643 "%s: failed to allocate rds ring [%d]\n",
644 netdev->name, ring);
645 err = -ENOMEM;
646 goto err_out_free;
648 rds_ring->desc_head = (struct rcv_desc *)addr;
650 if (adapter->fw_major < 4)
651 rds_ring->crb_rcv_producer =
652 recv_crb_registers[port].crb_rcv_producer[ring];
655 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
656 sds_ring = &recv_ctx->sds_rings[ring];
658 addr = pci_alloc_consistent(adapter->pdev,
659 STATUS_DESC_RINGSIZE(sds_ring),
660 &sds_ring->phys_addr);
661 if (addr == NULL) {
662 dev_err(&pdev->dev,
663 "%s: failed to allocate sds ring [%d]\n",
664 netdev->name, ring);
665 err = -ENOMEM;
666 goto err_out_free;
668 sds_ring->desc_head = (struct status_desc *)addr;
670 sds_ring->crb_sts_consumer =
671 recv_crb_registers[port].crb_sts_consumer[ring];
673 sds_ring->crb_intr_mask =
674 recv_crb_registers[port].sw_int_mask[ring];
678 if (adapter->fw_major >= 4) {
679 err = nx_fw_cmd_create_rx_ctx(adapter);
680 if (err)
681 goto err_out_free;
682 err = nx_fw_cmd_create_tx_ctx(adapter);
683 if (err)
684 goto err_out_free;
685 } else {
686 err = netxen_init_old_ctx(adapter);
687 if (err) {
688 netxen_free_hw_resources(adapter);
689 return err;
693 return 0;
695 err_out_free:
696 netxen_free_hw_resources(adapter);
697 return err;
700 void netxen_free_hw_resources(struct netxen_adapter *adapter)
702 struct netxen_recv_context *recv_ctx;
703 struct nx_host_rds_ring *rds_ring;
704 struct nx_host_sds_ring *sds_ring;
705 struct nx_host_tx_ring *tx_ring;
706 int ring;
708 int port = adapter->portnum;
710 if (adapter->fw_major >= 4) {
711 nx_fw_cmd_destroy_tx_ctx(adapter);
712 nx_fw_cmd_destroy_rx_ctx(adapter);
713 } else {
714 netxen_api_lock(adapter);
715 NXWR32(adapter, CRB_CTX_SIGNATURE_REG(port),
716 NETXEN_CTX_RESET | port);
717 netxen_api_unlock(adapter);
720 recv_ctx = &adapter->recv_ctx;
722 if (recv_ctx->hwctx != NULL) {
723 pci_free_consistent(adapter->pdev,
724 sizeof(struct netxen_ring_ctx) +
725 sizeof(uint32_t),
726 recv_ctx->hwctx,
727 recv_ctx->phys_addr);
728 recv_ctx->hwctx = NULL;
731 tx_ring = adapter->tx_ring;
732 if (tx_ring->desc_head != NULL) {
733 pci_free_consistent(adapter->pdev,
734 TX_DESC_RINGSIZE(tx_ring),
735 tx_ring->desc_head, tx_ring->phys_addr);
736 tx_ring->desc_head = NULL;
739 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
740 rds_ring = &recv_ctx->rds_rings[ring];
742 if (rds_ring->desc_head != NULL) {
743 pci_free_consistent(adapter->pdev,
744 RCV_DESC_RINGSIZE(rds_ring),
745 rds_ring->desc_head,
746 rds_ring->phys_addr);
747 rds_ring->desc_head = NULL;
751 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
752 sds_ring = &recv_ctx->sds_rings[ring];
754 if (sds_ring->desc_head != NULL) {
755 pci_free_consistent(adapter->pdev,
756 STATUS_DESC_RINGSIZE(sds_ring),
757 sds_ring->desc_head,
758 sds_ring->phys_addr);
759 sds_ring->desc_head = NULL;