Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 - 2009 ServerEngines |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
| 11 | * linux-drivers@serverengines.com |
| 12 | * |
| 13 | * ServerEngines |
| 14 | * 209 N. Fair Oaks Ave |
| 15 | * Sunnyvale, CA 94085 |
| 16 | */ |
| 17 | |
| 18 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 19 | #include "be_cmds.h" |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 20 | #include <asm/div64.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 21 | |
| 22 | MODULE_VERSION(DRV_VER); |
| 23 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
| 24 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
| 25 | MODULE_AUTHOR("ServerEngines Corporation"); |
| 26 | MODULE_LICENSE("GPL"); |
| 27 | |
| 28 | static unsigned int rx_frag_size = 2048; |
| 29 | module_param(rx_frag_size, uint, S_IRUGO); |
| 30 | MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data."); |
| 31 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 32 | static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 33 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
| 34 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 35 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 36 | { 0 } |
| 37 | }; |
| 38 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
| 39 | |
| 40 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 41 | { |
| 42 | struct be_dma_mem *mem = &q->dma_mem; |
| 43 | if (mem->va) |
| 44 | pci_free_consistent(adapter->pdev, mem->size, |
| 45 | mem->va, mem->dma); |
| 46 | } |
| 47 | |
| 48 | static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q, |
| 49 | u16 len, u16 entry_size) |
| 50 | { |
| 51 | struct be_dma_mem *mem = &q->dma_mem; |
| 52 | |
| 53 | memset(q, 0, sizeof(*q)); |
| 54 | q->len = len; |
| 55 | q->entry_size = entry_size; |
| 56 | mem->size = len * entry_size; |
| 57 | mem->va = pci_alloc_consistent(adapter->pdev, mem->size, &mem->dma); |
| 58 | if (!mem->va) |
| 59 | return -1; |
| 60 | memset(mem->va, 0, mem->size); |
| 61 | return 0; |
| 62 | } |
| 63 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 64 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 65 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 66 | u8 __iomem *addr = adapter->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 67 | u32 reg = ioread32(addr); |
| 68 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 69 | |
| 70 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 71 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 72 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 73 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 74 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 75 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 76 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 77 | iowrite32(reg, addr); |
| 78 | } |
| 79 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 80 | static void be_rxq_notify(struct be_adapter *adapter, u16 qid, u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 81 | { |
| 82 | u32 val = 0; |
| 83 | val |= qid & DB_RQ_RING_ID_MASK; |
| 84 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 85 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 88 | static void be_txq_notify(struct be_adapter *adapter, u16 qid, u16 posted) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 89 | { |
| 90 | u32 val = 0; |
| 91 | val |= qid & DB_TXULP_RING_ID_MASK; |
| 92 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 93 | iowrite32(val, adapter->db + DB_TXULP1_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 96 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 97 | bool arm, bool clear_int, u16 num_popped) |
| 98 | { |
| 99 | u32 val = 0; |
| 100 | val |= qid & DB_EQ_RING_ID_MASK; |
| 101 | if (arm) |
| 102 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 103 | if (clear_int) |
| 104 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 105 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 106 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 107 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 110 | void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 111 | { |
| 112 | u32 val = 0; |
| 113 | val |= qid & DB_CQ_RING_ID_MASK; |
| 114 | if (arm) |
| 115 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 116 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 117 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 120 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 121 | { |
| 122 | struct be_adapter *adapter = netdev_priv(netdev); |
| 123 | struct sockaddr *addr = p; |
| 124 | int status = 0; |
| 125 | |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 126 | status = be_cmd_pmac_del(adapter, adapter->if_handle, adapter->pmac_id); |
| 127 | if (status) |
| 128 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 129 | |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 130 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
| 131 | adapter->if_handle, &adapter->pmac_id); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 132 | if (!status) |
| 133 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 134 | |
| 135 | return status; |
| 136 | } |
| 137 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 138 | void netdev_stats_update(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 139 | { |
| 140 | struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va); |
| 141 | struct be_rxf_stats *rxf_stats = &hw_stats->rxf; |
| 142 | struct be_port_rxf_stats *port_stats = |
| 143 | &rxf_stats->port[adapter->port_num]; |
Ajit Khaparde | 78122a5 | 2009-10-07 03:11:20 -0700 | [diff] [blame] | 144 | struct net_device_stats *dev_stats = &adapter->netdev->stats; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 145 | struct be_erx_stats *erx_stats = &hw_stats->erx; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 146 | |
| 147 | dev_stats->rx_packets = port_stats->rx_total_frames; |
| 148 | dev_stats->tx_packets = port_stats->tx_unicastframes + |
| 149 | port_stats->tx_multicastframes + port_stats->tx_broadcastframes; |
| 150 | dev_stats->rx_bytes = (u64) port_stats->rx_bytes_msd << 32 | |
| 151 | (u64) port_stats->rx_bytes_lsd; |
| 152 | dev_stats->tx_bytes = (u64) port_stats->tx_bytes_msd << 32 | |
| 153 | (u64) port_stats->tx_bytes_lsd; |
| 154 | |
| 155 | /* bad pkts received */ |
| 156 | dev_stats->rx_errors = port_stats->rx_crc_errors + |
| 157 | port_stats->rx_alignment_symbol_errors + |
| 158 | port_stats->rx_in_range_errors + |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 159 | port_stats->rx_out_range_errors + |
| 160 | port_stats->rx_frame_too_long + |
| 161 | port_stats->rx_dropped_too_small + |
| 162 | port_stats->rx_dropped_too_short + |
| 163 | port_stats->rx_dropped_header_too_small + |
| 164 | port_stats->rx_dropped_tcp_length + |
| 165 | port_stats->rx_dropped_runt + |
| 166 | port_stats->rx_tcp_checksum_errs + |
| 167 | port_stats->rx_ip_checksum_errs + |
| 168 | port_stats->rx_udp_checksum_errs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 169 | |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 170 | /* no space in linux buffers: best possible approximation */ |
| 171 | dev_stats->rx_dropped = erx_stats->rx_drops_no_fragments[0]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 172 | |
| 173 | /* detailed rx errors */ |
| 174 | dev_stats->rx_length_errors = port_stats->rx_in_range_errors + |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 175 | port_stats->rx_out_range_errors + |
| 176 | port_stats->rx_frame_too_long; |
| 177 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 178 | /* receive ring buffer overflow */ |
| 179 | dev_stats->rx_over_errors = 0; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 180 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 181 | dev_stats->rx_crc_errors = port_stats->rx_crc_errors; |
| 182 | |
| 183 | /* frame alignment errors */ |
| 184 | dev_stats->rx_frame_errors = port_stats->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 185 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 186 | /* receiver fifo overrun */ |
| 187 | /* drops_no_pbuf is no per i/f, it's per BE card */ |
| 188 | dev_stats->rx_fifo_errors = port_stats->rx_fifo_overflow + |
| 189 | port_stats->rx_input_fifo_overflow + |
| 190 | rxf_stats->rx_drops_no_pbuf; |
| 191 | /* receiver missed packetd */ |
| 192 | dev_stats->rx_missed_errors = 0; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 193 | |
| 194 | /* packet transmit problems */ |
| 195 | dev_stats->tx_errors = 0; |
| 196 | |
| 197 | /* no space available in linux */ |
| 198 | dev_stats->tx_dropped = 0; |
| 199 | |
Ajit Khaparde | c5b9b92 | 2009-10-05 02:21:51 +0000 | [diff] [blame] | 200 | dev_stats->multicast = port_stats->rx_multicast_frames; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 201 | dev_stats->collisions = 0; |
| 202 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 203 | /* detailed tx_errors */ |
| 204 | dev_stats->tx_aborted_errors = 0; |
| 205 | dev_stats->tx_carrier_errors = 0; |
| 206 | dev_stats->tx_fifo_errors = 0; |
| 207 | dev_stats->tx_heartbeat_errors = 0; |
| 208 | dev_stats->tx_window_errors = 0; |
| 209 | } |
| 210 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 211 | void be_link_status_update(struct be_adapter *adapter, bool link_up) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 212 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 213 | struct net_device *netdev = adapter->netdev; |
| 214 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 215 | /* If link came up or went down */ |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 216 | if (adapter->link_up != link_up) { |
| 217 | if (link_up) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 218 | netif_start_queue(netdev); |
| 219 | netif_carrier_on(netdev); |
| 220 | printk(KERN_INFO "%s: Link up\n", netdev->name); |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 221 | } else { |
| 222 | netif_stop_queue(netdev); |
| 223 | netif_carrier_off(netdev); |
| 224 | printk(KERN_INFO "%s: Link down\n", netdev->name); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 225 | } |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 226 | adapter->link_up = link_up; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 227 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* Update the EQ delay n BE based on the RX frags consumed / sec */ |
| 231 | static void be_rx_eqd_update(struct be_adapter *adapter) |
| 232 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 233 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 234 | struct be_drvr_stats *stats = &adapter->stats.drvr_stats; |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 235 | ulong now = jiffies; |
| 236 | u32 eqd; |
| 237 | |
| 238 | if (!rx_eq->enable_aic) |
| 239 | return; |
| 240 | |
| 241 | /* Wrapped around */ |
| 242 | if (time_before(now, stats->rx_fps_jiffies)) { |
| 243 | stats->rx_fps_jiffies = now; |
| 244 | return; |
| 245 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 246 | |
| 247 | /* Update once a second */ |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 248 | if ((now - stats->rx_fps_jiffies) < HZ) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 249 | return; |
| 250 | |
| 251 | stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) / |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 252 | ((now - stats->rx_fps_jiffies) / HZ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 253 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 254 | stats->rx_fps_jiffies = now; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 255 | stats->be_prev_rx_frags = stats->be_rx_frags; |
| 256 | eqd = stats->be_rx_fps / 110000; |
| 257 | eqd = eqd << 3; |
| 258 | if (eqd > rx_eq->max_eqd) |
| 259 | eqd = rx_eq->max_eqd; |
| 260 | if (eqd < rx_eq->min_eqd) |
| 261 | eqd = rx_eq->min_eqd; |
| 262 | if (eqd < 10) |
| 263 | eqd = 0; |
| 264 | if (eqd != rx_eq->cur_eqd) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 265 | be_cmd_modify_eqd(adapter, rx_eq->q.id, eqd); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 266 | |
| 267 | rx_eq->cur_eqd = eqd; |
| 268 | } |
| 269 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 270 | static struct net_device_stats *be_get_stats(struct net_device *dev) |
| 271 | { |
Ajit Khaparde | 78122a5 | 2009-10-07 03:11:20 -0700 | [diff] [blame] | 272 | return &dev->stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 275 | static u32 be_calc_rate(u64 bytes, unsigned long ticks) |
| 276 | { |
| 277 | u64 rate = bytes; |
| 278 | |
| 279 | do_div(rate, ticks / HZ); |
| 280 | rate <<= 3; /* bytes/sec -> bits/sec */ |
| 281 | do_div(rate, 1000000ul); /* MB/Sec */ |
| 282 | |
| 283 | return rate; |
| 284 | } |
| 285 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 286 | static void be_tx_rate_update(struct be_adapter *adapter) |
| 287 | { |
| 288 | struct be_drvr_stats *stats = drvr_stats(adapter); |
| 289 | ulong now = jiffies; |
| 290 | |
| 291 | /* Wrapped around? */ |
| 292 | if (time_before(now, stats->be_tx_jiffies)) { |
| 293 | stats->be_tx_jiffies = now; |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | /* Update tx rate once in two seconds */ |
| 298 | if ((now - stats->be_tx_jiffies) > 2 * HZ) { |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 299 | stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes |
| 300 | - stats->be_tx_bytes_prev, |
| 301 | now - stats->be_tx_jiffies); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 302 | stats->be_tx_jiffies = now; |
| 303 | stats->be_tx_bytes_prev = stats->be_tx_bytes; |
| 304 | } |
| 305 | } |
| 306 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 307 | static void be_tx_stats_update(struct be_adapter *adapter, |
| 308 | u32 wrb_cnt, u32 copied, bool stopped) |
| 309 | { |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 310 | struct be_drvr_stats *stats = drvr_stats(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 311 | stats->be_tx_reqs++; |
| 312 | stats->be_tx_wrbs += wrb_cnt; |
| 313 | stats->be_tx_bytes += copied; |
| 314 | if (stopped) |
| 315 | stats->be_tx_stops++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* Determine number of WRB entries needed to xmit data in an skb */ |
| 319 | static u32 wrb_cnt_for_skb(struct sk_buff *skb, bool *dummy) |
| 320 | { |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 321 | int cnt = (skb->len > skb->data_len); |
| 322 | |
| 323 | cnt += skb_shinfo(skb)->nr_frags; |
| 324 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 325 | /* to account for hdr wrb */ |
| 326 | cnt++; |
| 327 | if (cnt & 1) { |
| 328 | /* add a dummy to make it an even num */ |
| 329 | cnt++; |
| 330 | *dummy = true; |
| 331 | } else |
| 332 | *dummy = false; |
| 333 | BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT); |
| 334 | return cnt; |
| 335 | } |
| 336 | |
| 337 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 338 | { |
| 339 | wrb->frag_pa_hi = upper_32_bits(addr); |
| 340 | wrb->frag_pa_lo = addr & 0xFFFFFFFF; |
| 341 | wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK; |
| 342 | } |
| 343 | |
| 344 | static void wrb_fill_hdr(struct be_eth_hdr_wrb *hdr, struct sk_buff *skb, |
| 345 | bool vlan, u32 wrb_cnt, u32 len) |
| 346 | { |
| 347 | memset(hdr, 0, sizeof(*hdr)); |
| 348 | |
| 349 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1); |
| 350 | |
| 351 | if (skb_shinfo(skb)->gso_segs > 1 && skb_shinfo(skb)->gso_size) { |
| 352 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1); |
| 353 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss, |
| 354 | hdr, skb_shinfo(skb)->gso_size); |
| 355 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 356 | if (is_tcp_pkt(skb)) |
| 357 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1); |
| 358 | else if (is_udp_pkt(skb)) |
| 359 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1); |
| 360 | } |
| 361 | |
| 362 | if (vlan && vlan_tx_tag_present(skb)) { |
| 363 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1); |
| 364 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag, |
| 365 | hdr, vlan_tx_tag_get(skb)); |
| 366 | } |
| 367 | |
| 368 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1); |
| 369 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, 1); |
| 370 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt); |
| 371 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | static int make_tx_wrbs(struct be_adapter *adapter, |
| 376 | struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb) |
| 377 | { |
| 378 | u64 busaddr; |
| 379 | u32 i, copied = 0; |
| 380 | struct pci_dev *pdev = adapter->pdev; |
| 381 | struct sk_buff *first_skb = skb; |
| 382 | struct be_queue_info *txq = &adapter->tx_obj.q; |
| 383 | struct be_eth_wrb *wrb; |
| 384 | struct be_eth_hdr_wrb *hdr; |
| 385 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 386 | hdr = queue_head_node(txq); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 387 | atomic_add(wrb_cnt, &txq->used); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 388 | queue_head_inc(txq); |
| 389 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 390 | if (skb_dma_map(&pdev->dev, skb, DMA_TO_DEVICE)) { |
| 391 | dev_err(&pdev->dev, "TX DMA mapping failed\n"); |
| 392 | return 0; |
| 393 | } |
| 394 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 395 | if (skb->len > skb->data_len) { |
| 396 | int len = skb->len - skb->data_len; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 397 | wrb = queue_head_node(txq); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 398 | busaddr = skb_shinfo(skb)->dma_head; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 399 | wrb_fill(wrb, busaddr, len); |
| 400 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 401 | queue_head_inc(txq); |
| 402 | copied += len; |
| 403 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 404 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 405 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 406 | struct skb_frag_struct *frag = |
| 407 | &skb_shinfo(skb)->frags[i]; |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 408 | |
| 409 | busaddr = skb_shinfo(skb)->dma_maps[i]; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 410 | wrb = queue_head_node(txq); |
| 411 | wrb_fill(wrb, busaddr, frag->size); |
| 412 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 413 | queue_head_inc(txq); |
| 414 | copied += frag->size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | if (dummy_wrb) { |
| 418 | wrb = queue_head_node(txq); |
| 419 | wrb_fill(wrb, 0, 0); |
| 420 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 421 | queue_head_inc(txq); |
| 422 | } |
| 423 | |
| 424 | wrb_fill_hdr(hdr, first_skb, adapter->vlan_grp ? true : false, |
| 425 | wrb_cnt, copied); |
| 426 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 427 | |
| 428 | return copied; |
| 429 | } |
| 430 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 431 | static netdev_tx_t be_xmit(struct sk_buff *skb, |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 432 | struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 433 | { |
| 434 | struct be_adapter *adapter = netdev_priv(netdev); |
| 435 | struct be_tx_obj *tx_obj = &adapter->tx_obj; |
| 436 | struct be_queue_info *txq = &tx_obj->q; |
| 437 | u32 wrb_cnt = 0, copied = 0; |
| 438 | u32 start = txq->head; |
| 439 | bool dummy_wrb, stopped = false; |
| 440 | |
| 441 | wrb_cnt = wrb_cnt_for_skb(skb, &dummy_wrb); |
| 442 | |
| 443 | copied = make_tx_wrbs(adapter, skb, wrb_cnt, dummy_wrb); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 444 | if (copied) { |
| 445 | /* record the sent skb in the sent_skb table */ |
| 446 | BUG_ON(tx_obj->sent_skb_list[start]); |
| 447 | tx_obj->sent_skb_list[start] = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 448 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 449 | /* Ensure txq has space for the next skb; Else stop the queue |
| 450 | * *BEFORE* ringing the tx doorbell, so that we serialze the |
| 451 | * tx compls of the current transmit which'll wake up the queue |
| 452 | */ |
| 453 | if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >= |
| 454 | txq->len) { |
| 455 | netif_stop_queue(netdev); |
| 456 | stopped = true; |
| 457 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 458 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 459 | be_txq_notify(adapter, txq->id, wrb_cnt); |
| 460 | |
| 461 | be_tx_stats_update(adapter, wrb_cnt, copied, stopped); |
| 462 | } else { |
| 463 | txq->head = start; |
| 464 | dev_kfree_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 465 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 466 | return NETDEV_TX_OK; |
| 467 | } |
| 468 | |
| 469 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 470 | { |
| 471 | struct be_adapter *adapter = netdev_priv(netdev); |
| 472 | if (new_mtu < BE_MIN_MTU || |
| 473 | new_mtu > BE_MAX_JUMBO_FRAME_SIZE) { |
| 474 | dev_info(&adapter->pdev->dev, |
| 475 | "MTU must be between %d and %d bytes\n", |
| 476 | BE_MIN_MTU, BE_MAX_JUMBO_FRAME_SIZE); |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n", |
| 480 | netdev->mtu, new_mtu); |
| 481 | netdev->mtu = new_mtu; |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | * if there are BE_NUM_VLANS_SUPPORTED or lesser number of VLANS configured, |
| 487 | * program them in BE. If more than BE_NUM_VLANS_SUPPORTED are configured, |
| 488 | * set the BE in promiscuous VLAN mode. |
| 489 | */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 490 | static int be_vid_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 491 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 492 | u16 vtag[BE_NUM_VLANS_SUPPORTED]; |
| 493 | u16 ntags = 0, i; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 494 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 495 | |
| 496 | if (adapter->num_vlans <= BE_NUM_VLANS_SUPPORTED) { |
| 497 | /* Construct VLAN Table to give to HW */ |
| 498 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 499 | if (adapter->vlan_tag[i]) { |
| 500 | vtag[ntags] = cpu_to_le16(i); |
| 501 | ntags++; |
| 502 | } |
| 503 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 504 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 505 | vtag, ntags, 1, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 506 | } else { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 507 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 508 | NULL, 0, 1, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 509 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 510 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static void be_vlan_register(struct net_device *netdev, struct vlan_group *grp) |
| 514 | { |
| 515 | struct be_adapter *adapter = netdev_priv(netdev); |
| 516 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 517 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 518 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 519 | be_eq_notify(adapter, rx_eq->q.id, false, false, 0); |
| 520 | be_eq_notify(adapter, tx_eq->q.id, false, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 521 | adapter->vlan_grp = grp; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 522 | be_eq_notify(adapter, rx_eq->q.id, true, false, 0); |
| 523 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void be_vlan_add_vid(struct net_device *netdev, u16 vid) |
| 527 | { |
| 528 | struct be_adapter *adapter = netdev_priv(netdev); |
| 529 | |
| 530 | adapter->num_vlans++; |
| 531 | adapter->vlan_tag[vid] = 1; |
| 532 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 533 | be_vid_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void be_vlan_rem_vid(struct net_device *netdev, u16 vid) |
| 537 | { |
| 538 | struct be_adapter *adapter = netdev_priv(netdev); |
| 539 | |
| 540 | adapter->num_vlans--; |
| 541 | adapter->vlan_tag[vid] = 0; |
| 542 | |
| 543 | vlan_group_set_device(adapter->vlan_grp, vid, NULL); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 544 | be_vid_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 547 | static void be_set_multicast_list(struct net_device *netdev) |
| 548 | { |
| 549 | struct be_adapter *adapter = netdev_priv(netdev); |
| 550 | |
| 551 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 552 | be_cmd_promiscuous_config(adapter, adapter->port_num, 1); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 553 | adapter->promiscuous = true; |
| 554 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 555 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 556 | |
| 557 | /* BE was previously in promiscous mode; disable it */ |
| 558 | if (adapter->promiscuous) { |
| 559 | adapter->promiscuous = false; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 560 | be_cmd_promiscuous_config(adapter, adapter->port_num, 0); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | if (netdev->flags & IFF_ALLMULTI) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 564 | be_cmd_multicast_set(adapter, adapter->if_handle, NULL, 0); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 565 | goto done; |
| 566 | } |
| 567 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 568 | be_cmd_multicast_set(adapter, adapter->if_handle, netdev->mc_list, |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 569 | netdev->mc_count); |
| 570 | done: |
| 571 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 574 | static void be_rx_rate_update(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 575 | { |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 576 | struct be_drvr_stats *stats = drvr_stats(adapter); |
| 577 | ulong now = jiffies; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 578 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 579 | /* Wrapped around */ |
| 580 | if (time_before(now, stats->be_rx_jiffies)) { |
| 581 | stats->be_rx_jiffies = now; |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | /* Update the rate once in two seconds */ |
| 586 | if ((now - stats->be_rx_jiffies) < 2 * HZ) |
| 587 | return; |
| 588 | |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 589 | stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes |
| 590 | - stats->be_rx_bytes_prev, |
| 591 | now - stats->be_rx_jiffies); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 592 | stats->be_rx_jiffies = now; |
| 593 | stats->be_rx_bytes_prev = stats->be_rx_bytes; |
| 594 | } |
| 595 | |
| 596 | static void be_rx_stats_update(struct be_adapter *adapter, |
| 597 | u32 pktsize, u16 numfrags) |
| 598 | { |
| 599 | struct be_drvr_stats *stats = drvr_stats(adapter); |
| 600 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 601 | stats->be_rx_compl++; |
| 602 | stats->be_rx_frags += numfrags; |
| 603 | stats->be_rx_bytes += pktsize; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 606 | static inline bool do_pkt_csum(struct be_eth_rx_compl *rxcp, bool cso) |
| 607 | { |
| 608 | u8 l4_cksm, ip_version, ipcksm, tcpf = 0, udpf = 0, ipv6_chk; |
| 609 | |
| 610 | l4_cksm = AMAP_GET_BITS(struct amap_eth_rx_compl, l4_cksm, rxcp); |
| 611 | ipcksm = AMAP_GET_BITS(struct amap_eth_rx_compl, ipcksm, rxcp); |
| 612 | ip_version = AMAP_GET_BITS(struct amap_eth_rx_compl, ip_version, rxcp); |
| 613 | if (ip_version) { |
| 614 | tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp); |
| 615 | udpf = AMAP_GET_BITS(struct amap_eth_rx_compl, udpf, rxcp); |
| 616 | } |
| 617 | ipv6_chk = (ip_version && (tcpf || udpf)); |
| 618 | |
| 619 | return ((l4_cksm && ipv6_chk && ipcksm) && cso) ? false : true; |
| 620 | } |
| 621 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 622 | static struct be_rx_page_info * |
| 623 | get_rx_page_info(struct be_adapter *adapter, u16 frag_idx) |
| 624 | { |
| 625 | struct be_rx_page_info *rx_page_info; |
| 626 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
| 627 | |
| 628 | rx_page_info = &adapter->rx_obj.page_info_tbl[frag_idx]; |
| 629 | BUG_ON(!rx_page_info->page); |
| 630 | |
| 631 | if (rx_page_info->last_page_user) |
| 632 | pci_unmap_page(adapter->pdev, pci_unmap_addr(rx_page_info, bus), |
| 633 | adapter->big_page_size, PCI_DMA_FROMDEVICE); |
| 634 | |
| 635 | atomic_dec(&rxq->used); |
| 636 | return rx_page_info; |
| 637 | } |
| 638 | |
| 639 | /* Throwaway the data in the Rx completion */ |
| 640 | static void be_rx_compl_discard(struct be_adapter *adapter, |
| 641 | struct be_eth_rx_compl *rxcp) |
| 642 | { |
| 643 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
| 644 | struct be_rx_page_info *page_info; |
| 645 | u16 rxq_idx, i, num_rcvd; |
| 646 | |
| 647 | rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp); |
| 648 | num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp); |
| 649 | |
| 650 | for (i = 0; i < num_rcvd; i++) { |
| 651 | page_info = get_rx_page_info(adapter, rxq_idx); |
| 652 | put_page(page_info->page); |
| 653 | memset(page_info, 0, sizeof(*page_info)); |
| 654 | index_inc(&rxq_idx, rxq->len); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 660 | * indicated by rxcp. |
| 661 | */ |
| 662 | static void skb_fill_rx_data(struct be_adapter *adapter, |
| 663 | struct sk_buff *skb, struct be_eth_rx_compl *rxcp) |
| 664 | { |
| 665 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
| 666 | struct be_rx_page_info *page_info; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 667 | u16 rxq_idx, i, num_rcvd, j; |
Ajit Khaparde | fa77406 | 2009-07-22 09:28:55 -0700 | [diff] [blame] | 668 | u32 pktsize, hdr_len, curr_frag_len, size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 669 | u8 *start; |
| 670 | |
| 671 | rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp); |
| 672 | pktsize = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp); |
| 673 | num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp); |
| 674 | |
| 675 | page_info = get_rx_page_info(adapter, rxq_idx); |
| 676 | |
| 677 | start = page_address(page_info->page) + page_info->page_offset; |
| 678 | prefetch(start); |
| 679 | |
| 680 | /* Copy data in the first descriptor of this completion */ |
| 681 | curr_frag_len = min(pktsize, rx_frag_size); |
| 682 | |
| 683 | /* Copy the header portion into skb_data */ |
| 684 | hdr_len = min((u32)BE_HDR_LEN, curr_frag_len); |
| 685 | memcpy(skb->data, start, hdr_len); |
| 686 | skb->len = curr_frag_len; |
| 687 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
| 688 | /* Complete packet has now been moved to data */ |
| 689 | put_page(page_info->page); |
| 690 | skb->data_len = 0; |
| 691 | skb->tail += curr_frag_len; |
| 692 | } else { |
| 693 | skb_shinfo(skb)->nr_frags = 1; |
| 694 | skb_shinfo(skb)->frags[0].page = page_info->page; |
| 695 | skb_shinfo(skb)->frags[0].page_offset = |
| 696 | page_info->page_offset + hdr_len; |
| 697 | skb_shinfo(skb)->frags[0].size = curr_frag_len - hdr_len; |
| 698 | skb->data_len = curr_frag_len - hdr_len; |
| 699 | skb->tail += hdr_len; |
| 700 | } |
| 701 | memset(page_info, 0, sizeof(*page_info)); |
| 702 | |
| 703 | if (pktsize <= rx_frag_size) { |
| 704 | BUG_ON(num_rcvd != 1); |
Sathya Perla | 76fbb42 | 2009-06-10 02:21:56 +0000 | [diff] [blame] | 705 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /* More frags present for this completion */ |
Ajit Khaparde | fa77406 | 2009-07-22 09:28:55 -0700 | [diff] [blame] | 709 | size = pktsize; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 710 | for (i = 1, j = 0; i < num_rcvd; i++) { |
Ajit Khaparde | fa77406 | 2009-07-22 09:28:55 -0700 | [diff] [blame] | 711 | size -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 712 | index_inc(&rxq_idx, rxq->len); |
| 713 | page_info = get_rx_page_info(adapter, rxq_idx); |
| 714 | |
Ajit Khaparde | fa77406 | 2009-07-22 09:28:55 -0700 | [diff] [blame] | 715 | curr_frag_len = min(size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 716 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 717 | /* Coalesce all frags from the same physical page in one slot */ |
| 718 | if (page_info->page_offset == 0) { |
| 719 | /* Fresh page */ |
| 720 | j++; |
| 721 | skb_shinfo(skb)->frags[j].page = page_info->page; |
| 722 | skb_shinfo(skb)->frags[j].page_offset = |
| 723 | page_info->page_offset; |
| 724 | skb_shinfo(skb)->frags[j].size = 0; |
| 725 | skb_shinfo(skb)->nr_frags++; |
| 726 | } else { |
| 727 | put_page(page_info->page); |
| 728 | } |
| 729 | |
| 730 | skb_shinfo(skb)->frags[j].size += curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 731 | skb->len += curr_frag_len; |
| 732 | skb->data_len += curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 733 | |
| 734 | memset(page_info, 0, sizeof(*page_info)); |
| 735 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 736 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 737 | |
Sathya Perla | 76fbb42 | 2009-06-10 02:21:56 +0000 | [diff] [blame] | 738 | done: |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 739 | be_rx_stats_update(adapter, pktsize, num_rcvd); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 740 | return; |
| 741 | } |
| 742 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 743 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 744 | static void be_rx_compl_process(struct be_adapter *adapter, |
| 745 | struct be_eth_rx_compl *rxcp) |
| 746 | { |
| 747 | struct sk_buff *skb; |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 748 | u32 vlanf, vid; |
| 749 | u8 vtm; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 750 | |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 751 | vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp); |
| 752 | vtm = AMAP_GET_BITS(struct amap_eth_rx_compl, vtm, rxcp); |
| 753 | |
| 754 | /* vlanf could be wrongly set in some cards. |
| 755 | * ignore if vtm is not set */ |
| 756 | if ((adapter->cap == 0x400) && !vtm) |
| 757 | vlanf = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 758 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame^] | 759 | skb = netdev_alloc_skb_ip_align(adapter->netdev, BE_HDR_LEN); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 760 | if (!skb) { |
| 761 | if (net_ratelimit()) |
| 762 | dev_warn(&adapter->pdev->dev, "skb alloc failed\n"); |
| 763 | be_rx_compl_discard(adapter, rxcp); |
| 764 | return; |
| 765 | } |
| 766 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 767 | skb_fill_rx_data(adapter, skb, rxcp); |
| 768 | |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 769 | if (do_pkt_csum(rxcp, adapter->rx_csum)) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 770 | skb->ip_summed = CHECKSUM_NONE; |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 771 | else |
| 772 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 773 | |
| 774 | skb->truesize = skb->len + sizeof(struct sk_buff); |
| 775 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
| 776 | skb->dev = adapter->netdev; |
| 777 | |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 778 | if (vlanf) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 779 | if (!adapter->vlan_grp || adapter->num_vlans == 0) { |
| 780 | kfree_skb(skb); |
| 781 | return; |
| 782 | } |
| 783 | vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp); |
| 784 | vid = be16_to_cpu(vid); |
| 785 | vlan_hwaccel_receive_skb(skb, adapter->vlan_grp, vid); |
| 786 | } else { |
| 787 | netif_receive_skb(skb); |
| 788 | } |
| 789 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 790 | return; |
| 791 | } |
| 792 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 793 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
| 794 | static void be_rx_compl_process_gro(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 795 | struct be_eth_rx_compl *rxcp) |
| 796 | { |
| 797 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 798 | struct sk_buff *skb = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 799 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 800 | struct be_eq_obj *eq_obj = &adapter->rx_eq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 801 | u32 num_rcvd, pkt_size, remaining, vlanf, curr_frag_len; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 802 | u16 i, rxq_idx = 0, vid, j; |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 803 | u8 vtm; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 804 | |
| 805 | num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp); |
| 806 | pkt_size = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp); |
| 807 | vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp); |
| 808 | rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp); |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 809 | vtm = AMAP_GET_BITS(struct amap_eth_rx_compl, vtm, rxcp); |
| 810 | |
| 811 | /* vlanf could be wrongly set in some cards. |
| 812 | * ignore if vtm is not set */ |
| 813 | if ((adapter->cap == 0x400) && !vtm) |
| 814 | vlanf = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 815 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 816 | skb = napi_get_frags(&eq_obj->napi); |
| 817 | if (!skb) { |
| 818 | be_rx_compl_discard(adapter, rxcp); |
| 819 | return; |
| 820 | } |
| 821 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 822 | remaining = pkt_size; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 823 | for (i = 0, j = -1; i < num_rcvd; i++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 824 | page_info = get_rx_page_info(adapter, rxq_idx); |
| 825 | |
| 826 | curr_frag_len = min(remaining, rx_frag_size); |
| 827 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 828 | /* Coalesce all frags from the same physical page in one slot */ |
| 829 | if (i == 0 || page_info->page_offset == 0) { |
| 830 | /* First frag or Fresh page */ |
| 831 | j++; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 832 | skb_shinfo(skb)->frags[j].page = page_info->page; |
| 833 | skb_shinfo(skb)->frags[j].page_offset = |
| 834 | page_info->page_offset; |
| 835 | skb_shinfo(skb)->frags[j].size = 0; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 836 | } else { |
| 837 | put_page(page_info->page); |
| 838 | } |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 839 | skb_shinfo(skb)->frags[j].size += curr_frag_len; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 840 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 841 | remaining -= curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 842 | index_inc(&rxq_idx, rxq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 843 | memset(page_info, 0, sizeof(*page_info)); |
| 844 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 845 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 846 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 847 | skb_shinfo(skb)->nr_frags = j + 1; |
| 848 | skb->len = pkt_size; |
| 849 | skb->data_len = pkt_size; |
| 850 | skb->truesize += pkt_size; |
| 851 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 852 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 853 | if (likely(!vlanf)) { |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 854 | napi_gro_frags(&eq_obj->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 855 | } else { |
| 856 | vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp); |
| 857 | vid = be16_to_cpu(vid); |
| 858 | |
| 859 | if (!adapter->vlan_grp || adapter->num_vlans == 0) |
| 860 | return; |
| 861 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 862 | vlan_gro_frags(&eq_obj->napi, adapter->vlan_grp, vid); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 865 | be_rx_stats_update(adapter, pkt_size, num_rcvd); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 866 | return; |
| 867 | } |
| 868 | |
| 869 | static struct be_eth_rx_compl *be_rx_compl_get(struct be_adapter *adapter) |
| 870 | { |
| 871 | struct be_eth_rx_compl *rxcp = queue_tail_node(&adapter->rx_obj.cq); |
| 872 | |
| 873 | if (rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] == 0) |
| 874 | return NULL; |
| 875 | |
| 876 | be_dws_le_to_cpu(rxcp, sizeof(*rxcp)); |
| 877 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 878 | queue_tail_inc(&adapter->rx_obj.cq); |
| 879 | return rxcp; |
| 880 | } |
| 881 | |
Sathya Perla | a7a0ef3 | 2009-06-10 02:23:28 +0000 | [diff] [blame] | 882 | /* To reset the valid bit, we need to reset the whole word as |
| 883 | * when walking the queue the valid entries are little-endian |
| 884 | * and invalid entries are host endian |
| 885 | */ |
| 886 | static inline void be_rx_compl_reset(struct be_eth_rx_compl *rxcp) |
| 887 | { |
| 888 | rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] = 0; |
| 889 | } |
| 890 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 891 | static inline struct page *be_alloc_pages(u32 size) |
| 892 | { |
| 893 | gfp_t alloc_flags = GFP_ATOMIC; |
| 894 | u32 order = get_order(size); |
| 895 | if (order > 0) |
| 896 | alloc_flags |= __GFP_COMP; |
| 897 | return alloc_pages(alloc_flags, order); |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 902 | * receive buffers to BE |
| 903 | */ |
| 904 | static void be_post_rx_frags(struct be_adapter *adapter) |
| 905 | { |
| 906 | struct be_rx_page_info *page_info_tbl = adapter->rx_obj.page_info_tbl; |
| 907 | struct be_rx_page_info *page_info = NULL; |
| 908 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
| 909 | struct page *pagep = NULL; |
| 910 | struct be_eth_rx_d *rxd; |
| 911 | u64 page_dmaaddr = 0, frag_dmaaddr; |
| 912 | u32 posted, page_offset = 0; |
| 913 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 914 | page_info = &page_info_tbl[rxq->head]; |
| 915 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { |
| 916 | if (!pagep) { |
| 917 | pagep = be_alloc_pages(adapter->big_page_size); |
| 918 | if (unlikely(!pagep)) { |
| 919 | drvr_stats(adapter)->be_ethrx_post_fail++; |
| 920 | break; |
| 921 | } |
| 922 | page_dmaaddr = pci_map_page(adapter->pdev, pagep, 0, |
| 923 | adapter->big_page_size, |
| 924 | PCI_DMA_FROMDEVICE); |
| 925 | page_info->page_offset = 0; |
| 926 | } else { |
| 927 | get_page(pagep); |
| 928 | page_info->page_offset = page_offset + rx_frag_size; |
| 929 | } |
| 930 | page_offset = page_info->page_offset; |
| 931 | page_info->page = pagep; |
| 932 | pci_unmap_addr_set(page_info, bus, page_dmaaddr); |
| 933 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
| 934 | |
| 935 | rxd = queue_head_node(rxq); |
| 936 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 937 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
| 938 | queue_head_inc(rxq); |
| 939 | |
| 940 | /* Any space left in the current big page for another frag? */ |
| 941 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 942 | adapter->big_page_size) { |
| 943 | pagep = NULL; |
| 944 | page_info->last_page_user = true; |
| 945 | } |
| 946 | page_info = &page_info_tbl[rxq->head]; |
| 947 | } |
| 948 | if (pagep) |
| 949 | page_info->last_page_user = true; |
| 950 | |
| 951 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 952 | atomic_add(posted, &rxq->used); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 953 | be_rxq_notify(adapter, rxq->id, posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 954 | } else if (atomic_read(&rxq->used) == 0) { |
| 955 | /* Let be_worker replenish when memory is available */ |
| 956 | adapter->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | return; |
| 960 | } |
| 961 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 962 | static struct be_eth_tx_compl *be_tx_compl_get(struct be_queue_info *tx_cq) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 963 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 964 | struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq); |
| 965 | |
| 966 | if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
| 967 | return NULL; |
| 968 | |
| 969 | be_dws_le_to_cpu(txcp, sizeof(*txcp)); |
| 970 | |
| 971 | txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
| 972 | |
| 973 | queue_tail_inc(tx_cq); |
| 974 | return txcp; |
| 975 | } |
| 976 | |
| 977 | static void be_tx_compl_process(struct be_adapter *adapter, u16 last_index) |
| 978 | { |
| 979 | struct be_queue_info *txq = &adapter->tx_obj.q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 980 | struct sk_buff **sent_skbs = adapter->tx_obj.sent_skb_list; |
| 981 | struct sk_buff *sent_skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 982 | u16 cur_index, num_wrbs = 0; |
| 983 | |
| 984 | cur_index = txq->tail; |
| 985 | sent_skb = sent_skbs[cur_index]; |
| 986 | BUG_ON(!sent_skb); |
| 987 | sent_skbs[cur_index] = NULL; |
| 988 | |
| 989 | do { |
| 990 | cur_index = txq->tail; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 991 | num_wrbs++; |
| 992 | queue_tail_inc(txq); |
| 993 | } while (cur_index != last_index); |
| 994 | |
| 995 | atomic_sub(num_wrbs, &txq->used); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 996 | skb_dma_unmap(&adapter->pdev->dev, sent_skb, DMA_TO_DEVICE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 997 | kfree_skb(sent_skb); |
| 998 | } |
| 999 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1000 | static inline struct be_eq_entry *event_get(struct be_eq_obj *eq_obj) |
| 1001 | { |
| 1002 | struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q); |
| 1003 | |
| 1004 | if (!eqe->evt) |
| 1005 | return NULL; |
| 1006 | |
| 1007 | eqe->evt = le32_to_cpu(eqe->evt); |
| 1008 | queue_tail_inc(&eq_obj->q); |
| 1009 | return eqe; |
| 1010 | } |
| 1011 | |
| 1012 | static int event_handle(struct be_adapter *adapter, |
| 1013 | struct be_eq_obj *eq_obj) |
| 1014 | { |
| 1015 | struct be_eq_entry *eqe; |
| 1016 | u16 num = 0; |
| 1017 | |
| 1018 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1019 | eqe->evt = 0; |
| 1020 | num++; |
| 1021 | } |
| 1022 | |
| 1023 | /* Deal with any spurious interrupts that come |
| 1024 | * without events |
| 1025 | */ |
| 1026 | be_eq_notify(adapter, eq_obj->q.id, true, true, num); |
| 1027 | if (num) |
| 1028 | napi_schedule(&eq_obj->napi); |
| 1029 | |
| 1030 | return num; |
| 1031 | } |
| 1032 | |
| 1033 | /* Just read and notify events without processing them. |
| 1034 | * Used at the time of destroying event queues */ |
| 1035 | static void be_eq_clean(struct be_adapter *adapter, |
| 1036 | struct be_eq_obj *eq_obj) |
| 1037 | { |
| 1038 | struct be_eq_entry *eqe; |
| 1039 | u16 num = 0; |
| 1040 | |
| 1041 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1042 | eqe->evt = 0; |
| 1043 | num++; |
| 1044 | } |
| 1045 | |
| 1046 | if (num) |
| 1047 | be_eq_notify(adapter, eq_obj->q.id, false, true, num); |
| 1048 | } |
| 1049 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1050 | static void be_rx_q_clean(struct be_adapter *adapter) |
| 1051 | { |
| 1052 | struct be_rx_page_info *page_info; |
| 1053 | struct be_queue_info *rxq = &adapter->rx_obj.q; |
| 1054 | struct be_queue_info *rx_cq = &adapter->rx_obj.cq; |
| 1055 | struct be_eth_rx_compl *rxcp; |
| 1056 | u16 tail; |
| 1057 | |
| 1058 | /* First cleanup pending rx completions */ |
| 1059 | while ((rxcp = be_rx_compl_get(adapter)) != NULL) { |
| 1060 | be_rx_compl_discard(adapter, rxcp); |
Sathya Perla | a7a0ef3 | 2009-06-10 02:23:28 +0000 | [diff] [blame] | 1061 | be_rx_compl_reset(rxcp); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1062 | be_cq_notify(adapter, rx_cq->id, true, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /* Then free posted rx buffer that were not used */ |
| 1066 | tail = (rxq->head + rxq->len - atomic_read(&rxq->used)) % rxq->len; |
Sathya Perla | cdab23b | 2009-08-10 03:43:23 +0000 | [diff] [blame] | 1067 | for (; atomic_read(&rxq->used) > 0; index_inc(&tail, rxq->len)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1068 | page_info = get_rx_page_info(adapter, tail); |
| 1069 | put_page(page_info->page); |
| 1070 | memset(page_info, 0, sizeof(*page_info)); |
| 1071 | } |
| 1072 | BUG_ON(atomic_read(&rxq->used)); |
| 1073 | } |
| 1074 | |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1075 | static void be_tx_compl_clean(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1076 | { |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1077 | struct be_queue_info *tx_cq = &adapter->tx_obj.cq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1078 | struct be_queue_info *txq = &adapter->tx_obj.q; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1079 | struct be_eth_tx_compl *txcp; |
| 1080 | u16 end_idx, cmpl = 0, timeo = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1081 | |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1082 | /* Wait for a max of 200ms for all the tx-completions to arrive. */ |
| 1083 | do { |
| 1084 | while ((txcp = be_tx_compl_get(tx_cq))) { |
| 1085 | end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1086 | wrb_index, txcp); |
| 1087 | be_tx_compl_process(adapter, end_idx); |
| 1088 | cmpl++; |
| 1089 | } |
| 1090 | if (cmpl) { |
| 1091 | be_cq_notify(adapter, tx_cq->id, false, cmpl); |
| 1092 | cmpl = 0; |
| 1093 | } |
| 1094 | |
| 1095 | if (atomic_read(&txq->used) == 0 || ++timeo > 200) |
| 1096 | break; |
| 1097 | |
| 1098 | mdelay(1); |
| 1099 | } while (true); |
| 1100 | |
| 1101 | if (atomic_read(&txq->used)) |
| 1102 | dev_err(&adapter->pdev->dev, "%d pending tx-completions\n", |
| 1103 | atomic_read(&txq->used)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1106 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 1107 | { |
| 1108 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1109 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1110 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1111 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1112 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1113 | be_queue_free(adapter, q); |
| 1114 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1115 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1116 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1117 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1118 | be_queue_free(adapter, q); |
| 1119 | } |
| 1120 | |
| 1121 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 1122 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 1123 | { |
| 1124 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1125 | |
| 1126 | /* Alloc MCC compl queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1127 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1128 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 1129 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1130 | goto err; |
| 1131 | |
| 1132 | /* Ask BE to create MCC compl queue; share TX's eq */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1133 | if (be_cmd_cq_create(adapter, cq, &adapter->tx_eq.q, false, true, 0)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1134 | goto mcc_cq_free; |
| 1135 | |
| 1136 | /* Alloc MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1137 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1138 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 1139 | goto mcc_cq_destroy; |
| 1140 | |
| 1141 | /* Ask BE to create MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1142 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1143 | goto mcc_q_free; |
| 1144 | |
| 1145 | return 0; |
| 1146 | |
| 1147 | mcc_q_free: |
| 1148 | be_queue_free(adapter, q); |
| 1149 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1150 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1151 | mcc_cq_free: |
| 1152 | be_queue_free(adapter, cq); |
| 1153 | err: |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1157 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 1158 | { |
| 1159 | struct be_queue_info *q; |
| 1160 | |
| 1161 | q = &adapter->tx_obj.q; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1162 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1163 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1164 | be_queue_free(adapter, q); |
| 1165 | |
| 1166 | q = &adapter->tx_obj.cq; |
| 1167 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1168 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1169 | be_queue_free(adapter, q); |
| 1170 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1171 | /* Clear any residual events */ |
| 1172 | be_eq_clean(adapter, &adapter->tx_eq); |
| 1173 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1174 | q = &adapter->tx_eq.q; |
| 1175 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1176 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1177 | be_queue_free(adapter, q); |
| 1178 | } |
| 1179 | |
| 1180 | static int be_tx_queues_create(struct be_adapter *adapter) |
| 1181 | { |
| 1182 | struct be_queue_info *eq, *q, *cq; |
| 1183 | |
| 1184 | adapter->tx_eq.max_eqd = 0; |
| 1185 | adapter->tx_eq.min_eqd = 0; |
| 1186 | adapter->tx_eq.cur_eqd = 96; |
| 1187 | adapter->tx_eq.enable_aic = false; |
| 1188 | /* Alloc Tx Event queue */ |
| 1189 | eq = &adapter->tx_eq.q; |
| 1190 | if (be_queue_alloc(adapter, eq, EVNT_Q_LEN, sizeof(struct be_eq_entry))) |
| 1191 | return -1; |
| 1192 | |
| 1193 | /* Ask BE to create Tx Event queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1194 | if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd)) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1195 | goto tx_eq_free; |
| 1196 | /* Alloc TX eth compl queue */ |
| 1197 | cq = &adapter->tx_obj.cq; |
| 1198 | if (be_queue_alloc(adapter, cq, TX_CQ_LEN, |
| 1199 | sizeof(struct be_eth_tx_compl))) |
| 1200 | goto tx_eq_destroy; |
| 1201 | |
| 1202 | /* Ask BE to create Tx eth compl queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1203 | if (be_cmd_cq_create(adapter, cq, eq, false, false, 3)) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1204 | goto tx_cq_free; |
| 1205 | |
| 1206 | /* Alloc TX eth queue */ |
| 1207 | q = &adapter->tx_obj.q; |
| 1208 | if (be_queue_alloc(adapter, q, TX_Q_LEN, sizeof(struct be_eth_wrb))) |
| 1209 | goto tx_cq_destroy; |
| 1210 | |
| 1211 | /* Ask BE to create Tx eth queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1212 | if (be_cmd_txq_create(adapter, q, cq)) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1213 | goto tx_q_free; |
| 1214 | return 0; |
| 1215 | |
| 1216 | tx_q_free: |
| 1217 | be_queue_free(adapter, q); |
| 1218 | tx_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1219 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1220 | tx_cq_free: |
| 1221 | be_queue_free(adapter, cq); |
| 1222 | tx_eq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1223 | be_cmd_q_destroy(adapter, eq, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1224 | tx_eq_free: |
| 1225 | be_queue_free(adapter, eq); |
| 1226 | return -1; |
| 1227 | } |
| 1228 | |
| 1229 | static void be_rx_queues_destroy(struct be_adapter *adapter) |
| 1230 | { |
| 1231 | struct be_queue_info *q; |
| 1232 | |
| 1233 | q = &adapter->rx_obj.q; |
| 1234 | if (q->created) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1235 | be_cmd_q_destroy(adapter, q, QTYPE_RXQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1236 | be_rx_q_clean(adapter); |
| 1237 | } |
| 1238 | be_queue_free(adapter, q); |
| 1239 | |
| 1240 | q = &adapter->rx_obj.cq; |
| 1241 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1242 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1243 | be_queue_free(adapter, q); |
| 1244 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1245 | /* Clear any residual events */ |
| 1246 | be_eq_clean(adapter, &adapter->rx_eq); |
| 1247 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1248 | q = &adapter->rx_eq.q; |
| 1249 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1250 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1251 | be_queue_free(adapter, q); |
| 1252 | } |
| 1253 | |
| 1254 | static int be_rx_queues_create(struct be_adapter *adapter) |
| 1255 | { |
| 1256 | struct be_queue_info *eq, *q, *cq; |
| 1257 | int rc; |
| 1258 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1259 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
| 1260 | adapter->rx_eq.max_eqd = BE_MAX_EQD; |
| 1261 | adapter->rx_eq.min_eqd = 0; |
| 1262 | adapter->rx_eq.cur_eqd = 0; |
| 1263 | adapter->rx_eq.enable_aic = true; |
| 1264 | |
| 1265 | /* Alloc Rx Event queue */ |
| 1266 | eq = &adapter->rx_eq.q; |
| 1267 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 1268 | sizeof(struct be_eq_entry)); |
| 1269 | if (rc) |
| 1270 | return rc; |
| 1271 | |
| 1272 | /* Ask BE to create Rx Event queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1273 | rc = be_cmd_eq_create(adapter, eq, adapter->rx_eq.cur_eqd); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1274 | if (rc) |
| 1275 | goto rx_eq_free; |
| 1276 | |
| 1277 | /* Alloc RX eth compl queue */ |
| 1278 | cq = &adapter->rx_obj.cq; |
| 1279 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
| 1280 | sizeof(struct be_eth_rx_compl)); |
| 1281 | if (rc) |
| 1282 | goto rx_eq_destroy; |
| 1283 | |
| 1284 | /* Ask BE to create Rx eth compl queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1285 | rc = be_cmd_cq_create(adapter, cq, eq, false, false, 3); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1286 | if (rc) |
| 1287 | goto rx_cq_free; |
| 1288 | |
| 1289 | /* Alloc RX eth queue */ |
| 1290 | q = &adapter->rx_obj.q; |
| 1291 | rc = be_queue_alloc(adapter, q, RX_Q_LEN, sizeof(struct be_eth_rx_d)); |
| 1292 | if (rc) |
| 1293 | goto rx_cq_destroy; |
| 1294 | |
| 1295 | /* Ask BE to create Rx eth queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1296 | rc = be_cmd_rxq_create(adapter, q, cq->id, rx_frag_size, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1297 | BE_MAX_JUMBO_FRAME_SIZE, adapter->if_handle, false); |
| 1298 | if (rc) |
| 1299 | goto rx_q_free; |
| 1300 | |
| 1301 | return 0; |
| 1302 | rx_q_free: |
| 1303 | be_queue_free(adapter, q); |
| 1304 | rx_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1305 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1306 | rx_cq_free: |
| 1307 | be_queue_free(adapter, cq); |
| 1308 | rx_eq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1309 | be_cmd_q_destroy(adapter, eq, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1310 | rx_eq_free: |
| 1311 | be_queue_free(adapter, eq); |
| 1312 | return rc; |
| 1313 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1314 | |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1315 | /* There are 8 evt ids per func. Retruns the evt id's bit number */ |
| 1316 | static inline int be_evt_bit_get(struct be_adapter *adapter, u32 eq_id) |
| 1317 | { |
| 1318 | return eq_id - 8 * be_pci_func(adapter); |
| 1319 | } |
| 1320 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1321 | static irqreturn_t be_intx(int irq, void *dev) |
| 1322 | { |
| 1323 | struct be_adapter *adapter = dev; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1324 | int isr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1325 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1326 | isr = ioread32(adapter->csr + CEV_ISR0_OFFSET + |
Sathya Perla | eec368f | 2009-07-27 22:52:23 +0000 | [diff] [blame] | 1327 | be_pci_func(adapter) * CEV_ISR_SIZE); |
Sathya Perla | c001c21 | 2009-07-01 01:06:07 +0000 | [diff] [blame] | 1328 | if (!isr) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1329 | return IRQ_NONE; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1330 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1331 | event_handle(adapter, &adapter->tx_eq); |
| 1332 | event_handle(adapter, &adapter->rx_eq); |
Sathya Perla | c001c21 | 2009-07-01 01:06:07 +0000 | [diff] [blame] | 1333 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1334 | return IRQ_HANDLED; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static irqreturn_t be_msix_rx(int irq, void *dev) |
| 1338 | { |
| 1339 | struct be_adapter *adapter = dev; |
| 1340 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1341 | event_handle(adapter, &adapter->rx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1342 | |
| 1343 | return IRQ_HANDLED; |
| 1344 | } |
| 1345 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1346 | static irqreturn_t be_msix_tx_mcc(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1347 | { |
| 1348 | struct be_adapter *adapter = dev; |
| 1349 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1350 | event_handle(adapter, &adapter->tx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1351 | |
| 1352 | return IRQ_HANDLED; |
| 1353 | } |
| 1354 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1355 | static inline bool do_gro(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1356 | struct be_eth_rx_compl *rxcp) |
| 1357 | { |
| 1358 | int err = AMAP_GET_BITS(struct amap_eth_rx_compl, err, rxcp); |
| 1359 | int tcp_frame = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp); |
| 1360 | |
| 1361 | if (err) |
| 1362 | drvr_stats(adapter)->be_rxcp_err++; |
| 1363 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1364 | return (tcp_frame && !err) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | int be_poll_rx(struct napi_struct *napi, int budget) |
| 1368 | { |
| 1369 | struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi); |
| 1370 | struct be_adapter *adapter = |
| 1371 | container_of(rx_eq, struct be_adapter, rx_eq); |
| 1372 | struct be_queue_info *rx_cq = &adapter->rx_obj.cq; |
| 1373 | struct be_eth_rx_compl *rxcp; |
| 1374 | u32 work_done; |
| 1375 | |
| 1376 | for (work_done = 0; work_done < budget; work_done++) { |
| 1377 | rxcp = be_rx_compl_get(adapter); |
| 1378 | if (!rxcp) |
| 1379 | break; |
| 1380 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1381 | if (do_gro(adapter, rxcp)) |
| 1382 | be_rx_compl_process_gro(adapter, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1383 | else |
| 1384 | be_rx_compl_process(adapter, rxcp); |
Sathya Perla | a7a0ef3 | 2009-06-10 02:23:28 +0000 | [diff] [blame] | 1385 | |
| 1386 | be_rx_compl_reset(rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1389 | /* Refill the queue */ |
| 1390 | if (atomic_read(&adapter->rx_obj.q.used) < RX_FRAGS_REFILL_WM) |
| 1391 | be_post_rx_frags(adapter); |
| 1392 | |
| 1393 | /* All consumed */ |
| 1394 | if (work_done < budget) { |
| 1395 | napi_complete(napi); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1396 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1397 | } else { |
| 1398 | /* More to be consumed; continue with interrupts disabled */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1399 | be_cq_notify(adapter, rx_cq->id, false, work_done); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1400 | } |
| 1401 | return work_done; |
| 1402 | } |
| 1403 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1404 | void be_process_tx(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1405 | { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1406 | struct be_queue_info *txq = &adapter->tx_obj.q; |
| 1407 | struct be_queue_info *tx_cq = &adapter->tx_obj.cq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1408 | struct be_eth_tx_compl *txcp; |
| 1409 | u32 num_cmpl = 0; |
| 1410 | u16 end_idx; |
| 1411 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1412 | while ((txcp = be_tx_compl_get(tx_cq))) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1413 | end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1414 | wrb_index, txcp); |
| 1415 | be_tx_compl_process(adapter, end_idx); |
| 1416 | num_cmpl++; |
| 1417 | } |
| 1418 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1419 | if (num_cmpl) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1420 | be_cq_notify(adapter, tx_cq->id, true, num_cmpl); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1421 | |
| 1422 | /* As Tx wrbs have been freed up, wake up netdev queue if |
| 1423 | * it was stopped due to lack of tx wrbs. |
| 1424 | */ |
| 1425 | if (netif_queue_stopped(adapter->netdev) && |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1426 | atomic_read(&txq->used) < txq->len / 2) { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1427 | netif_wake_queue(adapter->netdev); |
| 1428 | } |
| 1429 | |
| 1430 | drvr_stats(adapter)->be_tx_events++; |
| 1431 | drvr_stats(adapter)->be_tx_compl += num_cmpl; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1432 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | /* As TX and MCC share the same EQ check for both TX and MCC completions. |
| 1436 | * For TX/MCC we don't honour budget; consume everything |
| 1437 | */ |
| 1438 | static int be_poll_tx_mcc(struct napi_struct *napi, int budget) |
| 1439 | { |
| 1440 | struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi); |
| 1441 | struct be_adapter *adapter = |
| 1442 | container_of(tx_eq, struct be_adapter, tx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1443 | |
| 1444 | napi_complete(napi); |
| 1445 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1446 | be_process_tx(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1447 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1448 | be_process_mcc(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1449 | |
| 1450 | return 1; |
| 1451 | } |
| 1452 | |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1453 | static void be_worker(struct work_struct *work) |
| 1454 | { |
| 1455 | struct be_adapter *adapter = |
| 1456 | container_of(work, struct be_adapter, work.work); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1457 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1458 | be_cmd_get_stats(adapter, &adapter->stats.cmd); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1459 | |
| 1460 | /* Set EQ delay */ |
| 1461 | be_rx_eqd_update(adapter); |
| 1462 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 1463 | be_tx_rate_update(adapter); |
| 1464 | be_rx_rate_update(adapter); |
| 1465 | |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1466 | if (adapter->rx_post_starved) { |
| 1467 | adapter->rx_post_starved = false; |
| 1468 | be_post_rx_frags(adapter); |
| 1469 | } |
| 1470 | |
| 1471 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 1472 | } |
| 1473 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1474 | static void be_msix_enable(struct be_adapter *adapter) |
| 1475 | { |
| 1476 | int i, status; |
| 1477 | |
| 1478 | for (i = 0; i < BE_NUM_MSIX_VECTORS; i++) |
| 1479 | adapter->msix_entries[i].entry = i; |
| 1480 | |
| 1481 | status = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
| 1482 | BE_NUM_MSIX_VECTORS); |
| 1483 | if (status == 0) |
| 1484 | adapter->msix_enabled = true; |
| 1485 | return; |
| 1486 | } |
| 1487 | |
| 1488 | static inline int be_msix_vec_get(struct be_adapter *adapter, u32 eq_id) |
| 1489 | { |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1490 | return adapter->msix_entries[ |
| 1491 | be_evt_bit_get(adapter, eq_id)].vector; |
| 1492 | } |
| 1493 | |
| 1494 | static int be_request_irq(struct be_adapter *adapter, |
| 1495 | struct be_eq_obj *eq_obj, |
| 1496 | void *handler, char *desc) |
| 1497 | { |
| 1498 | struct net_device *netdev = adapter->netdev; |
| 1499 | int vec; |
| 1500 | |
| 1501 | sprintf(eq_obj->desc, "%s-%s", netdev->name, desc); |
| 1502 | vec = be_msix_vec_get(adapter, eq_obj->q.id); |
| 1503 | return request_irq(vec, handler, 0, eq_obj->desc, adapter); |
| 1504 | } |
| 1505 | |
| 1506 | static void be_free_irq(struct be_adapter *adapter, struct be_eq_obj *eq_obj) |
| 1507 | { |
| 1508 | int vec = be_msix_vec_get(adapter, eq_obj->q.id); |
| 1509 | free_irq(vec, adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | static int be_msix_register(struct be_adapter *adapter) |
| 1513 | { |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1514 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1515 | |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1516 | status = be_request_irq(adapter, &adapter->tx_eq, be_msix_tx_mcc, "tx"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1517 | if (status) |
| 1518 | goto err; |
| 1519 | |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1520 | status = be_request_irq(adapter, &adapter->rx_eq, be_msix_rx, "rx"); |
| 1521 | if (status) |
| 1522 | goto free_tx_irq; |
| 1523 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1524 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1525 | |
| 1526 | free_tx_irq: |
| 1527 | be_free_irq(adapter, &adapter->tx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1528 | err: |
| 1529 | dev_warn(&adapter->pdev->dev, |
| 1530 | "MSIX Request IRQ failed - err %d\n", status); |
| 1531 | pci_disable_msix(adapter->pdev); |
| 1532 | adapter->msix_enabled = false; |
| 1533 | return status; |
| 1534 | } |
| 1535 | |
| 1536 | static int be_irq_register(struct be_adapter *adapter) |
| 1537 | { |
| 1538 | struct net_device *netdev = adapter->netdev; |
| 1539 | int status; |
| 1540 | |
| 1541 | if (adapter->msix_enabled) { |
| 1542 | status = be_msix_register(adapter); |
| 1543 | if (status == 0) |
| 1544 | goto done; |
| 1545 | } |
| 1546 | |
| 1547 | /* INTx */ |
| 1548 | netdev->irq = adapter->pdev->irq; |
| 1549 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
| 1550 | adapter); |
| 1551 | if (status) { |
| 1552 | dev_err(&adapter->pdev->dev, |
| 1553 | "INTx request IRQ failed - err %d\n", status); |
| 1554 | return status; |
| 1555 | } |
| 1556 | done: |
| 1557 | adapter->isr_registered = true; |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static void be_irq_unregister(struct be_adapter *adapter) |
| 1562 | { |
| 1563 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1564 | |
| 1565 | if (!adapter->isr_registered) |
| 1566 | return; |
| 1567 | |
| 1568 | /* INTx */ |
| 1569 | if (!adapter->msix_enabled) { |
| 1570 | free_irq(netdev->irq, adapter); |
| 1571 | goto done; |
| 1572 | } |
| 1573 | |
| 1574 | /* MSIx */ |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1575 | be_free_irq(adapter, &adapter->tx_eq); |
| 1576 | be_free_irq(adapter, &adapter->rx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1577 | done: |
| 1578 | adapter->isr_registered = false; |
| 1579 | return; |
| 1580 | } |
| 1581 | |
| 1582 | static int be_open(struct net_device *netdev) |
| 1583 | { |
| 1584 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1585 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 1586 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1587 | bool link_up; |
| 1588 | int status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1589 | |
| 1590 | /* First time posting */ |
| 1591 | be_post_rx_frags(adapter); |
| 1592 | |
| 1593 | napi_enable(&rx_eq->napi); |
| 1594 | napi_enable(&tx_eq->napi); |
| 1595 | |
| 1596 | be_irq_register(adapter); |
| 1597 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1598 | be_intr_set(adapter, true); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1599 | |
| 1600 | /* The evt queues are created in unarmed state; arm them */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1601 | be_eq_notify(adapter, rx_eq->q.id, true, false, 0); |
| 1602 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1603 | |
| 1604 | /* Rx compl queue may be in unarmed state; rearm it */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1605 | be_cq_notify(adapter, adapter->rx_obj.cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1606 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1607 | status = be_cmd_link_status_query(adapter, &link_up); |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1608 | if (status) |
| 1609 | return status; |
| 1610 | be_link_status_update(adapter, link_up); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1611 | |
| 1612 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | static int be_setup(struct be_adapter *adapter) |
| 1617 | { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1618 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1619 | u32 if_flags; |
| 1620 | int status; |
| 1621 | |
| 1622 | if_flags = BE_IF_FLAGS_BROADCAST | BE_IF_FLAGS_PROMISCUOUS | |
| 1623 | BE_IF_FLAGS_MCAST_PROMISCUOUS | BE_IF_FLAGS_UNTAGGED | |
| 1624 | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1625 | status = be_cmd_if_create(adapter, if_flags, netdev->dev_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1626 | false/* pmac_invalid */, &adapter->if_handle, |
| 1627 | &adapter->pmac_id); |
| 1628 | if (status != 0) |
| 1629 | goto do_none; |
| 1630 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1631 | |
| 1632 | status = be_tx_queues_create(adapter); |
| 1633 | if (status != 0) |
| 1634 | goto if_destroy; |
| 1635 | |
| 1636 | status = be_rx_queues_create(adapter); |
| 1637 | if (status != 0) |
| 1638 | goto tx_qs_destroy; |
| 1639 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1640 | status = be_mcc_queues_create(adapter); |
| 1641 | if (status != 0) |
| 1642 | goto rx_qs_destroy; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1643 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1644 | status = be_vid_config(adapter); |
| 1645 | if (status != 0) |
| 1646 | goto mccqs_destroy; |
| 1647 | |
| 1648 | status = be_cmd_set_flow_control(adapter, true, true); |
| 1649 | if (status != 0) |
| 1650 | goto mccqs_destroy; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1651 | return 0; |
| 1652 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1653 | mccqs_destroy: |
| 1654 | be_mcc_queues_destroy(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1655 | rx_qs_destroy: |
| 1656 | be_rx_queues_destroy(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1657 | tx_qs_destroy: |
| 1658 | be_tx_queues_destroy(adapter); |
| 1659 | if_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1660 | be_cmd_if_destroy(adapter, adapter->if_handle); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1661 | do_none: |
| 1662 | return status; |
| 1663 | } |
| 1664 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1665 | static int be_clear(struct be_adapter *adapter) |
| 1666 | { |
Sathya Perla | 1a8887d | 2009-08-17 00:58:41 +0000 | [diff] [blame] | 1667 | be_mcc_queues_destroy(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1668 | be_rx_queues_destroy(adapter); |
| 1669 | be_tx_queues_destroy(adapter); |
| 1670 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1671 | be_cmd_if_destroy(adapter, adapter->if_handle); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1672 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1673 | return 0; |
| 1674 | } |
| 1675 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1676 | static int be_close(struct net_device *netdev) |
| 1677 | { |
| 1678 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1679 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 1680 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 1681 | int vec; |
| 1682 | |
Sathya Perla | b305be7 | 2009-06-10 02:18:35 +0000 | [diff] [blame] | 1683 | cancel_delayed_work_sync(&adapter->work); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1684 | |
| 1685 | netif_stop_queue(netdev); |
| 1686 | netif_carrier_off(netdev); |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1687 | adapter->link_up = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1688 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1689 | be_intr_set(adapter, false); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (adapter->msix_enabled) { |
| 1692 | vec = be_msix_vec_get(adapter, tx_eq->q.id); |
| 1693 | synchronize_irq(vec); |
| 1694 | vec = be_msix_vec_get(adapter, rx_eq->q.id); |
| 1695 | synchronize_irq(vec); |
| 1696 | } else { |
| 1697 | synchronize_irq(netdev->irq); |
| 1698 | } |
| 1699 | be_irq_unregister(adapter); |
| 1700 | |
| 1701 | napi_disable(&rx_eq->napi); |
| 1702 | napi_disable(&tx_eq->napi); |
| 1703 | |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1704 | /* Wait for all pending tx completions to arrive so that |
| 1705 | * all tx skbs are freed. |
| 1706 | */ |
| 1707 | be_tx_compl_clean(adapter); |
| 1708 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1709 | return 0; |
| 1710 | } |
| 1711 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1712 | #define FW_FILE_HDR_SIGN "ServerEngines Corp. " |
| 1713 | char flash_cookie[2][16] = {"*** SE FLAS", |
| 1714 | "H DIRECTORY *** "}; |
| 1715 | static int be_flash_image(struct be_adapter *adapter, |
| 1716 | const struct firmware *fw, |
| 1717 | struct be_dma_mem *flash_cmd, u32 flash_type) |
| 1718 | { |
| 1719 | int status; |
| 1720 | u32 flash_op, image_offset = 0, total_bytes, image_size = 0; |
| 1721 | int num_bytes; |
| 1722 | const u8 *p = fw->data; |
| 1723 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
| 1724 | |
| 1725 | switch (flash_type) { |
| 1726 | case FLASHROM_TYPE_ISCSI_ACTIVE: |
| 1727 | image_offset = FLASH_iSCSI_PRIMARY_IMAGE_START; |
| 1728 | image_size = FLASH_IMAGE_MAX_SIZE; |
| 1729 | break; |
| 1730 | case FLASHROM_TYPE_ISCSI_BACKUP: |
| 1731 | image_offset = FLASH_iSCSI_BACKUP_IMAGE_START; |
| 1732 | image_size = FLASH_IMAGE_MAX_SIZE; |
| 1733 | break; |
| 1734 | case FLASHROM_TYPE_FCOE_FW_ACTIVE: |
| 1735 | image_offset = FLASH_FCoE_PRIMARY_IMAGE_START; |
| 1736 | image_size = FLASH_IMAGE_MAX_SIZE; |
| 1737 | break; |
| 1738 | case FLASHROM_TYPE_FCOE_FW_BACKUP: |
| 1739 | image_offset = FLASH_FCoE_BACKUP_IMAGE_START; |
| 1740 | image_size = FLASH_IMAGE_MAX_SIZE; |
| 1741 | break; |
| 1742 | case FLASHROM_TYPE_BIOS: |
| 1743 | image_offset = FLASH_iSCSI_BIOS_START; |
| 1744 | image_size = FLASH_BIOS_IMAGE_MAX_SIZE; |
| 1745 | break; |
| 1746 | case FLASHROM_TYPE_FCOE_BIOS: |
| 1747 | image_offset = FLASH_FCoE_BIOS_START; |
| 1748 | image_size = FLASH_BIOS_IMAGE_MAX_SIZE; |
| 1749 | break; |
| 1750 | case FLASHROM_TYPE_PXE_BIOS: |
| 1751 | image_offset = FLASH_PXE_BIOS_START; |
| 1752 | image_size = FLASH_BIOS_IMAGE_MAX_SIZE; |
| 1753 | break; |
| 1754 | default: |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | p += sizeof(struct flash_file_hdr) + image_offset; |
| 1759 | if (p + image_size > fw->data + fw->size) |
| 1760 | return -1; |
| 1761 | |
| 1762 | total_bytes = image_size; |
| 1763 | |
| 1764 | while (total_bytes) { |
| 1765 | if (total_bytes > 32*1024) |
| 1766 | num_bytes = 32*1024; |
| 1767 | else |
| 1768 | num_bytes = total_bytes; |
| 1769 | total_bytes -= num_bytes; |
| 1770 | |
| 1771 | if (!total_bytes) |
| 1772 | flash_op = FLASHROM_OPER_FLASH; |
| 1773 | else |
| 1774 | flash_op = FLASHROM_OPER_SAVE; |
| 1775 | memcpy(req->params.data_buf, p, num_bytes); |
| 1776 | p += num_bytes; |
| 1777 | status = be_cmd_write_flashrom(adapter, flash_cmd, |
| 1778 | flash_type, flash_op, num_bytes); |
| 1779 | if (status) { |
| 1780 | dev_err(&adapter->pdev->dev, |
| 1781 | "cmd to write to flash rom failed. type/op %d/%d\n", |
| 1782 | flash_type, flash_op); |
| 1783 | return -1; |
| 1784 | } |
| 1785 | yield(); |
| 1786 | } |
| 1787 | |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | int be_load_fw(struct be_adapter *adapter, u8 *func) |
| 1792 | { |
| 1793 | char fw_file[ETHTOOL_FLASH_MAX_FILENAME]; |
| 1794 | const struct firmware *fw; |
| 1795 | struct flash_file_hdr *fhdr; |
| 1796 | struct flash_section_info *fsec = NULL; |
| 1797 | struct be_dma_mem flash_cmd; |
| 1798 | int status; |
| 1799 | const u8 *p; |
| 1800 | bool entry_found = false; |
| 1801 | int flash_type; |
| 1802 | char fw_ver[FW_VER_LEN]; |
| 1803 | char fw_cfg; |
| 1804 | |
| 1805 | status = be_cmd_get_fw_ver(adapter, fw_ver); |
| 1806 | if (status) |
| 1807 | return status; |
| 1808 | |
| 1809 | fw_cfg = *(fw_ver + 2); |
| 1810 | if (fw_cfg == '0') |
| 1811 | fw_cfg = '1'; |
| 1812 | strcpy(fw_file, func); |
| 1813 | |
| 1814 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 1815 | if (status) |
| 1816 | goto fw_exit; |
| 1817 | |
| 1818 | p = fw->data; |
| 1819 | fhdr = (struct flash_file_hdr *) p; |
| 1820 | if (memcmp(fhdr->sign, FW_FILE_HDR_SIGN, strlen(FW_FILE_HDR_SIGN))) { |
| 1821 | dev_err(&adapter->pdev->dev, |
| 1822 | "Firmware(%s) load error (signature did not match)\n", |
| 1823 | fw_file); |
| 1824 | status = -1; |
| 1825 | goto fw_exit; |
| 1826 | } |
| 1827 | |
| 1828 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 1829 | |
| 1830 | p += sizeof(struct flash_file_hdr); |
| 1831 | while (p < (fw->data + fw->size)) { |
| 1832 | fsec = (struct flash_section_info *)p; |
| 1833 | if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie))) { |
| 1834 | entry_found = true; |
| 1835 | break; |
| 1836 | } |
| 1837 | p += 32; |
| 1838 | } |
| 1839 | |
| 1840 | if (!entry_found) { |
| 1841 | status = -1; |
| 1842 | dev_err(&adapter->pdev->dev, |
| 1843 | "Flash cookie not found in firmware image\n"); |
| 1844 | goto fw_exit; |
| 1845 | } |
| 1846 | |
| 1847 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024; |
| 1848 | flash_cmd.va = pci_alloc_consistent(adapter->pdev, flash_cmd.size, |
| 1849 | &flash_cmd.dma); |
| 1850 | if (!flash_cmd.va) { |
| 1851 | status = -ENOMEM; |
| 1852 | dev_err(&adapter->pdev->dev, |
| 1853 | "Memory allocation failure while flashing\n"); |
| 1854 | goto fw_exit; |
| 1855 | } |
| 1856 | |
| 1857 | for (flash_type = FLASHROM_TYPE_ISCSI_ACTIVE; |
| 1858 | flash_type <= FLASHROM_TYPE_FCOE_FW_BACKUP; flash_type++) { |
| 1859 | status = be_flash_image(adapter, fw, &flash_cmd, |
| 1860 | flash_type); |
| 1861 | if (status) |
| 1862 | break; |
| 1863 | } |
| 1864 | |
| 1865 | pci_free_consistent(adapter->pdev, flash_cmd.size, flash_cmd.va, |
| 1866 | flash_cmd.dma); |
| 1867 | if (status) { |
| 1868 | dev_err(&adapter->pdev->dev, "Firmware load error\n"); |
| 1869 | goto fw_exit; |
| 1870 | } |
| 1871 | |
| 1872 | dev_info(&adapter->pdev->dev, "Firmware flashed succesfully\n"); |
| 1873 | |
| 1874 | fw_exit: |
| 1875 | release_firmware(fw); |
| 1876 | return status; |
| 1877 | } |
| 1878 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1879 | static struct net_device_ops be_netdev_ops = { |
| 1880 | .ndo_open = be_open, |
| 1881 | .ndo_stop = be_close, |
| 1882 | .ndo_start_xmit = be_xmit, |
| 1883 | .ndo_get_stats = be_get_stats, |
| 1884 | .ndo_set_rx_mode = be_set_multicast_list, |
| 1885 | .ndo_set_mac_address = be_mac_addr_set, |
| 1886 | .ndo_change_mtu = be_change_mtu, |
| 1887 | .ndo_validate_addr = eth_validate_addr, |
| 1888 | .ndo_vlan_rx_register = be_vlan_register, |
| 1889 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 1890 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
| 1891 | }; |
| 1892 | |
| 1893 | static void be_netdev_init(struct net_device *netdev) |
| 1894 | { |
| 1895 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1896 | |
| 1897 | netdev->features |= NETIF_F_SG | NETIF_F_HW_VLAN_RX | NETIF_F_TSO | |
Ajit Khaparde | 583e3f3 | 2009-10-05 02:22:19 +0000 | [diff] [blame] | 1898 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_FILTER | NETIF_F_HW_CSUM | |
| 1899 | NETIF_F_GRO; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1900 | |
| 1901 | netdev->flags |= IFF_MULTICAST; |
| 1902 | |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1903 | adapter->rx_csum = true; |
| 1904 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 1905 | netif_set_gso_max_size(netdev, 65535); |
| 1906 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1907 | BE_SET_NETDEV_OPS(netdev, &be_netdev_ops); |
| 1908 | |
| 1909 | SET_ETHTOOL_OPS(netdev, &be_ethtool_ops); |
| 1910 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1911 | netif_napi_add(netdev, &adapter->rx_eq.napi, be_poll_rx, |
| 1912 | BE_NAPI_WEIGHT); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1913 | netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1914 | BE_NAPI_WEIGHT); |
| 1915 | |
| 1916 | netif_carrier_off(netdev); |
| 1917 | netif_stop_queue(netdev); |
| 1918 | } |
| 1919 | |
| 1920 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 1921 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1922 | if (adapter->csr) |
| 1923 | iounmap(adapter->csr); |
| 1924 | if (adapter->db) |
| 1925 | iounmap(adapter->db); |
| 1926 | if (adapter->pcicfg) |
| 1927 | iounmap(adapter->pcicfg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 1931 | { |
| 1932 | u8 __iomem *addr; |
| 1933 | |
| 1934 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2), |
| 1935 | pci_resource_len(adapter->pdev, 2)); |
| 1936 | if (addr == NULL) |
| 1937 | return -ENOMEM; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1938 | adapter->csr = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1939 | |
| 1940 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 4), |
| 1941 | 128 * 1024); |
| 1942 | if (addr == NULL) |
| 1943 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1944 | adapter->db = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1945 | |
| 1946 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 1), |
| 1947 | pci_resource_len(adapter->pdev, 1)); |
| 1948 | if (addr == NULL) |
| 1949 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1950 | adapter->pcicfg = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1951 | |
| 1952 | return 0; |
| 1953 | pci_map_err: |
| 1954 | be_unmap_pci_bars(adapter); |
| 1955 | return -ENOMEM; |
| 1956 | } |
| 1957 | |
| 1958 | |
| 1959 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 1960 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1961 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1962 | |
| 1963 | be_unmap_pci_bars(adapter); |
| 1964 | |
| 1965 | if (mem->va) |
| 1966 | pci_free_consistent(adapter->pdev, mem->size, |
| 1967 | mem->va, mem->dma); |
| 1968 | } |
| 1969 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1970 | static int be_ctrl_init(struct be_adapter *adapter) |
| 1971 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1972 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 1973 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1974 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1975 | |
| 1976 | status = be_map_pci_bars(adapter); |
| 1977 | if (status) |
| 1978 | return status; |
| 1979 | |
| 1980 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 1981 | mbox_mem_alloc->va = pci_alloc_consistent(adapter->pdev, |
| 1982 | mbox_mem_alloc->size, &mbox_mem_alloc->dma); |
| 1983 | if (!mbox_mem_alloc->va) { |
| 1984 | be_unmap_pci_bars(adapter); |
| 1985 | return -1; |
| 1986 | } |
| 1987 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 1988 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 1989 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 1990 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1991 | spin_lock_init(&adapter->mbox_lock); |
| 1992 | spin_lock_init(&adapter->mcc_lock); |
| 1993 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1994 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 1999 | { |
| 2000 | struct be_stats_obj *stats = &adapter->stats; |
| 2001 | struct be_dma_mem *cmd = &stats->cmd; |
| 2002 | |
| 2003 | if (cmd->va) |
| 2004 | pci_free_consistent(adapter->pdev, cmd->size, |
| 2005 | cmd->va, cmd->dma); |
| 2006 | } |
| 2007 | |
| 2008 | static int be_stats_init(struct be_adapter *adapter) |
| 2009 | { |
| 2010 | struct be_stats_obj *stats = &adapter->stats; |
| 2011 | struct be_dma_mem *cmd = &stats->cmd; |
| 2012 | |
| 2013 | cmd->size = sizeof(struct be_cmd_req_get_stats); |
| 2014 | cmd->va = pci_alloc_consistent(adapter->pdev, cmd->size, &cmd->dma); |
| 2015 | if (cmd->va == NULL) |
| 2016 | return -1; |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
| 2020 | static void __devexit be_remove(struct pci_dev *pdev) |
| 2021 | { |
| 2022 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2023 | if (!adapter) |
| 2024 | return; |
| 2025 | |
| 2026 | unregister_netdev(adapter->netdev); |
| 2027 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2028 | be_clear(adapter); |
| 2029 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2030 | be_stats_cleanup(adapter); |
| 2031 | |
| 2032 | be_ctrl_cleanup(adapter); |
| 2033 | |
| 2034 | if (adapter->msix_enabled) { |
| 2035 | pci_disable_msix(adapter->pdev); |
| 2036 | adapter->msix_enabled = false; |
| 2037 | } |
| 2038 | |
| 2039 | pci_set_drvdata(pdev, NULL); |
| 2040 | pci_release_regions(pdev); |
| 2041 | pci_disable_device(pdev); |
| 2042 | |
| 2043 | free_netdev(adapter->netdev); |
| 2044 | } |
| 2045 | |
| 2046 | static int be_hw_up(struct be_adapter *adapter) |
| 2047 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2048 | int status; |
| 2049 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2050 | status = be_cmd_POST(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2051 | if (status) |
| 2052 | return status; |
| 2053 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2054 | status = be_cmd_get_fw_ver(adapter, adapter->fw_ver); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2055 | if (status) |
| 2056 | return status; |
| 2057 | |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 2058 | status = be_cmd_query_fw_cfg(adapter, |
| 2059 | &adapter->port_num, &adapter->cap); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2060 | return status; |
| 2061 | } |
| 2062 | |
| 2063 | static int __devinit be_probe(struct pci_dev *pdev, |
| 2064 | const struct pci_device_id *pdev_id) |
| 2065 | { |
| 2066 | int status = 0; |
| 2067 | struct be_adapter *adapter; |
| 2068 | struct net_device *netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2069 | u8 mac[ETH_ALEN]; |
| 2070 | |
| 2071 | status = pci_enable_device(pdev); |
| 2072 | if (status) |
| 2073 | goto do_none; |
| 2074 | |
| 2075 | status = pci_request_regions(pdev, DRV_NAME); |
| 2076 | if (status) |
| 2077 | goto disable_dev; |
| 2078 | pci_set_master(pdev); |
| 2079 | |
| 2080 | netdev = alloc_etherdev(sizeof(struct be_adapter)); |
| 2081 | if (netdev == NULL) { |
| 2082 | status = -ENOMEM; |
| 2083 | goto rel_reg; |
| 2084 | } |
| 2085 | adapter = netdev_priv(netdev); |
| 2086 | adapter->pdev = pdev; |
| 2087 | pci_set_drvdata(pdev, adapter); |
| 2088 | adapter->netdev = netdev; |
| 2089 | |
| 2090 | be_msix_enable(adapter); |
| 2091 | |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2092 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2093 | if (!status) { |
| 2094 | netdev->features |= NETIF_F_HIGHDMA; |
| 2095 | } else { |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2096 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2097 | if (status) { |
| 2098 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 2099 | goto free_netdev; |
| 2100 | } |
| 2101 | } |
| 2102 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2103 | status = be_ctrl_init(adapter); |
| 2104 | if (status) |
| 2105 | goto free_netdev; |
| 2106 | |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2107 | status = be_cmd_reset_function(adapter); |
| 2108 | if (status) |
| 2109 | goto ctrl_clean; |
| 2110 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2111 | status = be_stats_init(adapter); |
| 2112 | if (status) |
| 2113 | goto ctrl_clean; |
| 2114 | |
| 2115 | status = be_hw_up(adapter); |
| 2116 | if (status) |
| 2117 | goto stats_clean; |
| 2118 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2119 | status = be_cmd_mac_addr_query(adapter, mac, MAC_ADDRESS_TYPE_NETWORK, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2120 | true /* permanent */, 0); |
| 2121 | if (status) |
| 2122 | goto stats_clean; |
| 2123 | memcpy(netdev->dev_addr, mac, ETH_ALEN); |
| 2124 | |
| 2125 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
| 2126 | be_netdev_init(netdev); |
| 2127 | SET_NETDEV_DEV(netdev, &adapter->pdev->dev); |
| 2128 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2129 | status = be_setup(adapter); |
| 2130 | if (status) |
| 2131 | goto stats_clean; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2132 | status = register_netdev(netdev); |
| 2133 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2134 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2135 | |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 2136 | dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2137 | return 0; |
| 2138 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2139 | unsetup: |
| 2140 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2141 | stats_clean: |
| 2142 | be_stats_cleanup(adapter); |
| 2143 | ctrl_clean: |
| 2144 | be_ctrl_cleanup(adapter); |
| 2145 | free_netdev: |
| 2146 | free_netdev(adapter->netdev); |
| 2147 | rel_reg: |
| 2148 | pci_release_regions(pdev); |
| 2149 | disable_dev: |
| 2150 | pci_disable_device(pdev); |
| 2151 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 2152 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2153 | return status; |
| 2154 | } |
| 2155 | |
| 2156 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2157 | { |
| 2158 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2159 | struct net_device *netdev = adapter->netdev; |
| 2160 | |
| 2161 | netif_device_detach(netdev); |
| 2162 | if (netif_running(netdev)) { |
| 2163 | rtnl_lock(); |
| 2164 | be_close(netdev); |
| 2165 | rtnl_unlock(); |
| 2166 | } |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 2167 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2168 | |
| 2169 | pci_save_state(pdev); |
| 2170 | pci_disable_device(pdev); |
| 2171 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 2172 | return 0; |
| 2173 | } |
| 2174 | |
| 2175 | static int be_resume(struct pci_dev *pdev) |
| 2176 | { |
| 2177 | int status = 0; |
| 2178 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2179 | struct net_device *netdev = adapter->netdev; |
| 2180 | |
| 2181 | netif_device_detach(netdev); |
| 2182 | |
| 2183 | status = pci_enable_device(pdev); |
| 2184 | if (status) |
| 2185 | return status; |
| 2186 | |
| 2187 | pci_set_power_state(pdev, 0); |
| 2188 | pci_restore_state(pdev); |
| 2189 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 2190 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2191 | if (netif_running(netdev)) { |
| 2192 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2193 | be_open(netdev); |
| 2194 | rtnl_unlock(); |
| 2195 | } |
| 2196 | netif_device_attach(netdev); |
| 2197 | return 0; |
| 2198 | } |
| 2199 | |
| 2200 | static struct pci_driver be_driver = { |
| 2201 | .name = DRV_NAME, |
| 2202 | .id_table = be_dev_ids, |
| 2203 | .probe = be_probe, |
| 2204 | .remove = be_remove, |
| 2205 | .suspend = be_suspend, |
| 2206 | .resume = be_resume |
| 2207 | }; |
| 2208 | |
| 2209 | static int __init be_init_module(void) |
| 2210 | { |
| 2211 | if (rx_frag_size != 8192 && rx_frag_size != 4096 |
| 2212 | && rx_frag_size != 2048) { |
| 2213 | printk(KERN_WARNING DRV_NAME |
| 2214 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 2215 | " Using 2048\n"); |
| 2216 | rx_frag_size = 2048; |
| 2217 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2218 | |
| 2219 | return pci_register_driver(&be_driver); |
| 2220 | } |
| 2221 | module_init(be_init_module); |
| 2222 | |
| 2223 | static void __exit be_exit_module(void) |
| 2224 | { |
| 2225 | pci_unregister_driver(&be_driver); |
| 2226 | } |
| 2227 | module_exit(be_exit_module); |