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