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. |
Dhananjay Phadke | 13af7a6 | 2009-09-11 11:28:15 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 - QLogic Corporation. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 4 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 5 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 10 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 15 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 19 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 20 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 21 | * The full GNU General Public License is included in this distribution |
Amit Kumar Salecha | 4d21fef | 2010-01-14 01:53:23 +0000 | [diff] [blame] | 22 | * in the file called "COPYING". |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 23 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include "netxen_nic.h" |
| 29 | #include "netxen_nic_hw.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 30 | |
| 31 | struct crb_addr_pair { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 32 | u32 addr; |
| 33 | u32 data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | #define NETXEN_MAX_CRB_XFORM 60 |
| 37 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 38 | #define NETXEN_ADDR_ERROR (0xffffffff) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 39 | |
| 40 | #define crb_addr_transform(name) \ |
| 41 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ |
| 42 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 |
| 43 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 44 | #define NETXEN_NIC_XDMA_RESET 0x8000ff |
| 45 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 46 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 47 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 48 | struct nx_host_rds_ring *rds_ring); |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 49 | static int netxen_p3_has_mn(struct netxen_adapter *adapter); |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 50 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 51 | static void crb_addr_transform_setup(void) |
| 52 | { |
| 53 | crb_addr_transform(XDMA); |
| 54 | crb_addr_transform(TIMR); |
| 55 | crb_addr_transform(SRE); |
| 56 | crb_addr_transform(SQN3); |
| 57 | crb_addr_transform(SQN2); |
| 58 | crb_addr_transform(SQN1); |
| 59 | crb_addr_transform(SQN0); |
| 60 | crb_addr_transform(SQS3); |
| 61 | crb_addr_transform(SQS2); |
| 62 | crb_addr_transform(SQS1); |
| 63 | crb_addr_transform(SQS0); |
| 64 | crb_addr_transform(RPMX7); |
| 65 | crb_addr_transform(RPMX6); |
| 66 | crb_addr_transform(RPMX5); |
| 67 | crb_addr_transform(RPMX4); |
| 68 | crb_addr_transform(RPMX3); |
| 69 | crb_addr_transform(RPMX2); |
| 70 | crb_addr_transform(RPMX1); |
| 71 | crb_addr_transform(RPMX0); |
| 72 | crb_addr_transform(ROMUSB); |
| 73 | crb_addr_transform(SN); |
| 74 | crb_addr_transform(QMN); |
| 75 | crb_addr_transform(QMS); |
| 76 | crb_addr_transform(PGNI); |
| 77 | crb_addr_transform(PGND); |
| 78 | crb_addr_transform(PGN3); |
| 79 | crb_addr_transform(PGN2); |
| 80 | crb_addr_transform(PGN1); |
| 81 | crb_addr_transform(PGN0); |
| 82 | crb_addr_transform(PGSI); |
| 83 | crb_addr_transform(PGSD); |
| 84 | crb_addr_transform(PGS3); |
| 85 | crb_addr_transform(PGS2); |
| 86 | crb_addr_transform(PGS1); |
| 87 | crb_addr_transform(PGS0); |
| 88 | crb_addr_transform(PS); |
| 89 | crb_addr_transform(PH); |
| 90 | crb_addr_transform(NIU); |
| 91 | crb_addr_transform(I2Q); |
| 92 | crb_addr_transform(EG); |
| 93 | crb_addr_transform(MN); |
| 94 | crb_addr_transform(MS); |
| 95 | crb_addr_transform(CAS2); |
| 96 | crb_addr_transform(CAS1); |
| 97 | crb_addr_transform(CAS0); |
| 98 | crb_addr_transform(CAM); |
| 99 | crb_addr_transform(C2C1); |
| 100 | crb_addr_transform(C2C0); |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 101 | crb_addr_transform(SMB); |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 102 | crb_addr_transform(OCM0); |
| 103 | crb_addr_transform(I2C0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 106 | void netxen_release_rx_buffers(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 107 | { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 108 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 109 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 110 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 111 | int i, ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 112 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 113 | recv_ctx = &adapter->recv_ctx; |
| 114 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 115 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 116 | for (i = 0; i < rds_ring->num_desc; ++i) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 117 | rx_buf = &(rds_ring->rx_buf_arr[i]); |
| 118 | if (rx_buf->state == NETXEN_BUFFER_FREE) |
| 119 | continue; |
| 120 | pci_unmap_single(adapter->pdev, |
| 121 | rx_buf->dma, |
| 122 | rds_ring->dma_size, |
| 123 | PCI_DMA_FROMDEVICE); |
| 124 | if (rx_buf->skb != NULL) |
| 125 | dev_kfree_skb_any(rx_buf->skb); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void netxen_release_tx_buffers(struct netxen_adapter *adapter) |
| 131 | { |
| 132 | struct netxen_cmd_buffer *cmd_buf; |
| 133 | struct netxen_skb_frag *buffrag; |
| 134 | int i, j; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 135 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 136 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 137 | cmd_buf = tx_ring->cmd_buf_arr; |
| 138 | for (i = 0; i < tx_ring->num_desc; i++) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 139 | buffrag = cmd_buf->frag_array; |
| 140 | if (buffrag->dma) { |
| 141 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 142 | buffrag->length, PCI_DMA_TODEVICE); |
| 143 | buffrag->dma = 0ULL; |
| 144 | } |
| 145 | for (j = 0; j < cmd_buf->frag_count; j++) { |
| 146 | buffrag++; |
| 147 | if (buffrag->dma) { |
| 148 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 149 | buffrag->length, |
| 150 | PCI_DMA_TODEVICE); |
| 151 | buffrag->dma = 0ULL; |
| 152 | } |
| 153 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 154 | if (cmd_buf->skb) { |
| 155 | dev_kfree_skb_any(cmd_buf->skb); |
| 156 | cmd_buf->skb = NULL; |
| 157 | } |
| 158 | cmd_buf++; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void netxen_free_sw_resources(struct netxen_adapter *adapter) |
| 163 | { |
| 164 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 165 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 166 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 167 | int ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 168 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 169 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 170 | |
| 171 | if (recv_ctx->rds_rings == NULL) |
| 172 | goto skip_rds; |
| 173 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 174 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 175 | rds_ring = &recv_ctx->rds_rings[ring]; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 176 | vfree(rds_ring->rx_buf_arr); |
| 177 | rds_ring->rx_buf_arr = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 178 | } |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 179 | kfree(recv_ctx->rds_rings); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 180 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 181 | skip_rds: |
| 182 | if (adapter->tx_ring == NULL) |
| 183 | return; |
| 184 | |
| 185 | tx_ring = adapter->tx_ring; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 186 | vfree(tx_ring->cmd_buf_arr); |
Amit Kumar Salecha | 011f4ea | 2010-01-07 22:10:14 +0000 | [diff] [blame] | 187 | kfree(tx_ring); |
| 188 | adapter->tx_ring = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | int netxen_alloc_sw_resources(struct netxen_adapter *adapter) |
| 192 | { |
| 193 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 194 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 195 | struct nx_host_sds_ring *sds_ring; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 196 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 197 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 198 | int ring, i, size; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 199 | |
| 200 | struct netxen_cmd_buffer *cmd_buf_arr; |
| 201 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 202 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 203 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 204 | size = sizeof(struct nx_host_tx_ring); |
| 205 | tx_ring = kzalloc(size, GFP_KERNEL); |
| 206 | if (tx_ring == NULL) { |
| 207 | dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n", |
| 208 | netdev->name); |
| 209 | return -ENOMEM; |
| 210 | } |
| 211 | adapter->tx_ring = tx_ring; |
| 212 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 213 | tx_ring->num_desc = adapter->num_txd; |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 214 | tx_ring->txq = netdev_get_tx_queue(netdev, 0); |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 215 | |
| 216 | cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 217 | if (cmd_buf_arr == NULL) { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 218 | dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 219 | netdev->name); |
| 220 | return -ENOMEM; |
| 221 | } |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 222 | memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); |
| 223 | tx_ring->cmd_buf_arr = cmd_buf_arr; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 224 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 225 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 226 | |
| 227 | size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring); |
| 228 | rds_ring = kzalloc(size, GFP_KERNEL); |
| 229 | if (rds_ring == NULL) { |
| 230 | dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n", |
| 231 | netdev->name); |
| 232 | return -ENOMEM; |
| 233 | } |
| 234 | recv_ctx->rds_rings = rds_ring; |
| 235 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 236 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 237 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 238 | switch (ring) { |
| 239 | case RCV_RING_NORMAL: |
| 240 | rds_ring->num_desc = adapter->num_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 241 | if (adapter->ahw.cut_through) { |
| 242 | rds_ring->dma_size = |
| 243 | NX_CT_DEFAULT_RX_BUF_LEN; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 244 | rds_ring->skb_size = |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 245 | NX_CT_DEFAULT_RX_BUF_LEN; |
| 246 | } else { |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 247 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 248 | rds_ring->dma_size = |
| 249 | NX_P3_RX_BUF_MAX_LEN; |
| 250 | else |
| 251 | rds_ring->dma_size = |
| 252 | NX_P2_RX_BUF_MAX_LEN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 253 | rds_ring->skb_size = |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 254 | rds_ring->dma_size + NET_IP_ALIGN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 255 | } |
| 256 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 257 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 258 | case RCV_RING_JUMBO: |
| 259 | rds_ring->num_desc = adapter->num_jumbo_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 260 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 261 | rds_ring->dma_size = |
| 262 | NX_P3_RX_JUMBO_BUF_MAX_LEN; |
| 263 | else |
| 264 | rds_ring->dma_size = |
| 265 | NX_P2_RX_JUMBO_BUF_MAX_LEN; |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 266 | |
| 267 | if (adapter->capabilities & NX_CAP0_HW_LRO) |
| 268 | rds_ring->dma_size += NX_LRO_BUFFER_EXTRA; |
| 269 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 270 | rds_ring->skb_size = |
| 271 | rds_ring->dma_size + NET_IP_ALIGN; |
| 272 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 273 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 274 | case RCV_RING_LRO: |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 275 | rds_ring->num_desc = adapter->num_lro_rxd; |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 276 | rds_ring->dma_size = NX_RX_LRO_BUFFER_LENGTH; |
| 277 | rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 278 | break; |
| 279 | |
| 280 | } |
| 281 | rds_ring->rx_buf_arr = (struct netxen_rx_buffer *) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 282 | vmalloc(RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 283 | if (rds_ring->rx_buf_arr == NULL) { |
| 284 | printk(KERN_ERR "%s: Failed to allocate " |
| 285 | "rx buffer ring %d\n", |
| 286 | netdev->name, ring); |
| 287 | /* free whatever was already allocated */ |
| 288 | goto err_out; |
| 289 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 290 | memset(rds_ring->rx_buf_arr, 0, RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 291 | INIT_LIST_HEAD(&rds_ring->free_list); |
| 292 | /* |
| 293 | * Now go through all of them, set reference handles |
| 294 | * and put them in the queues. |
| 295 | */ |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 296 | rx_buf = rds_ring->rx_buf_arr; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 297 | for (i = 0; i < rds_ring->num_desc; i++) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 298 | list_add_tail(&rx_buf->list, |
| 299 | &rds_ring->free_list); |
| 300 | rx_buf->ref_handle = i; |
| 301 | rx_buf->state = NETXEN_BUFFER_FREE; |
| 302 | rx_buf++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 303 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 304 | spin_lock_init(&rds_ring->lock); |
| 305 | } |
| 306 | |
| 307 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 308 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 309 | sds_ring->irq = adapter->msix_entries[ring].vector; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 310 | sds_ring->adapter = adapter; |
| 311 | sds_ring->num_desc = adapter->num_rxd; |
| 312 | |
| 313 | for (i = 0; i < NUM_RCV_DESC_RINGS; i++) |
| 314 | INIT_LIST_HEAD(&sds_ring->free_list[i]); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 315 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | |
| 319 | err_out: |
| 320 | netxen_free_sw_resources(adapter); |
| 321 | return -ENOMEM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 324 | /* |
| 325 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB |
| 326 | * address to external PCI CRB address. |
| 327 | */ |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 328 | static u32 netxen_decode_crb_addr(u32 addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 329 | { |
| 330 | int i; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 331 | u32 base_addr, offset, pci_base; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 332 | |
| 333 | crb_addr_transform_setup(); |
| 334 | |
| 335 | pci_base = NETXEN_ADDR_ERROR; |
| 336 | base_addr = addr & 0xfff00000; |
| 337 | offset = addr & 0x000fffff; |
| 338 | |
| 339 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { |
| 340 | if (crb_addr_xform[i] == base_addr) { |
| 341 | pci_base = i << 20; |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | if (pci_base == NETXEN_ADDR_ERROR) |
| 346 | return pci_base; |
| 347 | else |
| 348 | return (pci_base + offset); |
| 349 | } |
| 350 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 351 | #define NETXEN_MAX_ROM_WAIT_USEC 100 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 352 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 353 | static int netxen_wait_rom_done(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 354 | { |
| 355 | long timeout = 0; |
| 356 | long done = 0; |
| 357 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 358 | cond_resched(); |
| 359 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 360 | while (done == 0) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 361 | done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 362 | done &= 2; |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 363 | if (++timeout >= NETXEN_MAX_ROM_WAIT_USEC) { |
| 364 | dev_err(&adapter->pdev->dev, |
| 365 | "Timeout reached waiting for rom done"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 366 | return -EIO; |
| 367 | } |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 368 | udelay(1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 369 | } |
| 370 | return 0; |
| 371 | } |
| 372 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 373 | static int do_rom_fast_read(struct netxen_adapter *adapter, |
| 374 | int addr, int *valp) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 375 | { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 376 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 377 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 378 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
| 379 | NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 380 | if (netxen_wait_rom_done(adapter)) { |
| 381 | printk("Error waiting for rom done\n"); |
| 382 | return -EIO; |
| 383 | } |
| 384 | /* reset abyte_cnt and dummy_byte_cnt */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 385 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 386 | udelay(10); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 387 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 388 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 389 | *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 393 | static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
| 394 | u8 *bytes, size_t size) |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 395 | { |
| 396 | int addridx; |
| 397 | int ret = 0; |
| 398 | |
| 399 | for (addridx = addr; addridx < (addr + size); addridx += 4) { |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 400 | int v; |
| 401 | ret = do_rom_fast_read(adapter, addridx, &v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 402 | if (ret != 0) |
| 403 | break; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 404 | *(__le32 *)bytes = cpu_to_le32(v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 405 | bytes += 4; |
| 406 | } |
| 407 | |
| 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | int |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 412 | netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 413 | u8 *bytes, size_t size) |
| 414 | { |
| 415 | int ret; |
| 416 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 417 | ret = netxen_rom_lock(adapter); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 418 | if (ret < 0) |
| 419 | return ret; |
| 420 | |
| 421 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); |
| 422 | |
| 423 | netxen_rom_unlock(adapter); |
| 424 | return ret; |
| 425 | } |
| 426 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 427 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) |
| 428 | { |
| 429 | int ret; |
| 430 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 431 | if (netxen_rom_lock(adapter) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 432 | return -EIO; |
| 433 | |
| 434 | ret = do_rom_fast_read(adapter, addr, valp); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 435 | netxen_rom_unlock(adapter); |
| 436 | return ret; |
| 437 | } |
| 438 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 439 | #define NETXEN_BOARDTYPE 0x4008 |
| 440 | #define NETXEN_BOARDNUM 0x400c |
| 441 | #define NETXEN_CHIPNUM 0x4010 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 442 | |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 443 | int netxen_pinit_from_rom(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 444 | { |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 445 | int addr, val; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 446 | int i, n, init_delay = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 447 | struct crb_addr_pair *buf; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 448 | unsigned offset; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 449 | u32 off; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 450 | |
| 451 | /* resetall */ |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 452 | netxen_rom_lock(adapter); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 453 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 454 | netxen_rom_unlock(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 455 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 456 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 457 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 458 | (n != 0xcafecafe) || |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 459 | netxen_rom_fast_read(adapter, 4, &n) != 0) { |
| 460 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 461 | "n: %08x\n", netxen_nic_driver_name, n); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 462 | return -EIO; |
| 463 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 464 | offset = n & 0xffffU; |
| 465 | n = (n >> 16) & 0xffffU; |
| 466 | } else { |
| 467 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
| 468 | !(n & 0x80000000)) { |
| 469 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 470 | "n: %08x\n", netxen_nic_driver_name, n); |
| 471 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 472 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 473 | offset = 1; |
| 474 | n &= ~0x80000000; |
| 475 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 476 | |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 477 | if (n >= 1024) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 478 | printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not" |
| 479 | " initialized.\n", __func__, n); |
| 480 | return -EIO; |
| 481 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 482 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 483 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 484 | if (buf == NULL) { |
| 485 | printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n", |
| 486 | netxen_nic_driver_name); |
| 487 | return -ENOMEM; |
| 488 | } |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 489 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 490 | for (i = 0; i < n; i++) { |
| 491 | 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] | 492 | netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { |
| 493 | kfree(buf); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 494 | return -EIO; |
Daniel Marjamäki | 584dbe9 | 2009-01-29 08:55:56 +0000 | [diff] [blame] | 495 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 496 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 497 | buf[i].addr = addr; |
| 498 | buf[i].data = val; |
| 499 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 500 | } |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 501 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 502 | for (i = 0; i < n; i++) { |
| 503 | |
| 504 | off = netxen_decode_crb_addr(buf[i].addr); |
| 505 | if (off == NETXEN_ADDR_ERROR) { |
| 506 | printk(KERN_ERR"CRB init value out of range %x\n", |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 507 | buf[i].addr); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 508 | continue; |
| 509 | } |
| 510 | off += NETXEN_PCI_CRBSPACE; |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 511 | |
| 512 | if (off & 1) |
| 513 | continue; |
| 514 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 515 | /* skipping cold reboot MAGIC */ |
| 516 | if (off == NETXEN_CAM_RAM(0x1fc)) |
| 517 | continue; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 518 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 519 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
Dhananjay Phadke | 8bee0a9 | 2009-10-21 19:39:01 +0000 | [diff] [blame] | 520 | if (off == (NETXEN_CRB_I2C0 + 0x1c)) |
| 521 | continue; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 522 | /* do not reset PCI */ |
| 523 | if (off == (ROMUSB_GLB + 0xbc)) |
| 524 | continue; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 525 | if (off == (ROMUSB_GLB + 0xa8)) |
| 526 | continue; |
| 527 | if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ |
| 528 | continue; |
| 529 | if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ |
| 530 | continue; |
| 531 | if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ |
| 532 | continue; |
Amit Kumar Salecha | e7473f1 | 2009-11-29 21:54:55 -0800 | [diff] [blame] | 533 | if ((off & 0x0ff00000) == NETXEN_CRB_DDR_NET) |
| 534 | continue; |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 535 | if (off == (NETXEN_CRB_PEG_NET_1 + 0x18) && |
| 536 | !NX_IS_REVISION_P3P(adapter->ahw.revision_id)) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 537 | buf[i].data = 0x1020; |
| 538 | /* skip the function enable register */ |
| 539 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION)) |
| 540 | continue; |
| 541 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2)) |
| 542 | continue; |
| 543 | if ((off & 0x0ff00000) == NETXEN_CRB_SMB) |
| 544 | continue; |
| 545 | } |
| 546 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 547 | init_delay = 1; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 548 | /* After writing this register, HW needs time for CRB */ |
| 549 | /* to quiet down (else crb_window returns 0xffffffff) */ |
| 550 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 551 | init_delay = 1000; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 552 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 553 | /* hold xdma in reset also */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 554 | buf[i].data = NETXEN_NIC_XDMA_RESET; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 555 | buf[i].data = 0x8000ff; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 556 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 557 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 558 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 559 | NXWR32(adapter, off, buf[i].data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 560 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 561 | msleep(init_delay); |
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 | kfree(buf); |
| 564 | |
| 565 | /* disable_peg_cache_all */ |
| 566 | |
| 567 | /* unreset_net_cache */ |
| 568 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 569 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); |
| 570 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* p2dn replyCount */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 574 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 575 | /* disable_peg_cache 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 576 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 577 | /* disable_peg_cache 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 578 | NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 579 | |
| 580 | /* peg_clr_all */ |
| 581 | |
| 582 | /* peg_clr 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 583 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0); |
| 584 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 585 | /* peg_clr 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 586 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0); |
| 587 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 588 | /* peg_clr 2 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 589 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0); |
| 590 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 591 | /* peg_clr 3 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 592 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0); |
| 593 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 597 | static struct uni_table_desc *nx_get_table_desc(const u8 *unirom, int section) |
| 598 | { |
| 599 | uint32_t i; |
| 600 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; |
| 601 | __le32 entries = cpu_to_le32(directory->num_entries); |
| 602 | |
| 603 | for (i = 0; i < entries; i++) { |
| 604 | |
| 605 | __le32 offs = cpu_to_le32(directory->findex) + |
| 606 | (i * cpu_to_le32(directory->entry_size)); |
| 607 | __le32 tab_type = cpu_to_le32(*((u32 *)&unirom[offs] + 8)); |
| 608 | |
| 609 | if (tab_type == section) |
| 610 | return (struct uni_table_desc *) &unirom[offs]; |
| 611 | } |
| 612 | |
| 613 | return NULL; |
| 614 | } |
| 615 | |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 616 | #define QLCNIC_FILEHEADER_SIZE (14 * 4) |
| 617 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 618 | static int |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 619 | netxen_nic_validate_header(struct netxen_adapter *adapter) |
| 620 | { |
| 621 | const u8 *unirom = adapter->fw->data; |
| 622 | struct uni_table_desc *directory = (struct uni_table_desc *) &unirom[0]; |
| 623 | u32 fw_file_size = adapter->fw->size; |
| 624 | u32 tab_size; |
| 625 | __le32 entries; |
| 626 | __le32 entry_size; |
| 627 | |
| 628 | if (fw_file_size < QLCNIC_FILEHEADER_SIZE) |
| 629 | return -EINVAL; |
| 630 | |
| 631 | entries = cpu_to_le32(directory->num_entries); |
| 632 | entry_size = cpu_to_le32(directory->entry_size); |
| 633 | tab_size = cpu_to_le32(directory->findex) + (entries * entry_size); |
| 634 | |
| 635 | if (fw_file_size < tab_size) |
| 636 | return -EINVAL; |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | static int |
| 642 | netxen_nic_validate_bootld(struct netxen_adapter *adapter) |
| 643 | { |
| 644 | struct uni_table_desc *tab_desc; |
| 645 | struct uni_data_desc *descr; |
| 646 | const u8 *unirom = adapter->fw->data; |
| 647 | __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 648 | NX_UNI_BOOTLD_IDX_OFF)); |
| 649 | u32 offs; |
| 650 | u32 tab_size; |
| 651 | u32 data_size; |
| 652 | |
| 653 | tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_BOOTLD); |
| 654 | |
| 655 | if (!tab_desc) |
| 656 | return -EINVAL; |
| 657 | |
| 658 | tab_size = cpu_to_le32(tab_desc->findex) + |
| 659 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); |
| 660 | |
| 661 | if (adapter->fw->size < tab_size) |
| 662 | return -EINVAL; |
| 663 | |
| 664 | offs = cpu_to_le32(tab_desc->findex) + |
| 665 | (cpu_to_le32(tab_desc->entry_size) * (idx)); |
| 666 | descr = (struct uni_data_desc *)&unirom[offs]; |
| 667 | |
| 668 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); |
| 669 | |
| 670 | if (adapter->fw->size < data_size) |
| 671 | return -EINVAL; |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | static int |
| 677 | netxen_nic_validate_fw(struct netxen_adapter *adapter) |
| 678 | { |
| 679 | struct uni_table_desc *tab_desc; |
| 680 | struct uni_data_desc *descr; |
| 681 | const u8 *unirom = adapter->fw->data; |
| 682 | __le32 idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 683 | NX_UNI_FIRMWARE_IDX_OFF)); |
| 684 | u32 offs; |
| 685 | u32 tab_size; |
| 686 | u32 data_size; |
| 687 | |
| 688 | tab_desc = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_FW); |
| 689 | |
| 690 | if (!tab_desc) |
| 691 | return -EINVAL; |
| 692 | |
| 693 | tab_size = cpu_to_le32(tab_desc->findex) + |
| 694 | (cpu_to_le32(tab_desc->entry_size) * (idx + 1)); |
| 695 | |
| 696 | if (adapter->fw->size < tab_size) |
| 697 | return -EINVAL; |
| 698 | |
| 699 | offs = cpu_to_le32(tab_desc->findex) + |
| 700 | (cpu_to_le32(tab_desc->entry_size) * (idx)); |
| 701 | descr = (struct uni_data_desc *)&unirom[offs]; |
| 702 | data_size = cpu_to_le32(descr->findex) + cpu_to_le32(descr->size); |
| 703 | |
| 704 | if (adapter->fw->size < data_size) |
| 705 | return -EINVAL; |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | |
| 711 | static int |
| 712 | netxen_nic_validate_product_offs(struct netxen_adapter *adapter) |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 713 | { |
| 714 | struct uni_table_desc *ptab_descr; |
| 715 | const u8 *unirom = adapter->fw->data; |
Dhananjay Phadke | 634d7df | 2009-12-05 12:23:56 +0000 | [diff] [blame] | 716 | int mn_present = (NX_IS_REVISION_P2(adapter->ahw.revision_id)) ? |
| 717 | 1 : netxen_p3_has_mn(adapter); |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 718 | __le32 entries; |
| 719 | __le32 entry_size; |
| 720 | u32 tab_size; |
| 721 | u32 i; |
Dhananjay Phadke | 634d7df | 2009-12-05 12:23:56 +0000 | [diff] [blame] | 722 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 723 | ptab_descr = nx_get_table_desc(unirom, NX_UNI_DIR_SECT_PRODUCT_TBL); |
| 724 | if (ptab_descr == NULL) |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 725 | return -EINVAL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 726 | |
| 727 | entries = cpu_to_le32(ptab_descr->num_entries); |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 728 | entry_size = cpu_to_le32(ptab_descr->entry_size); |
| 729 | tab_size = cpu_to_le32(ptab_descr->findex) + (entries * entry_size); |
| 730 | |
| 731 | if (adapter->fw->size < tab_size) |
| 732 | return -EINVAL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 733 | |
Dhananjay Phadke | 634d7df | 2009-12-05 12:23:56 +0000 | [diff] [blame] | 734 | nomn: |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 735 | for (i = 0; i < entries; i++) { |
| 736 | |
| 737 | __le32 flags, file_chiprev, offs; |
| 738 | u8 chiprev = adapter->ahw.revision_id; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 739 | uint32_t flagbit; |
| 740 | |
| 741 | offs = cpu_to_le32(ptab_descr->findex) + |
| 742 | (i * cpu_to_le32(ptab_descr->entry_size)); |
| 743 | flags = cpu_to_le32(*((int *)&unirom[offs] + NX_UNI_FLAGS_OFF)); |
| 744 | file_chiprev = cpu_to_le32(*((int *)&unirom[offs] + |
| 745 | NX_UNI_CHIP_REV_OFF)); |
| 746 | |
| 747 | flagbit = mn_present ? 1 : 2; |
| 748 | |
| 749 | if ((chiprev == file_chiprev) && |
| 750 | ((1ULL << flagbit) & flags)) { |
| 751 | adapter->file_prd_off = offs; |
| 752 | return 0; |
| 753 | } |
| 754 | } |
| 755 | |
Dhananjay Phadke | 634d7df | 2009-12-05 12:23:56 +0000 | [diff] [blame] | 756 | if (mn_present && NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 757 | mn_present = 0; |
| 758 | goto nomn; |
| 759 | } |
| 760 | |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 761 | return -EINVAL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 764 | static int |
| 765 | netxen_nic_validate_unified_romimage(struct netxen_adapter *adapter) |
| 766 | { |
| 767 | if (netxen_nic_validate_header(adapter)) { |
| 768 | dev_err(&adapter->pdev->dev, |
| 769 | "unified image: header validation failed\n"); |
| 770 | return -EINVAL; |
| 771 | } |
| 772 | |
| 773 | if (netxen_nic_validate_product_offs(adapter)) { |
| 774 | dev_err(&adapter->pdev->dev, |
| 775 | "unified image: product validation failed\n"); |
| 776 | return -EINVAL; |
| 777 | } |
| 778 | |
| 779 | if (netxen_nic_validate_bootld(adapter)) { |
| 780 | dev_err(&adapter->pdev->dev, |
| 781 | "unified image: bootld validation failed\n"); |
| 782 | return -EINVAL; |
| 783 | } |
| 784 | |
| 785 | if (netxen_nic_validate_fw(adapter)) { |
| 786 | dev_err(&adapter->pdev->dev, |
| 787 | "unified image: firmware validation failed\n"); |
| 788 | return -EINVAL; |
| 789 | } |
| 790 | |
| 791 | return 0; |
| 792 | } |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 793 | |
| 794 | static struct uni_data_desc *nx_get_data_desc(struct netxen_adapter *adapter, |
| 795 | u32 section, u32 idx_offset) |
| 796 | { |
| 797 | const u8 *unirom = adapter->fw->data; |
| 798 | int idx = cpu_to_le32(*((int *)&unirom[adapter->file_prd_off] + |
| 799 | idx_offset)); |
| 800 | struct uni_table_desc *tab_desc; |
| 801 | __le32 offs; |
| 802 | |
| 803 | tab_desc = nx_get_table_desc(unirom, section); |
| 804 | |
| 805 | if (tab_desc == NULL) |
| 806 | return NULL; |
| 807 | |
| 808 | offs = cpu_to_le32(tab_desc->findex) + |
| 809 | (cpu_to_le32(tab_desc->entry_size) * idx); |
| 810 | |
| 811 | return (struct uni_data_desc *)&unirom[offs]; |
| 812 | } |
| 813 | |
| 814 | static u8 * |
| 815 | nx_get_bootld_offs(struct netxen_adapter *adapter) |
| 816 | { |
| 817 | u32 offs = NETXEN_BOOTLD_START; |
| 818 | |
| 819 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) |
| 820 | offs = cpu_to_le32((nx_get_data_desc(adapter, |
| 821 | NX_UNI_DIR_SECT_BOOTLD, |
| 822 | NX_UNI_BOOTLD_IDX_OFF))->findex); |
| 823 | |
| 824 | return (u8 *)&adapter->fw->data[offs]; |
| 825 | } |
| 826 | |
| 827 | static u8 * |
| 828 | nx_get_fw_offs(struct netxen_adapter *adapter) |
| 829 | { |
| 830 | u32 offs = NETXEN_IMAGE_START; |
| 831 | |
| 832 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) |
| 833 | offs = cpu_to_le32((nx_get_data_desc(adapter, |
| 834 | NX_UNI_DIR_SECT_FW, |
| 835 | NX_UNI_FIRMWARE_IDX_OFF))->findex); |
| 836 | |
| 837 | return (u8 *)&adapter->fw->data[offs]; |
| 838 | } |
| 839 | |
| 840 | static __le32 |
| 841 | nx_get_fw_size(struct netxen_adapter *adapter) |
| 842 | { |
| 843 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) |
| 844 | return cpu_to_le32((nx_get_data_desc(adapter, |
| 845 | NX_UNI_DIR_SECT_FW, |
| 846 | NX_UNI_FIRMWARE_IDX_OFF))->size); |
| 847 | else |
| 848 | return cpu_to_le32( |
| 849 | *(u32 *)&adapter->fw->data[NX_FW_SIZE_OFFSET]); |
| 850 | } |
| 851 | |
| 852 | static __le32 |
| 853 | nx_get_fw_version(struct netxen_adapter *adapter) |
| 854 | { |
| 855 | struct uni_data_desc *fw_data_desc; |
| 856 | const struct firmware *fw = adapter->fw; |
| 857 | __le32 major, minor, sub; |
| 858 | const u8 *ver_str; |
| 859 | int i, ret = 0; |
| 860 | |
| 861 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { |
| 862 | |
| 863 | fw_data_desc = nx_get_data_desc(adapter, |
| 864 | NX_UNI_DIR_SECT_FW, NX_UNI_FIRMWARE_IDX_OFF); |
| 865 | ver_str = fw->data + cpu_to_le32(fw_data_desc->findex) + |
| 866 | cpu_to_le32(fw_data_desc->size) - 17; |
| 867 | |
| 868 | for (i = 0; i < 12; i++) { |
| 869 | if (!strncmp(&ver_str[i], "REV=", 4)) { |
| 870 | ret = sscanf(&ver_str[i+4], "%u.%u.%u ", |
| 871 | &major, &minor, &sub); |
| 872 | break; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | if (ret != 3) |
| 877 | return 0; |
| 878 | |
| 879 | return major + (minor << 8) + (sub << 16); |
| 880 | |
| 881 | } else |
| 882 | return cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); |
| 883 | } |
| 884 | |
| 885 | static __le32 |
| 886 | nx_get_bios_version(struct netxen_adapter *adapter) |
| 887 | { |
| 888 | const struct firmware *fw = adapter->fw; |
| 889 | __le32 bios_ver, prd_off = adapter->file_prd_off; |
| 890 | |
| 891 | if (adapter->fw_type == NX_UNIFIED_ROMIMAGE) { |
| 892 | bios_ver = cpu_to_le32(*((u32 *) (&fw->data[prd_off]) |
| 893 | + NX_UNI_BIOS_VERSION_OFF)); |
| 894 | return (bios_ver << 24) + ((bios_ver >> 8) & 0xff00) + |
| 895 | (bios_ver >> 24); |
| 896 | } else |
| 897 | return cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]); |
| 898 | |
| 899 | } |
| 900 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 901 | int |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 902 | netxen_need_fw_reset(struct netxen_adapter *adapter) |
| 903 | { |
| 904 | u32 count, old_count; |
| 905 | u32 val, version, major, minor, build; |
| 906 | int i, timeout; |
| 907 | u8 fw_type; |
| 908 | |
| 909 | /* NX2031 firmware doesn't support heartbit */ |
| 910 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 911 | return 1; |
| 912 | |
Amit Kumar Salecha | 6a808c6 | 2009-12-08 20:40:55 +0000 | [diff] [blame] | 913 | if (adapter->need_fw_reset) |
| 914 | return 1; |
| 915 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 916 | /* last attempt had failed */ |
| 917 | if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) |
| 918 | return 1; |
| 919 | |
Amit Kumar Salecha | 581e8ae | 2010-01-07 22:10:15 +0000 | [diff] [blame] | 920 | old_count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 921 | |
| 922 | for (i = 0; i < 10; i++) { |
| 923 | |
| 924 | timeout = msleep_interruptible(200); |
| 925 | if (timeout) { |
| 926 | NXWR32(adapter, CRB_CMDPEG_STATE, |
| 927 | PHAN_INITIALIZE_FAILED); |
| 928 | return -EINTR; |
| 929 | } |
| 930 | |
| 931 | count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 932 | if (count != old_count) |
| 933 | break; |
| 934 | } |
| 935 | |
| 936 | /* firmware is dead */ |
| 937 | if (count == old_count) |
| 938 | return 1; |
| 939 | |
| 940 | /* check if we have got newer or different file firmware */ |
| 941 | if (adapter->fw) { |
| 942 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 943 | val = nx_get_fw_version(adapter); |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 944 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 945 | version = NETXEN_DECODE_VERSION(val); |
| 946 | |
| 947 | major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); |
| 948 | minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); |
| 949 | build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); |
| 950 | |
| 951 | if (version > NETXEN_VERSION_CODE(major, minor, build)) |
| 952 | return 1; |
| 953 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 954 | if (version == NETXEN_VERSION_CODE(major, minor, build) && |
| 955 | adapter->fw_type != NX_UNIFIED_ROMIMAGE) { |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 956 | |
| 957 | val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL); |
| 958 | fw_type = (val & 0x4) ? |
| 959 | NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE; |
| 960 | |
| 961 | if (adapter->fw_type != fw_type) |
| 962 | return 1; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static char *fw_name[] = { |
Dhananjay Phadke | 7e8e5d9 | 2009-10-24 16:04:02 +0000 | [diff] [blame] | 970 | NX_P2_MN_ROMIMAGE_NAME, |
| 971 | NX_P3_CT_ROMIMAGE_NAME, |
| 972 | NX_P3_MN_ROMIMAGE_NAME, |
| 973 | NX_UNIFIED_ROMIMAGE_NAME, |
| 974 | NX_FLASH_ROMIMAGE_NAME, |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 975 | }; |
| 976 | |
| 977 | int |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 978 | netxen_load_firmware(struct netxen_adapter *adapter) |
| 979 | { |
| 980 | u64 *ptr64; |
| 981 | u32 i, flashaddr, size; |
| 982 | const struct firmware *fw = adapter->fw; |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 983 | struct pci_dev *pdev = adapter->pdev; |
| 984 | |
| 985 | dev_info(&pdev->dev, "loading firmware from %s\n", |
| 986 | fw_name[adapter->fw_type]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 987 | |
| 988 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 989 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1); |
| 990 | |
| 991 | if (fw) { |
| 992 | __le64 data; |
| 993 | |
| 994 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; |
| 995 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 996 | ptr64 = (u64 *)nx_get_bootld_offs(adapter); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 997 | flashaddr = NETXEN_BOOTLD_START; |
| 998 | |
| 999 | for (i = 0; i < size; i++) { |
| 1000 | data = cpu_to_le64(ptr64[i]); |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1001 | |
| 1002 | if (adapter->pci_mem_write(adapter, flashaddr, data)) |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 1003 | return -EIO; |
| 1004 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1005 | flashaddr += 8; |
| 1006 | } |
| 1007 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1008 | size = (__force u32)nx_get_fw_size(adapter) / 8; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1009 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1010 | ptr64 = (u64 *)nx_get_fw_offs(adapter); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1011 | flashaddr = NETXEN_IMAGE_START; |
| 1012 | |
| 1013 | for (i = 0; i < size; i++) { |
| 1014 | data = cpu_to_le64(ptr64[i]); |
| 1015 | |
| 1016 | if (adapter->pci_mem_write(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 1017 | flashaddr, data)) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1018 | return -EIO; |
| 1019 | |
| 1020 | flashaddr += 8; |
| 1021 | } |
| 1022 | } else { |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 1023 | u64 data; |
| 1024 | u32 hi, lo; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1025 | |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 1026 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1027 | flashaddr = NETXEN_BOOTLD_START; |
| 1028 | |
| 1029 | for (i = 0; i < size; i++) { |
| 1030 | if (netxen_rom_fast_read(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 1031 | flashaddr, (int *)&lo) != 0) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1032 | return -EIO; |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 1033 | if (netxen_rom_fast_read(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 1034 | flashaddr + 4, (int *)&hi) != 0) |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 1035 | return -EIO; |
| 1036 | |
| 1037 | /* hi, lo are already in host endian byteorder */ |
| 1038 | data = (((u64)hi << 32) | lo); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1039 | |
| 1040 | if (adapter->pci_mem_write(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 1041 | flashaddr, data)) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1042 | return -EIO; |
| 1043 | |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 1044 | flashaddr += 8; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | msleep(1); |
| 1048 | |
Amit Kumar Salecha | 0be367b | 2009-10-16 15:50:08 +0000 | [diff] [blame] | 1049 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) { |
| 1050 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x18, 0x1020); |
| 1051 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001e); |
| 1052 | } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1053 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); |
| 1054 | else { |
| 1055 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); |
| 1056 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0); |
| 1057 | } |
| 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static int |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1063 | netxen_validate_firmware(struct netxen_adapter *adapter) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1064 | { |
| 1065 | __le32 val; |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 1066 | u32 ver, min_ver, bios; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1067 | struct pci_dev *pdev = adapter->pdev; |
| 1068 | const struct firmware *fw = adapter->fw; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1069 | u8 fw_type = adapter->fw_type; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1070 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1071 | if (fw_type == NX_UNIFIED_ROMIMAGE) { |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 1072 | if (netxen_nic_validate_unified_romimage(adapter)) |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1073 | return -EINVAL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1074 | } else { |
| 1075 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]); |
| 1076 | if ((__force u32)val != NETXEN_BDINFO_MAGIC) |
| 1077 | return -EINVAL; |
| 1078 | |
Rajesh K Borundia | 10c0f2a | 2010-03-29 02:43:43 +0000 | [diff] [blame^] | 1079 | if (fw->size < NX_FW_MIN_SIZE) |
| 1080 | return -EINVAL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1083 | val = nx_get_fw_version(adapter); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1084 | |
| 1085 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1086 | min_ver = NETXEN_VERSION_CODE(4, 0, 216); |
| 1087 | else |
| 1088 | min_ver = NETXEN_VERSION_CODE(3, 4, 216); |
| 1089 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 1090 | ver = NETXEN_DECODE_VERSION(val); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1091 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 1092 | if ((_major(ver) > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1093 | dev_err(&pdev->dev, |
| 1094 | "%s: firmware version %d.%d.%d unsupported\n", |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1095 | fw_name[fw_type], _major(ver), _minor(ver), _build(ver)); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1096 | return -EINVAL; |
| 1097 | } |
| 1098 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1099 | val = nx_get_bios_version(adapter); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1100 | netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios); |
| 1101 | if ((__force u32)val != bios) { |
| 1102 | dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1103 | fw_name[fw_type]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1104 | return -EINVAL; |
| 1105 | } |
| 1106 | |
| 1107 | /* check if flashed firmware is newer */ |
| 1108 | if (netxen_rom_fast_read(adapter, |
| 1109 | NX_FW_VERSION_OFFSET, (int *)&val)) |
| 1110 | return -EIO; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 1111 | val = NETXEN_DECODE_VERSION(val); |
| 1112 | if (val > ver) { |
| 1113 | dev_info(&pdev->dev, "%s: firmware is older than flash\n", |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1114 | fw_name[fw_type]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1115 | return -EINVAL; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 1116 | } |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1117 | |
| 1118 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1122 | static void |
| 1123 | nx_get_next_fwtype(struct netxen_adapter *adapter) |
| 1124 | { |
| 1125 | u8 fw_type; |
| 1126 | |
| 1127 | switch (adapter->fw_type) { |
| 1128 | case NX_UNKNOWN_ROMIMAGE: |
| 1129 | fw_type = NX_UNIFIED_ROMIMAGE; |
| 1130 | break; |
| 1131 | |
| 1132 | case NX_UNIFIED_ROMIMAGE: |
| 1133 | if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) |
| 1134 | fw_type = NX_FLASH_ROMIMAGE; |
| 1135 | else if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1136 | fw_type = NX_P2_MN_ROMIMAGE; |
| 1137 | else if (netxen_p3_has_mn(adapter)) |
| 1138 | fw_type = NX_P3_MN_ROMIMAGE; |
| 1139 | else |
| 1140 | fw_type = NX_P3_CT_ROMIMAGE; |
| 1141 | break; |
| 1142 | |
| 1143 | case NX_P3_MN_ROMIMAGE: |
| 1144 | fw_type = NX_P3_CT_ROMIMAGE; |
| 1145 | break; |
| 1146 | |
| 1147 | case NX_P2_MN_ROMIMAGE: |
| 1148 | case NX_P3_CT_ROMIMAGE: |
| 1149 | default: |
| 1150 | fw_type = NX_FLASH_ROMIMAGE; |
| 1151 | break; |
| 1152 | } |
| 1153 | |
| 1154 | adapter->fw_type = fw_type; |
| 1155 | } |
| 1156 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1157 | static int |
| 1158 | netxen_p3_has_mn(struct netxen_adapter *adapter) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1159 | { |
| 1160 | u32 capability, flashed_ver; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1161 | capability = 0; |
| 1162 | |
Dhananjay Phadke | 634d7df | 2009-12-05 12:23:56 +0000 | [diff] [blame] | 1163 | /* NX2031 always had MN */ |
| 1164 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1165 | return 1; |
| 1166 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1167 | netxen_rom_fast_read(adapter, |
| 1168 | NX_FW_VERSION_OFFSET, (int *)&flashed_ver); |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 1169 | flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); |
| 1170 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1171 | if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1172 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1173 | capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1174 | if (capability & NX_PEG_TUNE_MN_PRESENT) |
| 1175 | return 1; |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | void netxen_request_firmware(struct netxen_adapter *adapter) |
| 1181 | { |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1182 | struct pci_dev *pdev = adapter->pdev; |
| 1183 | int rc = 0; |
| 1184 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1185 | adapter->fw_type = NX_UNKNOWN_ROMIMAGE; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1186 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1187 | next: |
| 1188 | nx_get_next_fwtype(adapter); |
Dhananjay Phadke | 7cecdca1 | 2009-10-16 15:50:10 +0000 | [diff] [blame] | 1189 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1190 | if (adapter->fw_type == NX_FLASH_ROMIMAGE) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1191 | adapter->fw = NULL; |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1192 | } else { |
| 1193 | rc = request_firmware(&adapter->fw, |
| 1194 | fw_name[adapter->fw_type], &pdev->dev); |
| 1195 | if (rc != 0) |
| 1196 | goto next; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1197 | |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1198 | rc = netxen_validate_firmware(adapter); |
| 1199 | if (rc != 0) { |
| 1200 | release_firmware(adapter->fw); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1201 | msleep(1); |
Amit Kumar Salecha | f50330f | 2009-10-24 16:03:58 +0000 | [diff] [blame] | 1202 | goto next; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1203 | } |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1204 | } |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | void |
| 1209 | netxen_release_firmware(struct netxen_adapter *adapter) |
| 1210 | { |
| 1211 | if (adapter->fw) |
| 1212 | release_firmware(adapter->fw); |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 1213 | adapter->fw = NULL; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1216 | int netxen_init_dummy_dma(struct netxen_adapter *adapter) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1217 | { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1218 | u64 addr; |
| 1219 | u32 hi, lo; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1220 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1221 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1222 | return 0; |
| 1223 | |
| 1224 | adapter->dummy_dma.addr = pci_alloc_consistent(adapter->pdev, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1225 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 1226 | &adapter->dummy_dma.phys_addr); |
| 1227 | if (adapter->dummy_dma.addr == NULL) { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1228 | dev_err(&adapter->pdev->dev, |
| 1229 | "ERROR: Could not allocate dummy DMA memory\n"); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1230 | return -ENOMEM; |
| 1231 | } |
| 1232 | |
| 1233 | addr = (uint64_t) adapter->dummy_dma.phys_addr; |
| 1234 | hi = (addr >> 32) & 0xffffffff; |
| 1235 | lo = addr & 0xffffffff; |
| 1236 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1237 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi); |
| 1238 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1239 | |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1243 | /* |
| 1244 | * NetXen DMA watchdog control: |
| 1245 | * |
| 1246 | * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive |
| 1247 | * Bit 1 : disable_request => 1 req disable dma watchdog |
| 1248 | * Bit 2 : enable_request => 1 req enable dma watchdog |
| 1249 | * Bit 3-31 : unused |
| 1250 | */ |
| 1251 | void netxen_free_dummy_dma(struct netxen_adapter *adapter) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1252 | { |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1253 | int i = 100; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1254 | u32 ctrl; |
| 1255 | |
| 1256 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1257 | return; |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1258 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1259 | if (!adapter->dummy_dma.addr) |
| 1260 | return; |
| 1261 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1262 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); |
| 1263 | if ((ctrl & 0x1) != 0) { |
| 1264 | NXWR32(adapter, NETXEN_DMA_WATCHDOG_CTRL, (ctrl | 0x2)); |
| 1265 | |
| 1266 | while ((ctrl & 0x1) != 0) { |
| 1267 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1268 | msleep(50); |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1269 | |
| 1270 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); |
| 1271 | |
| 1272 | if (--i == 0) |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1273 | break; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1274 | }; |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1275 | } |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1276 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 1277 | if (i) { |
| 1278 | pci_free_consistent(adapter->pdev, |
| 1279 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 1280 | adapter->dummy_dma.addr, |
| 1281 | adapter->dummy_dma.phys_addr); |
| 1282 | adapter->dummy_dma.addr = NULL; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 1283 | } else |
| 1284 | dev_err(&adapter->pdev->dev, "dma_watchdog_shutdown failed\n"); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1287 | int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1288 | { |
| 1289 | u32 val = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1290 | int retries = 60; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1291 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1292 | if (pegtune_val) |
| 1293 | return 0; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1294 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1295 | do { |
| 1296 | val = NXRD32(adapter, CRB_CMDPEG_STATE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1297 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1298 | switch (val) { |
| 1299 | case PHAN_INITIALIZE_COMPLETE: |
| 1300 | case PHAN_INITIALIZE_ACK: |
| 1301 | return 0; |
| 1302 | case PHAN_INITIALIZE_FAILED: |
| 1303 | goto out_err; |
| 1304 | default: |
| 1305 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1306 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1307 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 1308 | msleep(500); |
| 1309 | |
| 1310 | } while (--retries); |
| 1311 | |
| 1312 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); |
| 1313 | |
| 1314 | out_err: |
| 1315 | dev_warn(&adapter->pdev->dev, "firmware init failed\n"); |
| 1316 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1317 | } |
| 1318 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1319 | static int |
| 1320 | netxen_receive_peg_ready(struct netxen_adapter *adapter) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1321 | { |
| 1322 | u32 val = 0; |
| 1323 | int retries = 2000; |
| 1324 | |
| 1325 | do { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1326 | val = NXRD32(adapter, CRB_RCVPEG_STATE); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1327 | |
| 1328 | if (val == PHAN_PEG_RCV_INITIALIZED) |
| 1329 | return 0; |
| 1330 | |
| 1331 | msleep(10); |
| 1332 | |
| 1333 | } while (--retries); |
| 1334 | |
| 1335 | if (!retries) { |
| 1336 | printk(KERN_ERR "Receive Peg initialization not " |
| 1337 | "complete, state: 0x%x.\n", val); |
| 1338 | return -EIO; |
| 1339 | } |
| 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1344 | int netxen_init_firmware(struct netxen_adapter *adapter) |
| 1345 | { |
| 1346 | int err; |
| 1347 | |
| 1348 | err = netxen_receive_peg_ready(adapter); |
| 1349 | if (err) |
| 1350 | return err; |
| 1351 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1352 | NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT); |
| 1353 | NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC); |
| 1354 | NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE); |
| 1355 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1356 | |
| 1357 | return err; |
| 1358 | } |
| 1359 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1360 | static void |
| 1361 | netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg) |
| 1362 | { |
| 1363 | u32 cable_OUI; |
| 1364 | u16 cable_len; |
| 1365 | u16 link_speed; |
| 1366 | u8 link_status, module, duplex, autoneg; |
| 1367 | struct net_device *netdev = adapter->netdev; |
| 1368 | |
| 1369 | adapter->has_link_events = 1; |
| 1370 | |
| 1371 | cable_OUI = msg->body[1] & 0xffffffff; |
| 1372 | cable_len = (msg->body[1] >> 32) & 0xffff; |
| 1373 | link_speed = (msg->body[1] >> 48) & 0xffff; |
| 1374 | |
| 1375 | link_status = msg->body[2] & 0xff; |
| 1376 | duplex = (msg->body[2] >> 16) & 0xff; |
| 1377 | autoneg = (msg->body[2] >> 24) & 0xff; |
| 1378 | |
| 1379 | module = (msg->body[2] >> 8) & 0xff; |
| 1380 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) { |
| 1381 | printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n", |
| 1382 | netdev->name, cable_OUI, cable_len); |
| 1383 | } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) { |
| 1384 | printk(KERN_INFO "%s: unsupported cable length %d\n", |
| 1385 | netdev->name, cable_len); |
| 1386 | } |
| 1387 | |
| 1388 | netxen_advert_link_change(adapter, link_status); |
| 1389 | |
| 1390 | /* update link parameters */ |
| 1391 | if (duplex == LINKEVENT_FULL_DUPLEX) |
| 1392 | adapter->link_duplex = DUPLEX_FULL; |
| 1393 | else |
| 1394 | adapter->link_duplex = DUPLEX_HALF; |
| 1395 | adapter->module_type = module; |
| 1396 | adapter->link_autoneg = autoneg; |
| 1397 | adapter->link_speed = link_speed; |
| 1398 | } |
| 1399 | |
| 1400 | static void |
| 1401 | netxen_handle_fw_message(int desc_cnt, int index, |
| 1402 | struct nx_host_sds_ring *sds_ring) |
| 1403 | { |
| 1404 | nx_fw_msg_t msg; |
| 1405 | struct status_desc *desc; |
| 1406 | int i = 0, opcode; |
| 1407 | |
| 1408 | while (desc_cnt > 0 && i < 8) { |
| 1409 | desc = &sds_ring->desc_head[index]; |
| 1410 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); |
| 1411 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); |
| 1412 | |
| 1413 | index = get_next_index(index, sds_ring->num_desc); |
| 1414 | desc_cnt--; |
| 1415 | } |
| 1416 | |
| 1417 | opcode = netxen_get_nic_msg_opcode(msg.body[0]); |
| 1418 | switch (opcode) { |
| 1419 | case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: |
| 1420 | netxen_handle_linkevent(sds_ring->adapter, &msg); |
| 1421 | break; |
| 1422 | default: |
| 1423 | break; |
| 1424 | } |
| 1425 | } |
| 1426 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1427 | static int |
| 1428 | netxen_alloc_rx_skb(struct netxen_adapter *adapter, |
| 1429 | struct nx_host_rds_ring *rds_ring, |
| 1430 | struct netxen_rx_buffer *buffer) |
| 1431 | { |
| 1432 | struct sk_buff *skb; |
| 1433 | dma_addr_t dma; |
| 1434 | struct pci_dev *pdev = adapter->pdev; |
| 1435 | |
| 1436 | buffer->skb = dev_alloc_skb(rds_ring->skb_size); |
| 1437 | if (!buffer->skb) |
| 1438 | return 1; |
| 1439 | |
| 1440 | skb = buffer->skb; |
| 1441 | |
| 1442 | if (!adapter->ahw.cut_through) |
| 1443 | skb_reserve(skb, 2); |
| 1444 | |
| 1445 | dma = pci_map_single(pdev, skb->data, |
| 1446 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); |
| 1447 | |
| 1448 | if (pci_dma_mapping_error(pdev, dma)) { |
| 1449 | dev_kfree_skb_any(skb); |
| 1450 | buffer->skb = NULL; |
| 1451 | return 1; |
| 1452 | } |
| 1453 | |
| 1454 | buffer->skb = skb; |
| 1455 | buffer->dma = dma; |
| 1456 | buffer->state = NETXEN_BUFFER_BUSY; |
| 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1461 | static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter, |
| 1462 | struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum) |
| 1463 | { |
| 1464 | struct netxen_rx_buffer *buffer; |
| 1465 | struct sk_buff *skb; |
| 1466 | |
| 1467 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1468 | |
| 1469 | pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, |
| 1470 | PCI_DMA_FROMDEVICE); |
| 1471 | |
| 1472 | skb = buffer->skb; |
| 1473 | if (!skb) |
| 1474 | goto no_skb; |
| 1475 | |
| 1476 | if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) { |
| 1477 | adapter->stats.csummed++; |
| 1478 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1479 | } else |
| 1480 | skb->ip_summed = CHECKSUM_NONE; |
| 1481 | |
| 1482 | skb->dev = adapter->netdev; |
| 1483 | |
| 1484 | buffer->skb = NULL; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1485 | no_skb: |
| 1486 | buffer->state = NETXEN_BUFFER_FREE; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1487 | return skb; |
| 1488 | } |
| 1489 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1490 | static struct netxen_rx_buffer * |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1491 | netxen_process_rcv(struct netxen_adapter *adapter, |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1492 | struct nx_host_sds_ring *sds_ring, |
| 1493 | int ring, u64 sts_data0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1494 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1495 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1496 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1497 | struct netxen_rx_buffer *buffer; |
| 1498 | struct sk_buff *skb; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1499 | struct nx_host_rds_ring *rds_ring; |
| 1500 | int index, length, cksum, pkt_offset; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1501 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1502 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1503 | return NULL; |
| 1504 | |
| 1505 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1506 | |
| 1507 | index = netxen_get_sts_refhandle(sts_data0); |
| 1508 | if (unlikely(index >= rds_ring->num_desc)) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1509 | return NULL; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1510 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1511 | buffer = &rds_ring->rx_buf_arr[index]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1512 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1513 | length = netxen_get_sts_totallength(sts_data0); |
| 1514 | cksum = netxen_get_sts_status(sts_data0); |
| 1515 | pkt_offset = netxen_get_sts_pkt_offset(sts_data0); |
| 1516 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1517 | skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1518 | if (!skb) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1519 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1520 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1521 | if (length > rds_ring->skb_size) |
| 1522 | skb_put(skb, rds_ring->skb_size); |
| 1523 | else |
| 1524 | skb_put(skb, length); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1525 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1526 | |
| 1527 | if (pkt_offset) |
| 1528 | skb_pull(skb, pkt_offset); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1529 | |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 1530 | skb->truesize = skb->len + sizeof(struct sk_buff); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1531 | skb->protocol = eth_type_trans(skb, netdev); |
| 1532 | |
Amit Kumar Salecha | a92e9e6 | 2009-04-07 22:50:47 +0000 | [diff] [blame] | 1533 | napi_gro_receive(&sds_ring->napi, skb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1534 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1535 | adapter->stats.rx_pkts++; |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1536 | adapter->stats.rxbytes += length; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1537 | |
| 1538 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1539 | } |
| 1540 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1541 | #define TCP_HDR_SIZE 20 |
| 1542 | #define TCP_TS_OPTION_SIZE 12 |
| 1543 | #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE) |
| 1544 | |
| 1545 | static struct netxen_rx_buffer * |
| 1546 | netxen_process_lro(struct netxen_adapter *adapter, |
| 1547 | struct nx_host_sds_ring *sds_ring, |
| 1548 | int ring, u64 sts_data0, u64 sts_data1) |
| 1549 | { |
| 1550 | struct net_device *netdev = adapter->netdev; |
| 1551 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1552 | struct netxen_rx_buffer *buffer; |
| 1553 | struct sk_buff *skb; |
| 1554 | struct nx_host_rds_ring *rds_ring; |
| 1555 | struct iphdr *iph; |
| 1556 | struct tcphdr *th; |
| 1557 | bool push, timestamp; |
| 1558 | int l2_hdr_offset, l4_hdr_offset; |
| 1559 | int index; |
| 1560 | u16 lro_length, length, data_offset; |
| 1561 | u32 seq_number; |
| 1562 | |
| 1563 | if (unlikely(ring > adapter->max_rds_rings)) |
| 1564 | return NULL; |
| 1565 | |
| 1566 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1567 | |
| 1568 | index = netxen_get_lro_sts_refhandle(sts_data0); |
| 1569 | if (unlikely(index > rds_ring->num_desc)) |
| 1570 | return NULL; |
| 1571 | |
| 1572 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1573 | |
| 1574 | timestamp = netxen_get_lro_sts_timestamp(sts_data0); |
| 1575 | lro_length = netxen_get_lro_sts_length(sts_data0); |
| 1576 | l2_hdr_offset = netxen_get_lro_sts_l2_hdr_offset(sts_data0); |
| 1577 | l4_hdr_offset = netxen_get_lro_sts_l4_hdr_offset(sts_data0); |
| 1578 | push = netxen_get_lro_sts_push_flag(sts_data0); |
| 1579 | seq_number = netxen_get_lro_sts_seq_number(sts_data1); |
| 1580 | |
| 1581 | skb = netxen_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1582 | if (!skb) |
| 1583 | return buffer; |
| 1584 | |
| 1585 | if (timestamp) |
| 1586 | data_offset = l4_hdr_offset + TCP_TS_HDR_SIZE; |
| 1587 | else |
| 1588 | data_offset = l4_hdr_offset + TCP_HDR_SIZE; |
| 1589 | |
| 1590 | skb_put(skb, lro_length + data_offset); |
| 1591 | |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 1592 | skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb); |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1593 | |
| 1594 | skb_pull(skb, l2_hdr_offset); |
| 1595 | skb->protocol = eth_type_trans(skb, netdev); |
| 1596 | |
| 1597 | iph = (struct iphdr *)skb->data; |
| 1598 | th = (struct tcphdr *)(skb->data + (iph->ihl << 2)); |
| 1599 | |
| 1600 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; |
| 1601 | iph->tot_len = htons(length); |
| 1602 | iph->check = 0; |
| 1603 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 1604 | th->psh = push; |
| 1605 | th->seq = htonl(seq_number); |
| 1606 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1607 | length = skb->len; |
| 1608 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1609 | netif_receive_skb(skb); |
| 1610 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1611 | adapter->stats.lro_pkts++; |
| 1612 | adapter->stats.rxbytes += length; |
| 1613 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1614 | return buffer; |
| 1615 | } |
| 1616 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1617 | #define netxen_merge_rx_buffers(list, head) \ |
| 1618 | do { list_splice_tail_init(list, head); } while (0); |
| 1619 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1620 | int |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1621 | 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] | 1622 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1623 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 1624 | |
| 1625 | struct list_head *cur; |
| 1626 | |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1627 | struct status_desc *desc; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1628 | struct netxen_rx_buffer *rxbuf; |
| 1629 | |
| 1630 | u32 consumer = sds_ring->consumer; |
| 1631 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1632 | int count = 0; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1633 | u64 sts_data0, sts_data1; |
| 1634 | int opcode, ring = 0, desc_cnt; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1635 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1636 | while (count < max) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1637 | desc = &sds_ring->desc_head[consumer]; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1638 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1639 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1640 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1643 | desc_cnt = netxen_get_sts_desc_cnt(sts_data0); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1644 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1645 | opcode = netxen_get_sts_opcode(sts_data0); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1646 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1647 | switch (opcode) { |
| 1648 | case NETXEN_NIC_RXPKT_DESC: |
| 1649 | case NETXEN_OLD_RXPKT_DESC: |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1650 | case NETXEN_NIC_SYN_OFFLOAD: |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1651 | ring = netxen_get_sts_type(sts_data0); |
| 1652 | rxbuf = netxen_process_rcv(adapter, sds_ring, |
| 1653 | ring, sts_data0); |
| 1654 | break; |
| 1655 | case NETXEN_NIC_LRO_DESC: |
| 1656 | ring = netxen_get_lro_sts_type(sts_data0); |
| 1657 | sts_data1 = le64_to_cpu(desc->status_desc_data[1]); |
| 1658 | rxbuf = netxen_process_lro(adapter, sds_ring, |
| 1659 | ring, sts_data0, sts_data1); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1660 | break; |
| 1661 | case NETXEN_NIC_RESPONSE_DESC: |
| 1662 | netxen_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1663 | default: |
| 1664 | goto skip; |
| 1665 | } |
| 1666 | |
| 1667 | WARN_ON(desc_cnt > 1); |
| 1668 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1669 | if (rxbuf) |
| 1670 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
| 1671 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1672 | skip: |
| 1673 | for (; desc_cnt > 0; desc_cnt--) { |
| 1674 | desc = &sds_ring->desc_head[consumer]; |
| 1675 | desc->status_desc_data[0] = |
| 1676 | cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1677 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1678 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1679 | count++; |
| 1680 | } |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1681 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1682 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1683 | struct nx_host_rds_ring *rds_ring = |
| 1684 | &adapter->recv_ctx.rds_rings[ring]; |
| 1685 | |
| 1686 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1687 | list_for_each(cur, &sds_ring->free_list[ring]) { |
| 1688 | rxbuf = list_entry(cur, |
| 1689 | struct netxen_rx_buffer, list); |
| 1690 | netxen_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1691 | } |
| 1692 | spin_lock(&rds_ring->lock); |
| 1693 | netxen_merge_rx_buffers(&sds_ring->free_list[ring], |
| 1694 | &rds_ring->free_list); |
| 1695 | spin_unlock(&rds_ring->lock); |
| 1696 | } |
| 1697 | |
| 1698 | netxen_post_rx_buffers_nodb(adapter, rds_ring); |
| 1699 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1700 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1701 | if (count) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1702 | sds_ring->consumer = consumer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1703 | NXWRIO(adapter, sds_ring->crb_sts_consumer, consumer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | return count; |
| 1707 | } |
| 1708 | |
| 1709 | /* Process Command status ring */ |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1710 | int netxen_process_cmd_ring(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1711 | { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1712 | u32 sw_consumer, hw_consumer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1713 | int count = 0, i; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1714 | struct netxen_cmd_buffer *buffer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1715 | struct pci_dev *pdev = adapter->pdev; |
| 1716 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1717 | struct netxen_skb_frag *frag; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1718 | int done = 0; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1719 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1720 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1721 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 1722 | return 1; |
| 1723 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1724 | sw_consumer = tx_ring->sw_consumer; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1725 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1726 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1727 | while (sw_consumer != hw_consumer) { |
| 1728 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1729 | if (buffer->skb) { |
| 1730 | frag = &buffer->frag_array[0]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1731 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 1732 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1733 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1734 | for (i = 1; i < buffer->frag_count; i++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1735 | frag++; /* Get the next frag */ |
| 1736 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 1737 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1738 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1741 | adapter->stats.xmitfinished++; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1742 | dev_kfree_skb_any(buffer->skb); |
| 1743 | buffer->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1746 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1747 | if (++count >= MAX_STATUS_HANDLE) |
| 1748 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1749 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1750 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1751 | if (count && netif_running(netdev)) { |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1752 | tx_ring->sw_consumer = sw_consumer; |
| 1753 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1754 | smp_mb(); |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1755 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1756 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1757 | __netif_tx_lock(tx_ring->txq, smp_processor_id()); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1758 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) { |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1759 | netif_wake_queue(netdev); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1760 | adapter->tx_timeo_cnt = 0; |
| 1761 | } |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1762 | __netif_tx_unlock(tx_ring->txq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1763 | } |
| 1764 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1765 | /* |
| 1766 | * If everything is freed up to consumer then check if the ring is full |
| 1767 | * If the ring is full then check if more needs to be freed and |
| 1768 | * schedule the call back again. |
| 1769 | * |
| 1770 | * This happens when there are 2 CPUs. One could be freeing and the |
| 1771 | * other filling it. If the ring is full when we get out of here and |
| 1772 | * the card has already interrupted the host then the host can miss the |
| 1773 | * interrupt. |
| 1774 | * |
| 1775 | * There is still a possible race condition and the host could miss an |
| 1776 | * interrupt. The card has to take care of this. |
| 1777 | */ |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1778 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 1779 | done = (sw_consumer == hw_consumer); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1780 | spin_unlock(&adapter->tx_clean_lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1781 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1782 | return (done); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1785 | void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1786 | netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, |
| 1787 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1788 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1789 | struct rcv_desc *pdesc; |
| 1790 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1791 | int producer, count = 0; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1792 | netxen_ctx_msg msg = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1793 | struct list_head *head; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1794 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1795 | producer = rds_ring->producer; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1796 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1797 | spin_lock(&rds_ring->lock); |
| 1798 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1799 | while (!list_empty(head)) { |
| 1800 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1801 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1802 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1803 | if (!buffer->skb) { |
| 1804 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1805 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1809 | list_del(&buffer->list); |
| 1810 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1811 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1812 | pdesc = &rds_ring->desc_head[producer]; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1813 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1814 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1815 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1816 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1817 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1818 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1819 | spin_unlock(&rds_ring->lock); |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1820 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1821 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1822 | rds_ring->producer = producer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1823 | NXWRIO(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1824 | (producer-1) & (rds_ring->num_desc-1)); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1825 | |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1826 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1827 | /* |
| 1828 | * Write a doorbell msg to tell phanmon of change in |
| 1829 | * receive ring producer |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1830 | * Only for firmware version < 4.0.0 |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1831 | */ |
| 1832 | netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); |
| 1833 | netxen_set_msg_privid(msg); |
| 1834 | netxen_set_msg_count(msg, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1835 | ((producer - 1) & |
| 1836 | (rds_ring->num_desc - 1))); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1837 | netxen_set_msg_ctxid(msg, adapter->portnum); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1838 | netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); |
Dhananjay Phadke | f03b0eb | 2009-10-13 05:31:44 +0000 | [diff] [blame] | 1839 | NXWRIO(adapter, DB_NORMALIZE(adapter, |
| 1840 | NETXEN_RCV_PRODUCER_OFFSET), msg); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1841 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1845 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1846 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 1847 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1848 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1849 | struct rcv_desc *pdesc; |
| 1850 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1851 | int producer, count = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1852 | struct list_head *head; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1853 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1854 | producer = rds_ring->producer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1855 | if (!spin_trylock(&rds_ring->lock)) |
| 1856 | return; |
| 1857 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1858 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1859 | while (!list_empty(head)) { |
| 1860 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1861 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1862 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1863 | if (!buffer->skb) { |
| 1864 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1865 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1869 | list_del(&buffer->list); |
| 1870 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1871 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1872 | pdesc = &rds_ring->desc_head[producer]; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1873 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1874 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1875 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1876 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1877 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1878 | } |
| 1879 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1880 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1881 | rds_ring->producer = producer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1882 | NXWRIO(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1883 | (producer - 1) & (rds_ring->num_desc - 1)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1884 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1885 | spin_unlock(&rds_ring->lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1888 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) |
| 1889 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1890 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1891 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1892 | } |
| 1893 | |