Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
Dhananjay Phadke | 5d242f1 | 2009-02-25 15:57:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 - 2009 NetXen, Inc. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
Dhananjay Phadke | 5d242f1 | 2009-02-25 15:57:56 +0000 | [diff] [blame] | 25 | * NetXen Inc, |
| 26 | * 18922 Forge Drive |
| 27 | * Cupertino, CA 95014-0701 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include "netxen_nic.h" |
| 34 | #include "netxen_nic_hw.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 35 | #include "netxen_nic_phan_reg.h" |
| 36 | |
| 37 | struct crb_addr_pair { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 38 | u32 addr; |
| 39 | u32 data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | #define NETXEN_MAX_CRB_XFORM 60 |
| 43 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 44 | #define NETXEN_ADDR_ERROR (0xffffffff) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 45 | |
| 46 | #define crb_addr_transform(name) \ |
| 47 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ |
| 48 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 |
| 49 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 50 | #define NETXEN_NIC_XDMA_RESET 0x8000ff |
| 51 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 52 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 53 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 54 | struct nx_host_rds_ring *rds_ring); |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 55 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 56 | static void crb_addr_transform_setup(void) |
| 57 | { |
| 58 | crb_addr_transform(XDMA); |
| 59 | crb_addr_transform(TIMR); |
| 60 | crb_addr_transform(SRE); |
| 61 | crb_addr_transform(SQN3); |
| 62 | crb_addr_transform(SQN2); |
| 63 | crb_addr_transform(SQN1); |
| 64 | crb_addr_transform(SQN0); |
| 65 | crb_addr_transform(SQS3); |
| 66 | crb_addr_transform(SQS2); |
| 67 | crb_addr_transform(SQS1); |
| 68 | crb_addr_transform(SQS0); |
| 69 | crb_addr_transform(RPMX7); |
| 70 | crb_addr_transform(RPMX6); |
| 71 | crb_addr_transform(RPMX5); |
| 72 | crb_addr_transform(RPMX4); |
| 73 | crb_addr_transform(RPMX3); |
| 74 | crb_addr_transform(RPMX2); |
| 75 | crb_addr_transform(RPMX1); |
| 76 | crb_addr_transform(RPMX0); |
| 77 | crb_addr_transform(ROMUSB); |
| 78 | crb_addr_transform(SN); |
| 79 | crb_addr_transform(QMN); |
| 80 | crb_addr_transform(QMS); |
| 81 | crb_addr_transform(PGNI); |
| 82 | crb_addr_transform(PGND); |
| 83 | crb_addr_transform(PGN3); |
| 84 | crb_addr_transform(PGN2); |
| 85 | crb_addr_transform(PGN1); |
| 86 | crb_addr_transform(PGN0); |
| 87 | crb_addr_transform(PGSI); |
| 88 | crb_addr_transform(PGSD); |
| 89 | crb_addr_transform(PGS3); |
| 90 | crb_addr_transform(PGS2); |
| 91 | crb_addr_transform(PGS1); |
| 92 | crb_addr_transform(PGS0); |
| 93 | crb_addr_transform(PS); |
| 94 | crb_addr_transform(PH); |
| 95 | crb_addr_transform(NIU); |
| 96 | crb_addr_transform(I2Q); |
| 97 | crb_addr_transform(EG); |
| 98 | crb_addr_transform(MN); |
| 99 | crb_addr_transform(MS); |
| 100 | crb_addr_transform(CAS2); |
| 101 | crb_addr_transform(CAS1); |
| 102 | crb_addr_transform(CAS0); |
| 103 | crb_addr_transform(CAM); |
| 104 | crb_addr_transform(C2C1); |
| 105 | crb_addr_transform(C2C0); |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 106 | crb_addr_transform(SMB); |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 107 | crb_addr_transform(OCM0); |
| 108 | crb_addr_transform(I2C0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 111 | void netxen_release_rx_buffers(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 112 | { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 113 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 114 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 115 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 116 | int i, ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 117 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 118 | recv_ctx = &adapter->recv_ctx; |
| 119 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 120 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 121 | for (i = 0; i < rds_ring->num_desc; ++i) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 122 | rx_buf = &(rds_ring->rx_buf_arr[i]); |
| 123 | if (rx_buf->state == NETXEN_BUFFER_FREE) |
| 124 | continue; |
| 125 | pci_unmap_single(adapter->pdev, |
| 126 | rx_buf->dma, |
| 127 | rds_ring->dma_size, |
| 128 | PCI_DMA_FROMDEVICE); |
| 129 | if (rx_buf->skb != NULL) |
| 130 | dev_kfree_skb_any(rx_buf->skb); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void netxen_release_tx_buffers(struct netxen_adapter *adapter) |
| 136 | { |
| 137 | struct netxen_cmd_buffer *cmd_buf; |
| 138 | struct netxen_skb_frag *buffrag; |
| 139 | int i, j; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 140 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 141 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 142 | cmd_buf = tx_ring->cmd_buf_arr; |
| 143 | for (i = 0; i < tx_ring->num_desc; i++) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 144 | buffrag = cmd_buf->frag_array; |
| 145 | if (buffrag->dma) { |
| 146 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 147 | buffrag->length, PCI_DMA_TODEVICE); |
| 148 | buffrag->dma = 0ULL; |
| 149 | } |
| 150 | for (j = 0; j < cmd_buf->frag_count; j++) { |
| 151 | buffrag++; |
| 152 | if (buffrag->dma) { |
| 153 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 154 | buffrag->length, |
| 155 | PCI_DMA_TODEVICE); |
| 156 | buffrag->dma = 0ULL; |
| 157 | } |
| 158 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 159 | if (cmd_buf->skb) { |
| 160 | dev_kfree_skb_any(cmd_buf->skb); |
| 161 | cmd_buf->skb = NULL; |
| 162 | } |
| 163 | cmd_buf++; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | void netxen_free_sw_resources(struct netxen_adapter *adapter) |
| 168 | { |
| 169 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 170 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 171 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 172 | int ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 173 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 174 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 175 | |
| 176 | if (recv_ctx->rds_rings == NULL) |
| 177 | goto skip_rds; |
| 178 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 179 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 180 | rds_ring = &recv_ctx->rds_rings[ring]; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 181 | vfree(rds_ring->rx_buf_arr); |
| 182 | rds_ring->rx_buf_arr = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 183 | } |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 184 | kfree(recv_ctx->rds_rings); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 185 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 186 | skip_rds: |
| 187 | if (adapter->tx_ring == NULL) |
| 188 | return; |
| 189 | |
| 190 | tx_ring = adapter->tx_ring; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 191 | vfree(tx_ring->cmd_buf_arr); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | int netxen_alloc_sw_resources(struct netxen_adapter *adapter) |
| 195 | { |
| 196 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 197 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 198 | struct nx_host_sds_ring *sds_ring; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 199 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 200 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 201 | int ring, i, size; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 202 | |
| 203 | struct netxen_cmd_buffer *cmd_buf_arr; |
| 204 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 205 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 206 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 207 | size = sizeof(struct nx_host_tx_ring); |
| 208 | tx_ring = kzalloc(size, GFP_KERNEL); |
| 209 | if (tx_ring == NULL) { |
| 210 | dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n", |
| 211 | netdev->name); |
| 212 | return -ENOMEM; |
| 213 | } |
| 214 | adapter->tx_ring = tx_ring; |
| 215 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 216 | tx_ring->num_desc = adapter->num_txd; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 217 | |
| 218 | cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 219 | if (cmd_buf_arr == NULL) { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 220 | dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 221 | netdev->name); |
| 222 | return -ENOMEM; |
| 223 | } |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 224 | memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); |
| 225 | tx_ring->cmd_buf_arr = cmd_buf_arr; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 226 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 227 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 228 | |
| 229 | size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring); |
| 230 | rds_ring = kzalloc(size, GFP_KERNEL); |
| 231 | if (rds_ring == NULL) { |
| 232 | dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n", |
| 233 | netdev->name); |
| 234 | return -ENOMEM; |
| 235 | } |
| 236 | recv_ctx->rds_rings = rds_ring; |
| 237 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 238 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 239 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 240 | switch (ring) { |
| 241 | case RCV_RING_NORMAL: |
| 242 | rds_ring->num_desc = adapter->num_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 243 | if (adapter->ahw.cut_through) { |
| 244 | rds_ring->dma_size = |
| 245 | NX_CT_DEFAULT_RX_BUF_LEN; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 246 | rds_ring->skb_size = |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 247 | NX_CT_DEFAULT_RX_BUF_LEN; |
| 248 | } else { |
| 249 | rds_ring->dma_size = RX_DMA_MAP_LEN; |
| 250 | rds_ring->skb_size = |
| 251 | MAX_RX_BUFFER_LENGTH; |
| 252 | } |
| 253 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 254 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 255 | case RCV_RING_JUMBO: |
| 256 | rds_ring->num_desc = adapter->num_jumbo_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 257 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 258 | rds_ring->dma_size = |
| 259 | NX_P3_RX_JUMBO_BUF_MAX_LEN; |
| 260 | else |
| 261 | rds_ring->dma_size = |
| 262 | NX_P2_RX_JUMBO_BUF_MAX_LEN; |
| 263 | rds_ring->skb_size = |
| 264 | rds_ring->dma_size + NET_IP_ALIGN; |
| 265 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 266 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 267 | case RCV_RING_LRO: |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 268 | rds_ring->num_desc = adapter->num_lro_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 269 | rds_ring->dma_size = RX_LRO_DMA_MAP_LEN; |
| 270 | rds_ring->skb_size = MAX_RX_LRO_BUFFER_LENGTH; |
| 271 | break; |
| 272 | |
| 273 | } |
| 274 | rds_ring->rx_buf_arr = (struct netxen_rx_buffer *) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 275 | vmalloc(RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 276 | if (rds_ring->rx_buf_arr == NULL) { |
| 277 | printk(KERN_ERR "%s: Failed to allocate " |
| 278 | "rx buffer ring %d\n", |
| 279 | netdev->name, ring); |
| 280 | /* free whatever was already allocated */ |
| 281 | goto err_out; |
| 282 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 283 | memset(rds_ring->rx_buf_arr, 0, RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 284 | INIT_LIST_HEAD(&rds_ring->free_list); |
| 285 | /* |
| 286 | * Now go through all of them, set reference handles |
| 287 | * and put them in the queues. |
| 288 | */ |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 289 | rx_buf = rds_ring->rx_buf_arr; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 290 | for (i = 0; i < rds_ring->num_desc; i++) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 291 | list_add_tail(&rx_buf->list, |
| 292 | &rds_ring->free_list); |
| 293 | rx_buf->ref_handle = i; |
| 294 | rx_buf->state = NETXEN_BUFFER_FREE; |
| 295 | rx_buf++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 296 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 297 | spin_lock_init(&rds_ring->lock); |
| 298 | } |
| 299 | |
| 300 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 301 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 302 | sds_ring->irq = adapter->msix_entries[ring].vector; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 303 | sds_ring->adapter = adapter; |
| 304 | sds_ring->num_desc = adapter->num_rxd; |
| 305 | |
| 306 | for (i = 0; i < NUM_RCV_DESC_RINGS; i++) |
| 307 | INIT_LIST_HEAD(&sds_ring->free_list[i]); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 308 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 309 | |
| 310 | return 0; |
| 311 | |
| 312 | err_out: |
| 313 | netxen_free_sw_resources(adapter); |
| 314 | return -ENOMEM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 317 | void netxen_initialize_adapter_ops(struct netxen_adapter *adapter) |
| 318 | { |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 319 | adapter->macaddr_set = netxen_p2_nic_set_mac_addr; |
| 320 | adapter->set_multi = netxen_p2_nic_set_multi; |
| 321 | |
Dhananjay Phadke | 1e2d005 | 2009-03-09 08:50:56 +0000 | [diff] [blame] | 322 | switch (adapter->ahw.port_type) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 323 | case NETXEN_NIC_GBE: |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 324 | adapter->enable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 325 | netxen_niu_gbe_enable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 326 | adapter->disable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 327 | netxen_niu_gbe_disable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 328 | adapter->set_mtu = netxen_nic_set_mtu_gb; |
| 329 | adapter->set_promisc = netxen_niu_set_promiscuous_mode; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 330 | adapter->phy_read = netxen_niu_gbe_phy_read; |
| 331 | adapter->phy_write = netxen_niu_gbe_phy_write; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 332 | adapter->init_port = netxen_niu_gbe_init_port; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 333 | adapter->stop_port = netxen_niu_disable_gbe_port; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 334 | break; |
| 335 | |
| 336 | case NETXEN_NIC_XGBE: |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 337 | adapter->enable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 338 | netxen_niu_xgbe_enable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 339 | adapter->disable_phy_interrupts = |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 340 | netxen_niu_xgbe_disable_phy_interrupts; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 341 | adapter->set_mtu = netxen_nic_set_mtu_xgb; |
| 342 | adapter->init_port = netxen_niu_xg_init_port; |
| 343 | adapter->set_promisc = netxen_niu_xg_set_promiscuous_mode; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 344 | adapter->stop_port = netxen_niu_disable_xg_port; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 345 | break; |
| 346 | |
| 347 | default: |
| 348 | break; |
| 349 | } |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 350 | |
| 351 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 352 | adapter->set_mtu = nx_fw_cmd_set_mtu; |
| 353 | adapter->set_promisc = netxen_p3_nic_set_promisc; |
Dhananjay Phadke | 3d0a3cc | 2009-05-05 19:05:08 +0000 | [diff] [blame] | 354 | adapter->macaddr_set = netxen_p3_nic_set_mac_addr; |
| 355 | adapter->set_multi = netxen_p3_nic_set_multi; |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 356 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* |
| 360 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB |
| 361 | * address to external PCI CRB address. |
| 362 | */ |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 363 | static u32 netxen_decode_crb_addr(u32 addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 364 | { |
| 365 | int i; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 366 | u32 base_addr, offset, pci_base; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 367 | |
| 368 | crb_addr_transform_setup(); |
| 369 | |
| 370 | pci_base = NETXEN_ADDR_ERROR; |
| 371 | base_addr = addr & 0xfff00000; |
| 372 | offset = addr & 0x000fffff; |
| 373 | |
| 374 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { |
| 375 | if (crb_addr_xform[i] == base_addr) { |
| 376 | pci_base = i << 20; |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | if (pci_base == NETXEN_ADDR_ERROR) |
| 381 | return pci_base; |
| 382 | else |
| 383 | return (pci_base + offset); |
| 384 | } |
| 385 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 386 | static long rom_max_timeout = 100; |
| 387 | static long rom_lock_timeout = 10000; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 388 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 389 | static int rom_lock(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 390 | { |
| 391 | int iter; |
| 392 | u32 done = 0; |
| 393 | int timeout = 0; |
| 394 | |
| 395 | while (!done) { |
| 396 | /* acquire semaphore2 from PCI HW block */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 397 | done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM2_LOCK)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 398 | if (done == 1) |
| 399 | break; |
| 400 | if (timeout >= rom_lock_timeout) |
| 401 | return -EIO; |
| 402 | |
| 403 | timeout++; |
| 404 | /* |
| 405 | * Yield CPU |
| 406 | */ |
| 407 | if (!in_atomic()) |
| 408 | schedule(); |
| 409 | else { |
| 410 | for (iter = 0; iter < 20; iter++) |
| 411 | cpu_relax(); /*This a nop instr on i386 */ |
| 412 | } |
| 413 | } |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 414 | NXWR32(adapter, NETXEN_ROM_LOCK_ID, ROM_LOCK_DRIVER); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 418 | static int netxen_wait_rom_done(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 419 | { |
| 420 | long timeout = 0; |
| 421 | long done = 0; |
| 422 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 423 | cond_resched(); |
| 424 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 425 | while (done == 0) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 426 | done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 427 | done &= 2; |
| 428 | timeout++; |
| 429 | if (timeout >= rom_max_timeout) { |
| 430 | printk("Timeout reached waiting for rom done"); |
| 431 | return -EIO; |
| 432 | } |
| 433 | } |
| 434 | return 0; |
| 435 | } |
| 436 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 437 | static void netxen_rom_unlock(struct netxen_adapter *adapter) |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 438 | { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 439 | /* release semaphore2 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 440 | NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM2_UNLOCK)); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 441 | |
| 442 | } |
| 443 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 444 | static int do_rom_fast_read(struct netxen_adapter *adapter, |
| 445 | int addr, int *valp) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 446 | { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 447 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 448 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 449 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
| 450 | NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 451 | if (netxen_wait_rom_done(adapter)) { |
| 452 | printk("Error waiting for rom done\n"); |
| 453 | return -EIO; |
| 454 | } |
| 455 | /* reset abyte_cnt and dummy_byte_cnt */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 456 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 457 | udelay(10); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 458 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 459 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 460 | *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 464 | static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
| 465 | u8 *bytes, size_t size) |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 466 | { |
| 467 | int addridx; |
| 468 | int ret = 0; |
| 469 | |
| 470 | for (addridx = addr; addridx < (addr + size); addridx += 4) { |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 471 | int v; |
| 472 | ret = do_rom_fast_read(adapter, addridx, &v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 473 | if (ret != 0) |
| 474 | break; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 475 | *(__le32 *)bytes = cpu_to_le32(v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 476 | bytes += 4; |
| 477 | } |
| 478 | |
| 479 | return ret; |
| 480 | } |
| 481 | |
| 482 | int |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 483 | netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 484 | u8 *bytes, size_t size) |
| 485 | { |
| 486 | int ret; |
| 487 | |
| 488 | ret = rom_lock(adapter); |
| 489 | if (ret < 0) |
| 490 | return ret; |
| 491 | |
| 492 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); |
| 493 | |
| 494 | netxen_rom_unlock(adapter); |
| 495 | return ret; |
| 496 | } |
| 497 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 498 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) |
| 499 | { |
| 500 | int ret; |
| 501 | |
| 502 | if (rom_lock(adapter) != 0) |
| 503 | return -EIO; |
| 504 | |
| 505 | ret = do_rom_fast_read(adapter, addr, valp); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 506 | netxen_rom_unlock(adapter); |
| 507 | return ret; |
| 508 | } |
| 509 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 510 | #define NETXEN_BOARDTYPE 0x4008 |
| 511 | #define NETXEN_BOARDNUM 0x400c |
| 512 | #define NETXEN_CHIPNUM 0x4010 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 513 | |
| 514 | int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose) |
| 515 | { |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 516 | int addr, val; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 517 | int i, n, init_delay = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 518 | struct crb_addr_pair *buf; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 519 | unsigned offset; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 520 | u32 off; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 521 | |
| 522 | /* resetall */ |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 523 | rom_lock(adapter); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 524 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 525 | netxen_rom_unlock(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 526 | |
| 527 | if (verbose) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 528 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0) |
| 529 | printk("P2 ROM board type: 0x%08x\n", val); |
| 530 | else |
| 531 | printk("Could not read board type\n"); |
| 532 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0) |
| 533 | printk("P2 ROM board num: 0x%08x\n", val); |
| 534 | else |
| 535 | printk("Could not read board number\n"); |
| 536 | if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0) |
| 537 | printk("P2 ROM chip num: 0x%08x\n", val); |
| 538 | else |
| 539 | printk("Could not read chip number\n"); |
| 540 | } |
| 541 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 542 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 543 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 544 | (n != 0xcafecafe) || |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 545 | netxen_rom_fast_read(adapter, 4, &n) != 0) { |
| 546 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 547 | "n: %08x\n", netxen_nic_driver_name, n); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 548 | return -EIO; |
| 549 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 550 | offset = n & 0xffffU; |
| 551 | n = (n >> 16) & 0xffffU; |
| 552 | } else { |
| 553 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
| 554 | !(n & 0x80000000)) { |
| 555 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 556 | "n: %08x\n", netxen_nic_driver_name, n); |
| 557 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 558 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 559 | offset = 1; |
| 560 | n &= ~0x80000000; |
| 561 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 562 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 563 | if (n < 1024) { |
| 564 | if (verbose) |
| 565 | printk(KERN_DEBUG "%s: %d CRB init values found" |
| 566 | " in ROM.\n", netxen_nic_driver_name, n); |
| 567 | } else { |
| 568 | printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not" |
| 569 | " initialized.\n", __func__, n); |
| 570 | return -EIO; |
| 571 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 572 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 573 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 574 | if (buf == NULL) { |
| 575 | printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n", |
| 576 | netxen_nic_driver_name); |
| 577 | return -ENOMEM; |
| 578 | } |
| 579 | for (i = 0; i < n; i++) { |
| 580 | if (netxen_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 || |
Daniel Marjamäki | 584dbe9 | 2009-01-29 08:55:56 +0000 | [diff] [blame] | 581 | netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { |
| 582 | kfree(buf); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 583 | return -EIO; |
Daniel Marjamäki | 584dbe9 | 2009-01-29 08:55:56 +0000 | [diff] [blame] | 584 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 585 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 586 | buf[i].addr = addr; |
| 587 | buf[i].data = val; |
| 588 | |
| 589 | if (verbose) |
| 590 | printk(KERN_DEBUG "%s: PCI: 0x%08x == 0x%08x\n", |
| 591 | netxen_nic_driver_name, |
| 592 | (u32)netxen_decode_crb_addr(addr), val); |
| 593 | } |
| 594 | for (i = 0; i < n; i++) { |
| 595 | |
| 596 | off = netxen_decode_crb_addr(buf[i].addr); |
| 597 | if (off == NETXEN_ADDR_ERROR) { |
| 598 | printk(KERN_ERR"CRB init value out of range %x\n", |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 599 | buf[i].addr); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 600 | continue; |
| 601 | } |
| 602 | off += NETXEN_PCI_CRBSPACE; |
| 603 | /* skipping cold reboot MAGIC */ |
| 604 | if (off == NETXEN_CAM_RAM(0x1fc)) |
| 605 | continue; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 606 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 607 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 608 | /* do not reset PCI */ |
| 609 | if (off == (ROMUSB_GLB + 0xbc)) |
| 610 | continue; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 611 | if (off == (ROMUSB_GLB + 0xa8)) |
| 612 | continue; |
| 613 | if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ |
| 614 | continue; |
| 615 | if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ |
| 616 | continue; |
| 617 | if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ |
| 618 | continue; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 619 | if (off == (NETXEN_CRB_PEG_NET_1 + 0x18)) |
| 620 | buf[i].data = 0x1020; |
| 621 | /* skip the function enable register */ |
| 622 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION)) |
| 623 | continue; |
| 624 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2)) |
| 625 | continue; |
| 626 | if ((off & 0x0ff00000) == NETXEN_CRB_SMB) |
| 627 | continue; |
| 628 | } |
| 629 | |
| 630 | if (off == NETXEN_ADDR_ERROR) { |
| 631 | printk(KERN_ERR "%s: Err: Unknown addr: 0x%08x\n", |
| 632 | netxen_nic_driver_name, buf[i].addr); |
| 633 | continue; |
| 634 | } |
| 635 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 636 | init_delay = 1; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 637 | /* After writing this register, HW needs time for CRB */ |
| 638 | /* to quiet down (else crb_window returns 0xffffffff) */ |
| 639 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 640 | init_delay = 1000; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 641 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 642 | /* hold xdma in reset also */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 643 | buf[i].data = NETXEN_NIC_XDMA_RESET; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 644 | buf[i].data = 0x8000ff; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 645 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 646 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 647 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 648 | NXWR32(adapter, off, buf[i].data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 649 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 650 | msleep(init_delay); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 651 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 652 | kfree(buf); |
| 653 | |
| 654 | /* disable_peg_cache_all */ |
| 655 | |
| 656 | /* unreset_net_cache */ |
| 657 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 658 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); |
| 659 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* p2dn replyCount */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 663 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 664 | /* disable_peg_cache 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 665 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 666 | /* disable_peg_cache 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 667 | NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 668 | |
| 669 | /* peg_clr_all */ |
| 670 | |
| 671 | /* peg_clr 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 672 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0); |
| 673 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 674 | /* peg_clr 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 675 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0); |
| 676 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 677 | /* peg_clr 2 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 678 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0); |
| 679 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 680 | /* peg_clr 3 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 681 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0); |
| 682 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 686 | int |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 687 | netxen_need_fw_reset(struct netxen_adapter *adapter) |
| 688 | { |
| 689 | u32 count, old_count; |
| 690 | u32 val, version, major, minor, build; |
| 691 | int i, timeout; |
| 692 | u8 fw_type; |
| 693 | |
| 694 | /* NX2031 firmware doesn't support heartbit */ |
| 695 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 696 | return 1; |
| 697 | |
| 698 | /* last attempt had failed */ |
| 699 | if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) |
| 700 | return 1; |
| 701 | |
| 702 | old_count = count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 703 | |
| 704 | for (i = 0; i < 10; i++) { |
| 705 | |
| 706 | timeout = msleep_interruptible(200); |
| 707 | if (timeout) { |
| 708 | NXWR32(adapter, CRB_CMDPEG_STATE, |
| 709 | PHAN_INITIALIZE_FAILED); |
| 710 | return -EINTR; |
| 711 | } |
| 712 | |
| 713 | count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 714 | if (count != old_count) |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | /* firmware is dead */ |
| 719 | if (count == old_count) |
| 720 | return 1; |
| 721 | |
| 722 | /* check if we have got newer or different file firmware */ |
| 723 | if (adapter->fw) { |
| 724 | |
| 725 | const struct firmware *fw = adapter->fw; |
| 726 | |
| 727 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); |
| 728 | version = NETXEN_DECODE_VERSION(val); |
| 729 | |
| 730 | major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); |
| 731 | minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); |
| 732 | build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); |
| 733 | |
| 734 | if (version > NETXEN_VERSION_CODE(major, minor, build)) |
| 735 | return 1; |
| 736 | |
| 737 | if (version == NETXEN_VERSION_CODE(major, minor, build)) { |
| 738 | |
| 739 | val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL); |
| 740 | fw_type = (val & 0x4) ? |
| 741 | NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE; |
| 742 | |
| 743 | if (adapter->fw_type != fw_type) |
| 744 | return 1; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static char *fw_name[] = { |
| 752 | "nxromimg.bin", "nx3fwct.bin", "nx3fwmn.bin", "flash", |
| 753 | }; |
| 754 | |
| 755 | int |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 756 | netxen_load_firmware(struct netxen_adapter *adapter) |
| 757 | { |
| 758 | u64 *ptr64; |
| 759 | u32 i, flashaddr, size; |
| 760 | const struct firmware *fw = adapter->fw; |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 761 | struct pci_dev *pdev = adapter->pdev; |
| 762 | |
| 763 | dev_info(&pdev->dev, "loading firmware from %s\n", |
| 764 | fw_name[adapter->fw_type]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 765 | |
| 766 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 767 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1); |
| 768 | |
| 769 | if (fw) { |
| 770 | __le64 data; |
| 771 | |
| 772 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; |
| 773 | |
| 774 | ptr64 = (u64 *)&fw->data[NETXEN_BOOTLD_START]; |
| 775 | flashaddr = NETXEN_BOOTLD_START; |
| 776 | |
| 777 | for (i = 0; i < size; i++) { |
| 778 | data = cpu_to_le64(ptr64[i]); |
| 779 | adapter->pci_mem_write(adapter, flashaddr, &data, 8); |
| 780 | flashaddr += 8; |
| 781 | } |
| 782 | |
| 783 | size = *(u32 *)&fw->data[NX_FW_SIZE_OFFSET]; |
| 784 | size = (__force u32)cpu_to_le32(size) / 8; |
| 785 | |
| 786 | ptr64 = (u64 *)&fw->data[NETXEN_IMAGE_START]; |
| 787 | flashaddr = NETXEN_IMAGE_START; |
| 788 | |
| 789 | for (i = 0; i < size; i++) { |
| 790 | data = cpu_to_le64(ptr64[i]); |
| 791 | |
| 792 | if (adapter->pci_mem_write(adapter, |
| 793 | flashaddr, &data, 8)) |
| 794 | return -EIO; |
| 795 | |
| 796 | flashaddr += 8; |
| 797 | } |
| 798 | } else { |
| 799 | u32 data; |
| 800 | |
| 801 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 4; |
| 802 | flashaddr = NETXEN_BOOTLD_START; |
| 803 | |
| 804 | for (i = 0; i < size; i++) { |
| 805 | if (netxen_rom_fast_read(adapter, |
| 806 | flashaddr, (int *)&data) != 0) |
| 807 | return -EIO; |
| 808 | |
| 809 | if (adapter->pci_mem_write(adapter, |
| 810 | flashaddr, &data, 4)) |
| 811 | return -EIO; |
| 812 | |
| 813 | flashaddr += 4; |
| 814 | } |
| 815 | } |
| 816 | msleep(1); |
| 817 | |
| 818 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 819 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); |
| 820 | else { |
| 821 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); |
| 822 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0); |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int |
| 829 | netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname) |
| 830 | { |
| 831 | __le32 val; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 832 | u32 ver, min_ver, bios; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 833 | struct pci_dev *pdev = adapter->pdev; |
| 834 | const struct firmware *fw = adapter->fw; |
| 835 | |
| 836 | if (fw->size < NX_FW_MIN_SIZE) |
| 837 | return -EINVAL; |
| 838 | |
| 839 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]); |
| 840 | if ((__force u32)val != NETXEN_BDINFO_MAGIC) |
| 841 | return -EINVAL; |
| 842 | |
| 843 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 844 | |
| 845 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 846 | min_ver = NETXEN_VERSION_CODE(4, 0, 216); |
| 847 | else |
| 848 | min_ver = NETXEN_VERSION_CODE(3, 4, 216); |
| 849 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 850 | ver = NETXEN_DECODE_VERSION(val); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 851 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 852 | if ((_major(ver) > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 853 | dev_err(&pdev->dev, |
| 854 | "%s: firmware version %d.%d.%d unsupported\n", |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 855 | fwname, _major(ver), _minor(ver), _build(ver)); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 856 | return -EINVAL; |
| 857 | } |
| 858 | |
| 859 | val = cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]); |
| 860 | netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios); |
| 861 | if ((__force u32)val != bios) { |
| 862 | dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", |
| 863 | fwname); |
| 864 | return -EINVAL; |
| 865 | } |
| 866 | |
| 867 | /* check if flashed firmware is newer */ |
| 868 | if (netxen_rom_fast_read(adapter, |
| 869 | NX_FW_VERSION_OFFSET, (int *)&val)) |
| 870 | return -EIO; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 871 | val = NETXEN_DECODE_VERSION(val); |
| 872 | if (val > ver) { |
| 873 | dev_info(&pdev->dev, "%s: firmware is older than flash\n", |
| 874 | fwname); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 875 | return -EINVAL; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 876 | } |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 877 | |
| 878 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
| 879 | return 0; |
| 880 | } |
| 881 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 882 | void netxen_request_firmware(struct netxen_adapter *adapter) |
| 883 | { |
| 884 | u32 capability, flashed_ver; |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 885 | u8 fw_type; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 886 | struct pci_dev *pdev = adapter->pdev; |
| 887 | int rc = 0; |
| 888 | |
| 889 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 890 | fw_type = NX_P2_MN_ROMIMAGE; |
| 891 | goto request_fw; |
| 892 | } else { |
| 893 | fw_type = NX_P3_CT_ROMIMAGE; |
| 894 | goto request_fw; |
| 895 | } |
| 896 | |
| 897 | request_mn: |
| 898 | capability = 0; |
| 899 | |
| 900 | netxen_rom_fast_read(adapter, |
| 901 | NX_FW_VERSION_OFFSET, (int *)&flashed_ver); |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 902 | flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); |
| 903 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 904 | if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { |
| 905 | capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); |
| 906 | if (capability & NX_PEG_TUNE_MN_PRESENT) { |
| 907 | fw_type = NX_P3_MN_ROMIMAGE; |
| 908 | goto request_fw; |
| 909 | } |
| 910 | } |
| 911 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 912 | fw_type = NX_FLASH_ROMIMAGE; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 913 | adapter->fw = NULL; |
| 914 | goto done; |
| 915 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 916 | request_fw: |
| 917 | rc = request_firmware(&adapter->fw, fw_name[fw_type], &pdev->dev); |
| 918 | if (rc != 0) { |
| 919 | if (fw_type == NX_P3_CT_ROMIMAGE) { |
| 920 | msleep(1); |
| 921 | goto request_mn; |
| 922 | } |
| 923 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 924 | fw_type = NX_FLASH_ROMIMAGE; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 925 | adapter->fw = NULL; |
| 926 | goto done; |
| 927 | } |
| 928 | |
| 929 | rc = netxen_validate_firmware(adapter, fw_name[fw_type]); |
| 930 | if (rc != 0) { |
| 931 | release_firmware(adapter->fw); |
| 932 | |
| 933 | if (fw_type == NX_P3_CT_ROMIMAGE) { |
| 934 | msleep(1); |
| 935 | goto request_mn; |
| 936 | } |
| 937 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 938 | fw_type = NX_FLASH_ROMIMAGE; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 939 | adapter->fw = NULL; |
| 940 | goto done; |
| 941 | } |
| 942 | |
| 943 | done: |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 944 | adapter->fw_type = fw_type; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | |
| 948 | void |
| 949 | netxen_release_firmware(struct netxen_adapter *adapter) |
| 950 | { |
| 951 | if (adapter->fw) |
| 952 | release_firmware(adapter->fw); |
| 953 | } |
| 954 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 955 | int netxen_initialize_adapter_offload(struct netxen_adapter *adapter) |
| 956 | { |
| 957 | uint64_t addr; |
| 958 | uint32_t hi; |
| 959 | uint32_t lo; |
| 960 | |
| 961 | adapter->dummy_dma.addr = |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 962 | pci_alloc_consistent(adapter->pdev, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 963 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 964 | &adapter->dummy_dma.phys_addr); |
| 965 | if (adapter->dummy_dma.addr == NULL) { |
| 966 | printk("%s: ERROR: Could not allocate dummy DMA memory\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 967 | __func__); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 968 | return -ENOMEM; |
| 969 | } |
| 970 | |
| 971 | addr = (uint64_t) adapter->dummy_dma.phys_addr; |
| 972 | hi = (addr >> 32) & 0xffffffff; |
| 973 | lo = addr & 0xffffffff; |
| 974 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 975 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi); |
| 976 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 977 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 978 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 979 | uint32_t temp = 0; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 980 | NXWR32(adapter, CRB_HOST_DUMMY_BUF, temp); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | void netxen_free_adapter_offload(struct netxen_adapter *adapter) |
| 987 | { |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 988 | int i = 100; |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 989 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 990 | if (!adapter->dummy_dma.addr) |
| 991 | return; |
| 992 | |
| 993 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 994 | do { |
| 995 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 996 | break; |
| 997 | msleep(50); |
| 998 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 999 | break; |
| 1000 | } while (--i); |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1001 | } |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1002 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1003 | if (i) { |
| 1004 | pci_free_consistent(adapter->pdev, |
| 1005 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 1006 | adapter->dummy_dma.addr, |
| 1007 | adapter->dummy_dma.phys_addr); |
| 1008 | adapter->dummy_dma.addr = NULL; |
| 1009 | } else { |
| 1010 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 1011 | adapter->netdev->name); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1015 | int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1016 | { |
| 1017 | u32 val = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1018 | int retries = 60; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1019 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1020 | if (pegtune_val) |
| 1021 | return 0; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1022 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1023 | do { |
| 1024 | val = NXRD32(adapter, CRB_CMDPEG_STATE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1025 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1026 | switch (val) { |
| 1027 | case PHAN_INITIALIZE_COMPLETE: |
| 1028 | case PHAN_INITIALIZE_ACK: |
| 1029 | return 0; |
| 1030 | case PHAN_INITIALIZE_FAILED: |
| 1031 | goto out_err; |
| 1032 | default: |
| 1033 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1034 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1035 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1036 | msleep(500); |
| 1037 | |
| 1038 | } while (--retries); |
| 1039 | |
| 1040 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); |
| 1041 | |
| 1042 | out_err: |
| 1043 | dev_warn(&adapter->pdev->dev, "firmware init failed\n"); |
| 1044 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1047 | static int |
| 1048 | netxen_receive_peg_ready(struct netxen_adapter *adapter) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1049 | { |
| 1050 | u32 val = 0; |
| 1051 | int retries = 2000; |
| 1052 | |
| 1053 | do { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1054 | val = NXRD32(adapter, CRB_RCVPEG_STATE); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1055 | |
| 1056 | if (val == PHAN_PEG_RCV_INITIALIZED) |
| 1057 | return 0; |
| 1058 | |
| 1059 | msleep(10); |
| 1060 | |
| 1061 | } while (--retries); |
| 1062 | |
| 1063 | if (!retries) { |
| 1064 | printk(KERN_ERR "Receive Peg initialization not " |
| 1065 | "complete, state: 0x%x.\n", val); |
| 1066 | return -EIO; |
| 1067 | } |
| 1068 | |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1072 | int netxen_init_firmware(struct netxen_adapter *adapter) |
| 1073 | { |
| 1074 | int err; |
| 1075 | |
| 1076 | err = netxen_receive_peg_ready(adapter); |
| 1077 | if (err) |
| 1078 | return err; |
| 1079 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1080 | NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT); |
| 1081 | NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC); |
| 1082 | NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE); |
| 1083 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1084 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1085 | if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1086 | adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1089 | return err; |
| 1090 | } |
| 1091 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1092 | static void |
| 1093 | netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg) |
| 1094 | { |
| 1095 | u32 cable_OUI; |
| 1096 | u16 cable_len; |
| 1097 | u16 link_speed; |
| 1098 | u8 link_status, module, duplex, autoneg; |
| 1099 | struct net_device *netdev = adapter->netdev; |
| 1100 | |
| 1101 | adapter->has_link_events = 1; |
| 1102 | |
| 1103 | cable_OUI = msg->body[1] & 0xffffffff; |
| 1104 | cable_len = (msg->body[1] >> 32) & 0xffff; |
| 1105 | link_speed = (msg->body[1] >> 48) & 0xffff; |
| 1106 | |
| 1107 | link_status = msg->body[2] & 0xff; |
| 1108 | duplex = (msg->body[2] >> 16) & 0xff; |
| 1109 | autoneg = (msg->body[2] >> 24) & 0xff; |
| 1110 | |
| 1111 | module = (msg->body[2] >> 8) & 0xff; |
| 1112 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) { |
| 1113 | printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n", |
| 1114 | netdev->name, cable_OUI, cable_len); |
| 1115 | } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) { |
| 1116 | printk(KERN_INFO "%s: unsupported cable length %d\n", |
| 1117 | netdev->name, cable_len); |
| 1118 | } |
| 1119 | |
| 1120 | netxen_advert_link_change(adapter, link_status); |
| 1121 | |
| 1122 | /* update link parameters */ |
| 1123 | if (duplex == LINKEVENT_FULL_DUPLEX) |
| 1124 | adapter->link_duplex = DUPLEX_FULL; |
| 1125 | else |
| 1126 | adapter->link_duplex = DUPLEX_HALF; |
| 1127 | adapter->module_type = module; |
| 1128 | adapter->link_autoneg = autoneg; |
| 1129 | adapter->link_speed = link_speed; |
| 1130 | } |
| 1131 | |
| 1132 | static void |
| 1133 | netxen_handle_fw_message(int desc_cnt, int index, |
| 1134 | struct nx_host_sds_ring *sds_ring) |
| 1135 | { |
| 1136 | nx_fw_msg_t msg; |
| 1137 | struct status_desc *desc; |
| 1138 | int i = 0, opcode; |
| 1139 | |
| 1140 | while (desc_cnt > 0 && i < 8) { |
| 1141 | desc = &sds_ring->desc_head[index]; |
| 1142 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); |
| 1143 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); |
| 1144 | |
| 1145 | index = get_next_index(index, sds_ring->num_desc); |
| 1146 | desc_cnt--; |
| 1147 | } |
| 1148 | |
| 1149 | opcode = netxen_get_nic_msg_opcode(msg.body[0]); |
| 1150 | switch (opcode) { |
| 1151 | case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: |
| 1152 | netxen_handle_linkevent(sds_ring->adapter, &msg); |
| 1153 | break; |
| 1154 | default: |
| 1155 | break; |
| 1156 | } |
| 1157 | } |
| 1158 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1159 | static int |
| 1160 | netxen_alloc_rx_skb(struct netxen_adapter *adapter, |
| 1161 | struct nx_host_rds_ring *rds_ring, |
| 1162 | struct netxen_rx_buffer *buffer) |
| 1163 | { |
| 1164 | struct sk_buff *skb; |
| 1165 | dma_addr_t dma; |
| 1166 | struct pci_dev *pdev = adapter->pdev; |
| 1167 | |
| 1168 | buffer->skb = dev_alloc_skb(rds_ring->skb_size); |
| 1169 | if (!buffer->skb) |
| 1170 | return 1; |
| 1171 | |
| 1172 | skb = buffer->skb; |
| 1173 | |
| 1174 | if (!adapter->ahw.cut_through) |
| 1175 | skb_reserve(skb, 2); |
| 1176 | |
| 1177 | dma = pci_map_single(pdev, skb->data, |
| 1178 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); |
| 1179 | |
| 1180 | if (pci_dma_mapping_error(pdev, dma)) { |
| 1181 | dev_kfree_skb_any(skb); |
| 1182 | buffer->skb = NULL; |
| 1183 | return 1; |
| 1184 | } |
| 1185 | |
| 1186 | buffer->skb = skb; |
| 1187 | buffer->dma = dma; |
| 1188 | buffer->state = NETXEN_BUFFER_BUSY; |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1193 | static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter, |
| 1194 | struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum) |
| 1195 | { |
| 1196 | struct netxen_rx_buffer *buffer; |
| 1197 | struct sk_buff *skb; |
| 1198 | |
| 1199 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1200 | |
| 1201 | pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, |
| 1202 | PCI_DMA_FROMDEVICE); |
| 1203 | |
| 1204 | skb = buffer->skb; |
| 1205 | if (!skb) |
| 1206 | goto no_skb; |
| 1207 | |
| 1208 | if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) { |
| 1209 | adapter->stats.csummed++; |
| 1210 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1211 | } else |
| 1212 | skb->ip_summed = CHECKSUM_NONE; |
| 1213 | |
| 1214 | skb->dev = adapter->netdev; |
| 1215 | |
| 1216 | buffer->skb = NULL; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1217 | no_skb: |
| 1218 | buffer->state = NETXEN_BUFFER_FREE; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1219 | return skb; |
| 1220 | } |
| 1221 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1222 | static struct netxen_rx_buffer * |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1223 | netxen_process_rcv(struct netxen_adapter *adapter, |
Amit Kumar Salecha | a92e9e6 | 2009-04-07 22:50:47 +0000 | [diff] [blame] | 1224 | int ring, int index, int length, int cksum, int pkt_offset, |
| 1225 | struct nx_host_sds_ring *sds_ring) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1226 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1227 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1228 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1229 | struct netxen_rx_buffer *buffer; |
| 1230 | struct sk_buff *skb; |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1231 | struct nx_host_rds_ring *rds_ring = &recv_ctx->rds_rings[ring]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1232 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1233 | if (unlikely(index > rds_ring->num_desc)) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1234 | return NULL; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1235 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1236 | buffer = &rds_ring->rx_buf_arr[index]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1237 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1238 | skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1239 | if (!skb) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1240 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1241 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1242 | if (length > rds_ring->skb_size) |
| 1243 | skb_put(skb, rds_ring->skb_size); |
| 1244 | else |
| 1245 | skb_put(skb, length); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1246 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1247 | |
| 1248 | if (pkt_offset) |
| 1249 | skb_pull(skb, pkt_offset); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1250 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1251 | skb->protocol = eth_type_trans(skb, netdev); |
| 1252 | |
Amit Kumar Salecha | a92e9e6 | 2009-04-07 22:50:47 +0000 | [diff] [blame] | 1253 | napi_gro_receive(&sds_ring->napi, skb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1254 | |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1255 | adapter->stats.no_rcv++; |
| 1256 | adapter->stats.rxbytes += length; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1257 | |
| 1258 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1261 | #define netxen_merge_rx_buffers(list, head) \ |
| 1262 | do { list_splice_tail_init(list, head); } while (0); |
| 1263 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1264 | int |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1265 | netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1266 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1267 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 1268 | |
| 1269 | struct list_head *cur; |
| 1270 | |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1271 | struct status_desc *desc; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1272 | struct netxen_rx_buffer *rxbuf; |
| 1273 | |
| 1274 | u32 consumer = sds_ring->consumer; |
| 1275 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1276 | int count = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1277 | u64 sts_data; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1278 | int opcode, ring, index, length, cksum, pkt_offset, desc_cnt; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1279 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1280 | while (count < max) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1281 | desc = &sds_ring->desc_head[consumer]; |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1282 | sts_data = le64_to_cpu(desc->status_desc_data[0]); |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1283 | |
| 1284 | if (!(sts_data & STATUS_OWNER_HOST)) |
| 1285 | break; |
| 1286 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1287 | desc_cnt = netxen_get_sts_desc_cnt(sts_data); |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1288 | ring = netxen_get_sts_type(sts_data); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1289 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1290 | if (ring > RCV_RING_JUMBO) |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1291 | goto skip; |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1292 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1293 | opcode = netxen_get_sts_opcode(sts_data); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1294 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1295 | switch (opcode) { |
| 1296 | case NETXEN_NIC_RXPKT_DESC: |
| 1297 | case NETXEN_OLD_RXPKT_DESC: |
| 1298 | break; |
| 1299 | case NETXEN_NIC_RESPONSE_DESC: |
| 1300 | netxen_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1301 | default: |
| 1302 | goto skip; |
| 1303 | } |
| 1304 | |
| 1305 | WARN_ON(desc_cnt > 1); |
| 1306 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1307 | index = netxen_get_sts_refhandle(sts_data); |
| 1308 | length = netxen_get_sts_totallength(sts_data); |
| 1309 | cksum = netxen_get_sts_status(sts_data); |
| 1310 | pkt_offset = netxen_get_sts_pkt_offset(sts_data); |
| 1311 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1312 | rxbuf = netxen_process_rcv(adapter, ring, index, |
Amit Kumar Salecha | a92e9e6 | 2009-04-07 22:50:47 +0000 | [diff] [blame] | 1313 | length, cksum, pkt_offset, sds_ring); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1314 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1315 | if (rxbuf) |
| 1316 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
| 1317 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1318 | skip: |
| 1319 | for (; desc_cnt > 0; desc_cnt--) { |
| 1320 | desc = &sds_ring->desc_head[consumer]; |
| 1321 | desc->status_desc_data[0] = |
| 1322 | cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1323 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1324 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1325 | count++; |
| 1326 | } |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1327 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1328 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1329 | struct nx_host_rds_ring *rds_ring = |
| 1330 | &adapter->recv_ctx.rds_rings[ring]; |
| 1331 | |
| 1332 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1333 | list_for_each(cur, &sds_ring->free_list[ring]) { |
| 1334 | rxbuf = list_entry(cur, |
| 1335 | struct netxen_rx_buffer, list); |
| 1336 | netxen_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1337 | } |
| 1338 | spin_lock(&rds_ring->lock); |
| 1339 | netxen_merge_rx_buffers(&sds_ring->free_list[ring], |
| 1340 | &rds_ring->free_list); |
| 1341 | spin_unlock(&rds_ring->lock); |
| 1342 | } |
| 1343 | |
| 1344 | netxen_post_rx_buffers_nodb(adapter, rds_ring); |
| 1345 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1346 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1347 | if (count) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1348 | sds_ring->consumer = consumer; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1349 | NXWR32(adapter, sds_ring->crb_sts_consumer, consumer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | return count; |
| 1353 | } |
| 1354 | |
| 1355 | /* Process Command status ring */ |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1356 | int netxen_process_cmd_ring(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1357 | { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1358 | u32 sw_consumer, hw_consumer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1359 | int count = 0, i; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1360 | struct netxen_cmd_buffer *buffer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1361 | struct pci_dev *pdev = adapter->pdev; |
| 1362 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1363 | struct netxen_skb_frag *frag; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1364 | int done = 0; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1365 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1366 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1367 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 1368 | return 1; |
| 1369 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1370 | sw_consumer = tx_ring->sw_consumer; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1371 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1372 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1373 | while (sw_consumer != hw_consumer) { |
| 1374 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1375 | if (buffer->skb) { |
| 1376 | frag = &buffer->frag_array[0]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1377 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 1378 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1379 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1380 | for (i = 1; i < buffer->frag_count; i++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1381 | frag++; /* Get the next frag */ |
| 1382 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 1383 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1384 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1385 | } |
| 1386 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1387 | adapter->stats.xmitfinished++; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1388 | dev_kfree_skb_any(buffer->skb); |
| 1389 | buffer->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1392 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1393 | if (++count >= MAX_STATUS_HANDLE) |
| 1394 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1395 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1396 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1397 | if (count && netif_running(netdev)) { |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1398 | tx_ring->sw_consumer = sw_consumer; |
| 1399 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1400 | smp_mb(); |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1401 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1402 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1403 | netif_tx_lock(netdev); |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1404 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) |
| 1405 | netif_wake_queue(netdev); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1406 | netif_tx_unlock(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1407 | } |
| 1408 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1409 | /* |
| 1410 | * If everything is freed up to consumer then check if the ring is full |
| 1411 | * If the ring is full then check if more needs to be freed and |
| 1412 | * schedule the call back again. |
| 1413 | * |
| 1414 | * This happens when there are 2 CPUs. One could be freeing and the |
| 1415 | * other filling it. If the ring is full when we get out of here and |
| 1416 | * the card has already interrupted the host then the host can miss the |
| 1417 | * interrupt. |
| 1418 | * |
| 1419 | * There is still a possible race condition and the host could miss an |
| 1420 | * interrupt. The card has to take care of this. |
| 1421 | */ |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1422 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 1423 | done = (sw_consumer == hw_consumer); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1424 | spin_unlock(&adapter->tx_clean_lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1425 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1426 | return (done); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1429 | void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1430 | netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, |
| 1431 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1432 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1433 | struct rcv_desc *pdesc; |
| 1434 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1435 | int producer, count = 0; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1436 | netxen_ctx_msg msg = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1437 | struct list_head *head; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1438 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1439 | producer = rds_ring->producer; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1440 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1441 | spin_lock(&rds_ring->lock); |
| 1442 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1443 | while (!list_empty(head)) { |
| 1444 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1445 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1446 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1447 | if (!buffer->skb) { |
| 1448 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1449 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1453 | list_del(&buffer->list); |
| 1454 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1455 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1456 | pdesc = &rds_ring->desc_head[producer]; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1457 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1458 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1459 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1460 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1461 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1462 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1463 | spin_unlock(&rds_ring->lock); |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1464 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1465 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1466 | rds_ring->producer = producer; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1467 | NXWR32(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1468 | (producer-1) & (rds_ring->num_desc-1)); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1469 | |
| 1470 | if (adapter->fw_major < 4) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1471 | /* |
| 1472 | * Write a doorbell msg to tell phanmon of change in |
| 1473 | * receive ring producer |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1474 | * Only for firmware version < 4.0.0 |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1475 | */ |
| 1476 | netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); |
| 1477 | netxen_set_msg_privid(msg); |
| 1478 | netxen_set_msg_count(msg, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1479 | ((producer - 1) & |
| 1480 | (rds_ring->num_desc - 1))); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1481 | netxen_set_msg_ctxid(msg, adapter->portnum); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1482 | netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); |
| 1483 | writel(msg, |
| 1484 | DB_NORMALIZE(adapter, |
| 1485 | NETXEN_RCV_PRODUCER_OFFSET)); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1486 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1490 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1491 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 1492 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1493 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1494 | struct rcv_desc *pdesc; |
| 1495 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1496 | int producer, count = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1497 | struct list_head *head; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1498 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1499 | producer = rds_ring->producer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1500 | if (!spin_trylock(&rds_ring->lock)) |
| 1501 | return; |
| 1502 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1503 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1504 | while (!list_empty(head)) { |
| 1505 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1506 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1507 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1508 | if (!buffer->skb) { |
| 1509 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1510 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1514 | list_del(&buffer->list); |
| 1515 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1516 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1517 | pdesc = &rds_ring->desc_head[producer]; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1518 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1519 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1520 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1521 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1522 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1525 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1526 | rds_ring->producer = producer; |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1527 | NXWR32(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1528 | (producer - 1) & (rds_ring->num_desc - 1)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1529 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1530 | spin_unlock(&rds_ring->lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1533 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) |
| 1534 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1535 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1536 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |