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