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