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