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; |
| 1634 | if (be_physfn(adapter) && num_vfs) { |
| 1635 | status = pci_enable_sriov(adapter->pdev, num_vfs); |
| 1636 | adapter->sriov_enabled = status ? false : true; |
| 1637 | } |
| 1638 | #endif |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | static void be_sriov_disable(struct be_adapter *adapter) |
| 1642 | { |
| 1643 | #ifdef CONFIG_PCI_IOV |
| 1644 | if (adapter->sriov_enabled) { |
| 1645 | pci_disable_sriov(adapter->pdev); |
| 1646 | adapter->sriov_enabled = false; |
| 1647 | } |
| 1648 | #endif |
| 1649 | } |
| 1650 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1651 | static inline int be_msix_vec_get(struct be_adapter *adapter, u32 eq_id) |
| 1652 | { |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1653 | return adapter->msix_entries[ |
| 1654 | be_evt_bit_get(adapter, eq_id)].vector; |
| 1655 | } |
| 1656 | |
| 1657 | static int be_request_irq(struct be_adapter *adapter, |
| 1658 | struct be_eq_obj *eq_obj, |
| 1659 | void *handler, char *desc) |
| 1660 | { |
| 1661 | struct net_device *netdev = adapter->netdev; |
| 1662 | int vec; |
| 1663 | |
| 1664 | sprintf(eq_obj->desc, "%s-%s", netdev->name, desc); |
| 1665 | vec = be_msix_vec_get(adapter, eq_obj->q.id); |
| 1666 | return request_irq(vec, handler, 0, eq_obj->desc, adapter); |
| 1667 | } |
| 1668 | |
| 1669 | static void be_free_irq(struct be_adapter *adapter, struct be_eq_obj *eq_obj) |
| 1670 | { |
| 1671 | int vec = be_msix_vec_get(adapter, eq_obj->q.id); |
| 1672 | free_irq(vec, adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | static int be_msix_register(struct be_adapter *adapter) |
| 1676 | { |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1677 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1678 | |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1679 | 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] | 1680 | if (status) |
| 1681 | goto err; |
| 1682 | |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1683 | status = be_request_irq(adapter, &adapter->rx_eq, be_msix_rx, "rx"); |
| 1684 | if (status) |
| 1685 | goto free_tx_irq; |
| 1686 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1687 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1688 | |
| 1689 | free_tx_irq: |
| 1690 | be_free_irq(adapter, &adapter->tx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1691 | err: |
| 1692 | dev_warn(&adapter->pdev->dev, |
| 1693 | "MSIX Request IRQ failed - err %d\n", status); |
| 1694 | pci_disable_msix(adapter->pdev); |
| 1695 | adapter->msix_enabled = false; |
| 1696 | return status; |
| 1697 | } |
| 1698 | |
| 1699 | static int be_irq_register(struct be_adapter *adapter) |
| 1700 | { |
| 1701 | struct net_device *netdev = adapter->netdev; |
| 1702 | int status; |
| 1703 | |
| 1704 | if (adapter->msix_enabled) { |
| 1705 | status = be_msix_register(adapter); |
| 1706 | if (status == 0) |
| 1707 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1708 | /* INTx is not supported for VF */ |
| 1709 | if (!be_physfn(adapter)) |
| 1710 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /* INTx */ |
| 1714 | netdev->irq = adapter->pdev->irq; |
| 1715 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
| 1716 | adapter); |
| 1717 | if (status) { |
| 1718 | dev_err(&adapter->pdev->dev, |
| 1719 | "INTx request IRQ failed - err %d\n", status); |
| 1720 | return status; |
| 1721 | } |
| 1722 | done: |
| 1723 | adapter->isr_registered = true; |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | static void be_irq_unregister(struct be_adapter *adapter) |
| 1728 | { |
| 1729 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1730 | |
| 1731 | if (!adapter->isr_registered) |
| 1732 | return; |
| 1733 | |
| 1734 | /* INTx */ |
| 1735 | if (!adapter->msix_enabled) { |
| 1736 | free_irq(netdev->irq, adapter); |
| 1737 | goto done; |
| 1738 | } |
| 1739 | |
| 1740 | /* MSIx */ |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1741 | be_free_irq(adapter, &adapter->tx_eq); |
| 1742 | be_free_irq(adapter, &adapter->rx_eq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1743 | done: |
| 1744 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1747 | static int be_close(struct net_device *netdev) |
| 1748 | { |
| 1749 | struct be_adapter *adapter = netdev_priv(netdev); |
| 1750 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 1751 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 1752 | int vec; |
| 1753 | |
| 1754 | cancel_delayed_work_sync(&adapter->work); |
| 1755 | |
| 1756 | be_async_mcc_disable(adapter); |
| 1757 | |
| 1758 | netif_stop_queue(netdev); |
| 1759 | netif_carrier_off(netdev); |
| 1760 | adapter->link_up = false; |
| 1761 | |
| 1762 | be_intr_set(adapter, false); |
| 1763 | |
| 1764 | if (adapter->msix_enabled) { |
| 1765 | vec = be_msix_vec_get(adapter, tx_eq->q.id); |
| 1766 | synchronize_irq(vec); |
| 1767 | vec = be_msix_vec_get(adapter, rx_eq->q.id); |
| 1768 | synchronize_irq(vec); |
| 1769 | } else { |
| 1770 | synchronize_irq(netdev->irq); |
| 1771 | } |
| 1772 | be_irq_unregister(adapter); |
| 1773 | |
| 1774 | napi_disable(&rx_eq->napi); |
| 1775 | napi_disable(&tx_eq->napi); |
| 1776 | |
| 1777 | /* Wait for all pending tx completions to arrive so that |
| 1778 | * all tx skbs are freed. |
| 1779 | */ |
| 1780 | be_tx_compl_clean(adapter); |
| 1781 | |
| 1782 | return 0; |
| 1783 | } |
| 1784 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1785 | static int be_open(struct net_device *netdev) |
| 1786 | { |
| 1787 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1788 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 1789 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1790 | bool link_up; |
| 1791 | int status; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1792 | u8 mac_speed; |
| 1793 | u16 link_speed; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1794 | |
| 1795 | /* First time posting */ |
| 1796 | be_post_rx_frags(adapter); |
| 1797 | |
| 1798 | napi_enable(&rx_eq->napi); |
| 1799 | napi_enable(&tx_eq->napi); |
| 1800 | |
| 1801 | be_irq_register(adapter); |
| 1802 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1803 | be_intr_set(adapter, true); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1804 | |
| 1805 | /* The evt queues are created in unarmed state; arm them */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1806 | be_eq_notify(adapter, rx_eq->q.id, true, false, 0); |
| 1807 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1808 | |
| 1809 | /* Rx compl queue may be in unarmed state; rearm it */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1810 | be_cq_notify(adapter, adapter->rx_obj.cq.id, true, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1811 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 1812 | /* Now that interrupts are on we can process async mcc */ |
| 1813 | be_async_mcc_enable(adapter); |
| 1814 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1815 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
| 1816 | |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1817 | status = be_cmd_link_status_query(adapter, &link_up, &mac_speed, |
| 1818 | &link_speed); |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1819 | if (status) |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1820 | goto err; |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1821 | be_link_status_update(adapter, link_up); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1822 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1823 | if (be_physfn(adapter)) { |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1824 | status = be_vid_config(adapter); |
| 1825 | if (status) |
| 1826 | goto err; |
| 1827 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1828 | status = be_cmd_set_flow_control(adapter, |
| 1829 | adapter->tx_fc, adapter->rx_fc); |
| 1830 | if (status) |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1831 | goto err; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1832 | } |
Ajit Khaparde | 4f2aa89 | 2009-11-06 02:07:32 +0000 | [diff] [blame] | 1833 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 1834 | return 0; |
| 1835 | err: |
| 1836 | be_close(adapter->netdev); |
| 1837 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 1840 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 1841 | { |
| 1842 | struct be_dma_mem cmd; |
| 1843 | int status = 0; |
| 1844 | u8 mac[ETH_ALEN]; |
| 1845 | |
| 1846 | memset(mac, 0, ETH_ALEN); |
| 1847 | |
| 1848 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
| 1849 | cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma); |
| 1850 | if (cmd.va == NULL) |
| 1851 | return -1; |
| 1852 | memset(cmd.va, 0, cmd.size); |
| 1853 | |
| 1854 | if (enable) { |
| 1855 | status = pci_write_config_dword(adapter->pdev, |
| 1856 | PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK); |
| 1857 | if (status) { |
| 1858 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 1859 | "Could not enable Wake-on-lan\n"); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 1860 | pci_free_consistent(adapter->pdev, cmd.size, cmd.va, |
| 1861 | cmd.dma); |
| 1862 | return status; |
| 1863 | } |
| 1864 | status = be_cmd_enable_magic_wol(adapter, |
| 1865 | adapter->netdev->dev_addr, &cmd); |
| 1866 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 1867 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 1868 | } else { |
| 1869 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 1870 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 1871 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 1872 | } |
| 1873 | |
| 1874 | pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma); |
| 1875 | return status; |
| 1876 | } |
| 1877 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1878 | static int be_setup(struct be_adapter *adapter) |
| 1879 | { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1880 | struct net_device *netdev = adapter->netdev; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1881 | u32 cap_flags, en_flags, vf = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1882 | int status; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1883 | u8 mac[ETH_ALEN]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1884 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1885 | cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST; |
| 1886 | |
| 1887 | if (be_physfn(adapter)) { |
| 1888 | cap_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS | |
| 1889 | BE_IF_FLAGS_PROMISCUOUS | |
| 1890 | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
| 1891 | en_flags |= BE_IF_FLAGS_PASS_L3L4_ERRORS; |
| 1892 | } |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1893 | |
| 1894 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 1895 | netdev->dev_addr, false/* pmac_invalid */, |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1896 | &adapter->if_handle, &adapter->pmac_id, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1897 | if (status != 0) |
| 1898 | goto do_none; |
| 1899 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1900 | if (be_physfn(adapter)) { |
| 1901 | while (vf < num_vfs) { |
| 1902 | cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED |
| 1903 | | BE_IF_FLAGS_BROADCAST; |
| 1904 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 1905 | mac, true, &adapter->vf_if_handle[vf], |
| 1906 | NULL, vf+1); |
| 1907 | if (status) { |
| 1908 | dev_err(&adapter->pdev->dev, |
| 1909 | "Interface Create failed for VF %d\n", vf); |
| 1910 | goto if_destroy; |
| 1911 | } |
| 1912 | vf++; |
Sarveshwar Bandi | 84e5b9f | 2010-05-27 16:28:15 -0700 | [diff] [blame] | 1913 | } |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1914 | } else if (!be_physfn(adapter)) { |
| 1915 | status = be_cmd_mac_addr_query(adapter, mac, |
| 1916 | MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle); |
| 1917 | if (!status) { |
| 1918 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 1919 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 1920 | } |
| 1921 | } |
| 1922 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1923 | status = be_tx_queues_create(adapter); |
| 1924 | if (status != 0) |
| 1925 | goto if_destroy; |
| 1926 | |
| 1927 | status = be_rx_queues_create(adapter); |
| 1928 | if (status != 0) |
| 1929 | goto tx_qs_destroy; |
| 1930 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1931 | status = be_mcc_queues_create(adapter); |
| 1932 | if (status != 0) |
| 1933 | goto rx_qs_destroy; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1934 | |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 1935 | adapter->link_speed = -1; |
| 1936 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1937 | return 0; |
| 1938 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1939 | rx_qs_destroy: |
| 1940 | be_rx_queues_destroy(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1941 | tx_qs_destroy: |
| 1942 | be_tx_queues_destroy(adapter); |
| 1943 | if_destroy: |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1944 | for (vf = 0; vf < num_vfs; vf++) |
| 1945 | if (adapter->vf_if_handle[vf]) |
| 1946 | be_cmd_if_destroy(adapter, adapter->vf_if_handle[vf]); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1947 | be_cmd_if_destroy(adapter, adapter->if_handle); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1948 | do_none: |
| 1949 | return status; |
| 1950 | } |
| 1951 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1952 | static int be_clear(struct be_adapter *adapter) |
| 1953 | { |
Sathya Perla | 1a8887d | 2009-08-17 00:58:41 +0000 | [diff] [blame] | 1954 | be_mcc_queues_destroy(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1955 | be_rx_queues_destroy(adapter); |
| 1956 | be_tx_queues_destroy(adapter); |
| 1957 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1958 | be_cmd_if_destroy(adapter, adapter->if_handle); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1959 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 1960 | /* tell fw we're done with firing cmds */ |
| 1961 | be_cmd_fw_clean(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1962 | return 0; |
| 1963 | } |
| 1964 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1965 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1966 | #define FW_FILE_HDR_SIGN "ServerEngines Corp. " |
| 1967 | char flash_cookie[2][16] = {"*** SE FLAS", |
| 1968 | "H DIRECTORY *** "}; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1969 | |
| 1970 | static bool be_flash_redboot(struct be_adapter *adapter, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1971 | const u8 *p, u32 img_start, int image_size, |
| 1972 | int hdr_size) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1973 | { |
| 1974 | u32 crc_offset; |
| 1975 | u8 flashed_crc[4]; |
| 1976 | int status; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1977 | |
| 1978 | crc_offset = hdr_size + img_start + image_size - 4; |
| 1979 | |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1980 | p += crc_offset; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1981 | |
| 1982 | status = be_cmd_get_flash_crc(adapter, flashed_crc, |
Ajit Khaparde | f510fc6 | 2010-03-31 01:47:45 +0000 | [diff] [blame] | 1983 | (image_size - 4)); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1984 | if (status) { |
| 1985 | dev_err(&adapter->pdev->dev, |
| 1986 | "could not get crc from flash, not flashing redboot\n"); |
| 1987 | return false; |
| 1988 | } |
| 1989 | |
| 1990 | /*update redboot only if crc does not match*/ |
| 1991 | if (!memcmp(flashed_crc, p, 4)) |
| 1992 | return false; |
| 1993 | else |
| 1994 | return true; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1997 | static int be_flash_data(struct be_adapter *adapter, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1998 | const struct firmware *fw, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1999 | struct be_dma_mem *flash_cmd, int num_of_images) |
| 2000 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2001 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2002 | int status = 0, i, filehdr_size = 0; |
| 2003 | u32 total_bytes = 0, flash_op; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2004 | int num_bytes; |
| 2005 | const u8 *p = fw->data; |
| 2006 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2007 | struct flash_comp *pflashcomp; |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2008 | int num_comp; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2009 | |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2010 | struct flash_comp gen3_flash_types[9] = { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2011 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, IMG_TYPE_ISCSI_ACTIVE, |
| 2012 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2013 | { FLASH_REDBOOT_START_g3, IMG_TYPE_REDBOOT, |
| 2014 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3}, |
| 2015 | { FLASH_iSCSI_BIOS_START_g3, IMG_TYPE_BIOS, |
| 2016 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2017 | { FLASH_PXE_BIOS_START_g3, IMG_TYPE_PXE_BIOS, |
| 2018 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2019 | { FLASH_FCoE_BIOS_START_g3, IMG_TYPE_FCOE_BIOS, |
| 2020 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2021 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, IMG_TYPE_ISCSI_BACKUP, |
| 2022 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2023 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2024 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2025 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, IMG_TYPE_FCOE_FW_BACKUP, |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2026 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2027 | { FLASH_NCSI_START_g3, IMG_TYPE_NCSI_FW, |
| 2028 | FLASH_NCSI_IMAGE_MAX_SIZE_g3} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2029 | }; |
| 2030 | struct flash_comp gen2_flash_types[8] = { |
| 2031 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, IMG_TYPE_ISCSI_ACTIVE, |
| 2032 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2033 | { FLASH_REDBOOT_START_g2, IMG_TYPE_REDBOOT, |
| 2034 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2}, |
| 2035 | { FLASH_iSCSI_BIOS_START_g2, IMG_TYPE_BIOS, |
| 2036 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2037 | { FLASH_PXE_BIOS_START_g2, IMG_TYPE_PXE_BIOS, |
| 2038 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2039 | { FLASH_FCoE_BIOS_START_g2, IMG_TYPE_FCOE_BIOS, |
| 2040 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2041 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, IMG_TYPE_ISCSI_BACKUP, |
| 2042 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2043 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2044 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2045 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, IMG_TYPE_FCOE_FW_BACKUP, |
| 2046 | FLASH_IMAGE_MAX_SIZE_g2} |
| 2047 | }; |
| 2048 | |
| 2049 | if (adapter->generation == BE_GEN3) { |
| 2050 | pflashcomp = gen3_flash_types; |
| 2051 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2052 | num_comp = 9; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2053 | } else { |
| 2054 | pflashcomp = gen2_flash_types; |
| 2055 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2056 | num_comp = 8; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2057 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2058 | for (i = 0; i < num_comp; i++) { |
| 2059 | if ((pflashcomp[i].optype == IMG_TYPE_NCSI_FW) && |
| 2060 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 2061 | continue; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2062 | if ((pflashcomp[i].optype == IMG_TYPE_REDBOOT) && |
| 2063 | (!be_flash_redboot(adapter, fw->data, |
| 2064 | pflashcomp[i].offset, pflashcomp[i].size, |
| 2065 | filehdr_size))) |
| 2066 | continue; |
| 2067 | p = fw->data; |
| 2068 | p += filehdr_size + pflashcomp[i].offset |
| 2069 | + (num_of_images * sizeof(struct image_hdr)); |
| 2070 | if (p + pflashcomp[i].size > fw->data + fw->size) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2071 | return -1; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2072 | total_bytes = pflashcomp[i].size; |
| 2073 | while (total_bytes) { |
| 2074 | if (total_bytes > 32*1024) |
| 2075 | num_bytes = 32*1024; |
| 2076 | else |
| 2077 | num_bytes = total_bytes; |
| 2078 | total_bytes -= num_bytes; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2079 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2080 | if (!total_bytes) |
| 2081 | flash_op = FLASHROM_OPER_FLASH; |
| 2082 | else |
| 2083 | flash_op = FLASHROM_OPER_SAVE; |
| 2084 | memcpy(req->params.data_buf, p, num_bytes); |
| 2085 | p += num_bytes; |
| 2086 | status = be_cmd_write_flashrom(adapter, flash_cmd, |
| 2087 | pflashcomp[i].optype, flash_op, num_bytes); |
| 2088 | if (status) { |
| 2089 | dev_err(&adapter->pdev->dev, |
| 2090 | "cmd to write to flash rom failed.\n"); |
| 2091 | return -1; |
| 2092 | } |
| 2093 | yield(); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2094 | } |
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 | return 0; |
| 2097 | } |
| 2098 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2099 | static int get_ufigen_type(struct flash_file_hdr_g2 *fhdr) |
| 2100 | { |
| 2101 | if (fhdr == NULL) |
| 2102 | return 0; |
| 2103 | if (fhdr->build[0] == '3') |
| 2104 | return BE_GEN3; |
| 2105 | else if (fhdr->build[0] == '2') |
| 2106 | return BE_GEN2; |
| 2107 | else |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2111 | int be_load_fw(struct be_adapter *adapter, u8 *func) |
| 2112 | { |
| 2113 | char fw_file[ETHTOOL_FLASH_MAX_FILENAME]; |
| 2114 | const struct firmware *fw; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2115 | struct flash_file_hdr_g2 *fhdr; |
| 2116 | struct flash_file_hdr_g3 *fhdr3; |
| 2117 | struct image_hdr *img_hdr_ptr = NULL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2118 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2119 | int status, i = 0, num_imgs = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2120 | const u8 *p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2121 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2122 | strcpy(fw_file, func); |
| 2123 | |
| 2124 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 2125 | if (status) |
| 2126 | goto fw_exit; |
| 2127 | |
| 2128 | p = fw->data; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2129 | fhdr = (struct flash_file_hdr_g2 *) p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2130 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 2131 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2132 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024; |
| 2133 | flash_cmd.va = pci_alloc_consistent(adapter->pdev, flash_cmd.size, |
| 2134 | &flash_cmd.dma); |
| 2135 | if (!flash_cmd.va) { |
| 2136 | status = -ENOMEM; |
| 2137 | dev_err(&adapter->pdev->dev, |
| 2138 | "Memory allocation failure while flashing\n"); |
| 2139 | goto fw_exit; |
| 2140 | } |
| 2141 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2142 | if ((adapter->generation == BE_GEN3) && |
| 2143 | (get_ufigen_type(fhdr) == BE_GEN3)) { |
| 2144 | fhdr3 = (struct flash_file_hdr_g3 *) fw->data; |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2145 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 2146 | for (i = 0; i < num_imgs; i++) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2147 | img_hdr_ptr = (struct image_hdr *) (fw->data + |
| 2148 | (sizeof(struct flash_file_hdr_g3) + |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2149 | i * sizeof(struct image_hdr))); |
| 2150 | if (le32_to_cpu(img_hdr_ptr->imageid) == 1) |
| 2151 | status = be_flash_data(adapter, fw, &flash_cmd, |
| 2152 | num_imgs); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2153 | } |
| 2154 | } else if ((adapter->generation == BE_GEN2) && |
| 2155 | (get_ufigen_type(fhdr) == BE_GEN2)) { |
| 2156 | status = be_flash_data(adapter, fw, &flash_cmd, 0); |
| 2157 | } else { |
| 2158 | dev_err(&adapter->pdev->dev, |
| 2159 | "UFI and Interface are not compatible for flashing\n"); |
| 2160 | status = -1; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | pci_free_consistent(adapter->pdev, flash_cmd.size, flash_cmd.va, |
| 2164 | flash_cmd.dma); |
| 2165 | if (status) { |
| 2166 | dev_err(&adapter->pdev->dev, "Firmware load error\n"); |
| 2167 | goto fw_exit; |
| 2168 | } |
| 2169 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2170 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2171 | |
| 2172 | fw_exit: |
| 2173 | release_firmware(fw); |
| 2174 | return status; |
| 2175 | } |
| 2176 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2177 | static struct net_device_ops be_netdev_ops = { |
| 2178 | .ndo_open = be_open, |
| 2179 | .ndo_stop = be_close, |
| 2180 | .ndo_start_xmit = be_xmit, |
| 2181 | .ndo_get_stats = be_get_stats, |
| 2182 | .ndo_set_rx_mode = be_set_multicast_list, |
| 2183 | .ndo_set_mac_address = be_mac_addr_set, |
| 2184 | .ndo_change_mtu = be_change_mtu, |
| 2185 | .ndo_validate_addr = eth_validate_addr, |
| 2186 | .ndo_vlan_rx_register = be_vlan_register, |
| 2187 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 2188 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2189 | .ndo_set_vf_mac = be_set_vf_mac |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2190 | }; |
| 2191 | |
| 2192 | static void be_netdev_init(struct net_device *netdev) |
| 2193 | { |
| 2194 | struct be_adapter *adapter = netdev_priv(netdev); |
| 2195 | |
| 2196 | 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] | 2197 | 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] | 2198 | NETIF_F_GRO | NETIF_F_TSO6; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2199 | |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 2200 | netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_HW_CSUM; |
| 2201 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2202 | netdev->flags |= IFF_MULTICAST; |
| 2203 | |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 2204 | adapter->rx_csum = true; |
| 2205 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 2206 | /* Default settings for Rx and Tx flow control */ |
| 2207 | adapter->rx_fc = true; |
| 2208 | adapter->tx_fc = true; |
| 2209 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 2210 | netif_set_gso_max_size(netdev, 65535); |
| 2211 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2212 | BE_SET_NETDEV_OPS(netdev, &be_netdev_ops); |
| 2213 | |
| 2214 | SET_ETHTOOL_OPS(netdev, &be_ethtool_ops); |
| 2215 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2216 | netif_napi_add(netdev, &adapter->rx_eq.napi, be_poll_rx, |
| 2217 | BE_NAPI_WEIGHT); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2218 | netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2219 | BE_NAPI_WEIGHT); |
| 2220 | |
| 2221 | netif_carrier_off(netdev); |
| 2222 | netif_stop_queue(netdev); |
| 2223 | } |
| 2224 | |
| 2225 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 2226 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2227 | if (adapter->csr) |
| 2228 | iounmap(adapter->csr); |
| 2229 | if (adapter->db) |
| 2230 | iounmap(adapter->db); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2231 | if (adapter->pcicfg && be_physfn(adapter)) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2232 | iounmap(adapter->pcicfg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 2236 | { |
| 2237 | u8 __iomem *addr; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2238 | int pcicfg_reg, db_reg; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2239 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2240 | if (be_physfn(adapter)) { |
| 2241 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2), |
| 2242 | pci_resource_len(adapter->pdev, 2)); |
| 2243 | if (addr == NULL) |
| 2244 | return -ENOMEM; |
| 2245 | adapter->csr = addr; |
| 2246 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2247 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2248 | if (adapter->generation == BE_GEN2) { |
| 2249 | pcicfg_reg = 1; |
| 2250 | db_reg = 4; |
| 2251 | } else { |
| 2252 | pcicfg_reg = 0; |
| 2253 | if (be_physfn(adapter)) |
| 2254 | db_reg = 4; |
| 2255 | else |
| 2256 | db_reg = 0; |
| 2257 | } |
| 2258 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, db_reg), |
| 2259 | pci_resource_len(adapter->pdev, db_reg)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2260 | if (addr == NULL) |
| 2261 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2262 | adapter->db = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2263 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2264 | if (be_physfn(adapter)) { |
| 2265 | addr = ioremap_nocache( |
| 2266 | pci_resource_start(adapter->pdev, pcicfg_reg), |
| 2267 | pci_resource_len(adapter->pdev, pcicfg_reg)); |
| 2268 | if (addr == NULL) |
| 2269 | goto pci_map_err; |
| 2270 | adapter->pcicfg = addr; |
| 2271 | } else |
| 2272 | adapter->pcicfg = adapter->db + SRIOV_VF_PCICFG_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2273 | |
| 2274 | return 0; |
| 2275 | pci_map_err: |
| 2276 | be_unmap_pci_bars(adapter); |
| 2277 | return -ENOMEM; |
| 2278 | } |
| 2279 | |
| 2280 | |
| 2281 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 2282 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2283 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2284 | |
| 2285 | be_unmap_pci_bars(adapter); |
| 2286 | |
| 2287 | if (mem->va) |
| 2288 | pci_free_consistent(adapter->pdev, mem->size, |
| 2289 | mem->va, mem->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2290 | |
| 2291 | mem = &adapter->mc_cmd_mem; |
| 2292 | if (mem->va) |
| 2293 | pci_free_consistent(adapter->pdev, mem->size, |
| 2294 | mem->va, mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2297 | static int be_ctrl_init(struct be_adapter *adapter) |
| 2298 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2299 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 2300 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2301 | struct be_dma_mem *mc_cmd_mem = &adapter->mc_cmd_mem; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2302 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2303 | |
| 2304 | status = be_map_pci_bars(adapter); |
| 2305 | if (status) |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2306 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2307 | |
| 2308 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 2309 | mbox_mem_alloc->va = pci_alloc_consistent(adapter->pdev, |
| 2310 | mbox_mem_alloc->size, &mbox_mem_alloc->dma); |
| 2311 | if (!mbox_mem_alloc->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2312 | status = -ENOMEM; |
| 2313 | goto unmap_pci_bars; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2314 | } |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2315 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2316 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 2317 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 2318 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 2319 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2320 | |
| 2321 | mc_cmd_mem->size = sizeof(struct be_cmd_req_mcast_mac_config); |
| 2322 | mc_cmd_mem->va = pci_alloc_consistent(adapter->pdev, mc_cmd_mem->size, |
| 2323 | &mc_cmd_mem->dma); |
| 2324 | if (mc_cmd_mem->va == NULL) { |
| 2325 | status = -ENOMEM; |
| 2326 | goto free_mbox; |
| 2327 | } |
| 2328 | memset(mc_cmd_mem->va, 0, mc_cmd_mem->size); |
| 2329 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2330 | spin_lock_init(&adapter->mbox_lock); |
| 2331 | spin_lock_init(&adapter->mcc_lock); |
| 2332 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2333 | |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2334 | init_completion(&adapter->flash_compl); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 2335 | pci_save_state(adapter->pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2336 | return 0; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2337 | |
| 2338 | free_mbox: |
| 2339 | pci_free_consistent(adapter->pdev, mbox_mem_alloc->size, |
| 2340 | mbox_mem_alloc->va, mbox_mem_alloc->dma); |
| 2341 | |
| 2342 | unmap_pci_bars: |
| 2343 | be_unmap_pci_bars(adapter); |
| 2344 | |
| 2345 | done: |
| 2346 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 2350 | { |
| 2351 | struct be_stats_obj *stats = &adapter->stats; |
| 2352 | struct be_dma_mem *cmd = &stats->cmd; |
| 2353 | |
| 2354 | if (cmd->va) |
| 2355 | pci_free_consistent(adapter->pdev, cmd->size, |
| 2356 | cmd->va, cmd->dma); |
| 2357 | } |
| 2358 | |
| 2359 | static int be_stats_init(struct be_adapter *adapter) |
| 2360 | { |
| 2361 | struct be_stats_obj *stats = &adapter->stats; |
| 2362 | struct be_dma_mem *cmd = &stats->cmd; |
| 2363 | |
| 2364 | cmd->size = sizeof(struct be_cmd_req_get_stats); |
| 2365 | cmd->va = pci_alloc_consistent(adapter->pdev, cmd->size, &cmd->dma); |
| 2366 | if (cmd->va == NULL) |
| 2367 | return -1; |
David S. Miller | d291b9a | 2010-01-28 21:36:21 -0800 | [diff] [blame] | 2368 | memset(cmd->va, 0, cmd->size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2369 | return 0; |
| 2370 | } |
| 2371 | |
| 2372 | static void __devexit be_remove(struct pci_dev *pdev) |
| 2373 | { |
| 2374 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2375 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2376 | if (!adapter) |
| 2377 | return; |
| 2378 | |
| 2379 | unregister_netdev(adapter->netdev); |
| 2380 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2381 | be_clear(adapter); |
| 2382 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2383 | be_stats_cleanup(adapter); |
| 2384 | |
| 2385 | be_ctrl_cleanup(adapter); |
| 2386 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2387 | be_sriov_disable(adapter); |
| 2388 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2389 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2390 | |
| 2391 | pci_set_drvdata(pdev, NULL); |
| 2392 | pci_release_regions(pdev); |
| 2393 | pci_disable_device(pdev); |
| 2394 | |
| 2395 | free_netdev(adapter->netdev); |
| 2396 | } |
| 2397 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2398 | static int be_get_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2399 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2400 | int status; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2401 | u8 mac[ETH_ALEN]; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 2402 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2403 | status = be_cmd_get_fw_ver(adapter, adapter->fw_ver); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2404 | if (status) |
| 2405 | return status; |
| 2406 | |
Ajit Khaparde | dcb9b56 | 2009-09-30 21:58:22 -0700 | [diff] [blame] | 2407 | status = be_cmd_query_fw_cfg(adapter, |
| 2408 | &adapter->port_num, &adapter->cap); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2409 | if (status) |
| 2410 | return status; |
| 2411 | |
| 2412 | memset(mac, 0, ETH_ALEN); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2413 | |
| 2414 | if (be_physfn(adapter)) { |
| 2415 | status = be_cmd_mac_addr_query(adapter, mac, |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2416 | MAC_ADDRESS_TYPE_NETWORK, true /*permanent */, 0); |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 2417 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2418 | if (status) |
| 2419 | return status; |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 2420 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2421 | if (!is_valid_ether_addr(mac)) |
| 2422 | return -EADDRNOTAVAIL; |
| 2423 | |
| 2424 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 2425 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 2426 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2427 | |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 2428 | if (adapter->cap & 0x400) |
| 2429 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/4; |
| 2430 | else |
| 2431 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED; |
| 2432 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2433 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | static int __devinit be_probe(struct pci_dev *pdev, |
| 2437 | const struct pci_device_id *pdev_id) |
| 2438 | { |
| 2439 | int status = 0; |
| 2440 | struct be_adapter *adapter; |
| 2441 | struct net_device *netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2442 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2443 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2444 | status = pci_enable_device(pdev); |
| 2445 | if (status) |
| 2446 | goto do_none; |
| 2447 | |
| 2448 | status = pci_request_regions(pdev, DRV_NAME); |
| 2449 | if (status) |
| 2450 | goto disable_dev; |
| 2451 | pci_set_master(pdev); |
| 2452 | |
| 2453 | netdev = alloc_etherdev(sizeof(struct be_adapter)); |
| 2454 | if (netdev == NULL) { |
| 2455 | status = -ENOMEM; |
| 2456 | goto rel_reg; |
| 2457 | } |
| 2458 | adapter = netdev_priv(netdev); |
Ajit Khaparde | 7b139c8 | 2010-01-27 21:56:44 +0000 | [diff] [blame] | 2459 | |
| 2460 | switch (pdev->device) { |
| 2461 | case BE_DEVICE_ID1: |
| 2462 | case OC_DEVICE_ID1: |
| 2463 | adapter->generation = BE_GEN2; |
| 2464 | break; |
| 2465 | case BE_DEVICE_ID2: |
| 2466 | case OC_DEVICE_ID2: |
| 2467 | adapter->generation = BE_GEN3; |
| 2468 | break; |
| 2469 | default: |
| 2470 | adapter->generation = 0; |
| 2471 | } |
| 2472 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2473 | adapter->pdev = pdev; |
| 2474 | pci_set_drvdata(pdev, adapter); |
| 2475 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2476 | be_netdev_init(netdev); |
| 2477 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2478 | |
| 2479 | be_msix_enable(adapter); |
| 2480 | |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2481 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2482 | if (!status) { |
| 2483 | netdev->features |= NETIF_F_HIGHDMA; |
| 2484 | } else { |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2485 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2486 | if (status) { |
| 2487 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 2488 | goto free_netdev; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2492 | be_sriov_enable(adapter); |
| 2493 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2494 | status = be_ctrl_init(adapter); |
| 2495 | if (status) |
| 2496 | goto free_netdev; |
| 2497 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2498 | /* sync up with fw's ready state */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2499 | if (be_physfn(adapter)) { |
| 2500 | status = be_cmd_POST(adapter); |
| 2501 | if (status) |
| 2502 | goto ctrl_clean; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2503 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2504 | |
| 2505 | /* tell fw we're ready to fire cmds */ |
| 2506 | status = be_cmd_fw_init(adapter); |
| 2507 | if (status) |
| 2508 | goto ctrl_clean; |
| 2509 | |
Sarveshwar Bandi | 556ae19 | 2010-05-24 18:38:25 -0700 | [diff] [blame] | 2510 | if (be_physfn(adapter)) { |
| 2511 | status = be_cmd_reset_function(adapter); |
| 2512 | if (status) |
| 2513 | goto ctrl_clean; |
| 2514 | } |
| 2515 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2516 | status = be_stats_init(adapter); |
| 2517 | if (status) |
| 2518 | goto ctrl_clean; |
| 2519 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2520 | status = be_get_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2521 | if (status) |
| 2522 | goto stats_clean; |
| 2523 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2524 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2525 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2526 | status = be_setup(adapter); |
| 2527 | if (status) |
| 2528 | goto stats_clean; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2529 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2530 | status = register_netdev(netdev); |
| 2531 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2532 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2533 | |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 2534 | 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] | 2535 | return 0; |
| 2536 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2537 | unsetup: |
| 2538 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2539 | stats_clean: |
| 2540 | be_stats_cleanup(adapter); |
| 2541 | ctrl_clean: |
| 2542 | be_ctrl_cleanup(adapter); |
| 2543 | free_netdev: |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2544 | be_msix_disable(adapter); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2545 | be_sriov_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2546 | free_netdev(adapter->netdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2547 | pci_set_drvdata(pdev, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2548 | rel_reg: |
| 2549 | pci_release_regions(pdev); |
| 2550 | disable_dev: |
| 2551 | pci_disable_device(pdev); |
| 2552 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 2553 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2554 | return status; |
| 2555 | } |
| 2556 | |
| 2557 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2558 | { |
| 2559 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2560 | struct net_device *netdev = adapter->netdev; |
| 2561 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2562 | if (adapter->wol) |
| 2563 | be_setup_wol(adapter, true); |
| 2564 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2565 | netif_device_detach(netdev); |
| 2566 | if (netif_running(netdev)) { |
| 2567 | rtnl_lock(); |
| 2568 | be_close(netdev); |
| 2569 | rtnl_unlock(); |
| 2570 | } |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 2571 | be_cmd_get_flow_control(adapter, &adapter->tx_fc, &adapter->rx_fc); |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 2572 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2573 | |
| 2574 | pci_save_state(pdev); |
| 2575 | pci_disable_device(pdev); |
| 2576 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 2577 | return 0; |
| 2578 | } |
| 2579 | |
| 2580 | static int be_resume(struct pci_dev *pdev) |
| 2581 | { |
| 2582 | int status = 0; |
| 2583 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2584 | struct net_device *netdev = adapter->netdev; |
| 2585 | |
| 2586 | netif_device_detach(netdev); |
| 2587 | |
| 2588 | status = pci_enable_device(pdev); |
| 2589 | if (status) |
| 2590 | return status; |
| 2591 | |
| 2592 | pci_set_power_state(pdev, 0); |
| 2593 | pci_restore_state(pdev); |
| 2594 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2595 | /* tell fw we're ready to fire cmds */ |
| 2596 | status = be_cmd_fw_init(adapter); |
| 2597 | if (status) |
| 2598 | return status; |
| 2599 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 2600 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2601 | if (netif_running(netdev)) { |
| 2602 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2603 | be_open(netdev); |
| 2604 | rtnl_unlock(); |
| 2605 | } |
| 2606 | netif_device_attach(netdev); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2607 | |
| 2608 | if (adapter->wol) |
| 2609 | be_setup_wol(adapter, false); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2610 | return 0; |
| 2611 | } |
| 2612 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 2613 | /* |
| 2614 | * An FLR will stop BE from DMAing any data. |
| 2615 | */ |
| 2616 | static void be_shutdown(struct pci_dev *pdev) |
| 2617 | { |
| 2618 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2619 | struct net_device *netdev = adapter->netdev; |
| 2620 | |
| 2621 | netif_device_detach(netdev); |
| 2622 | |
| 2623 | be_cmd_reset_function(adapter); |
| 2624 | |
| 2625 | if (adapter->wol) |
| 2626 | be_setup_wol(adapter, true); |
| 2627 | |
| 2628 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 2631 | static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev, |
| 2632 | pci_channel_state_t state) |
| 2633 | { |
| 2634 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2635 | struct net_device *netdev = adapter->netdev; |
| 2636 | |
| 2637 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 2638 | |
| 2639 | adapter->eeh_err = true; |
| 2640 | |
| 2641 | netif_device_detach(netdev); |
| 2642 | |
| 2643 | if (netif_running(netdev)) { |
| 2644 | rtnl_lock(); |
| 2645 | be_close(netdev); |
| 2646 | rtnl_unlock(); |
| 2647 | } |
| 2648 | be_clear(adapter); |
| 2649 | |
| 2650 | if (state == pci_channel_io_perm_failure) |
| 2651 | return PCI_ERS_RESULT_DISCONNECT; |
| 2652 | |
| 2653 | pci_disable_device(pdev); |
| 2654 | |
| 2655 | return PCI_ERS_RESULT_NEED_RESET; |
| 2656 | } |
| 2657 | |
| 2658 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 2659 | { |
| 2660 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2661 | int status; |
| 2662 | |
| 2663 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
| 2664 | adapter->eeh_err = false; |
| 2665 | |
| 2666 | status = pci_enable_device(pdev); |
| 2667 | if (status) |
| 2668 | return PCI_ERS_RESULT_DISCONNECT; |
| 2669 | |
| 2670 | pci_set_master(pdev); |
| 2671 | pci_set_power_state(pdev, 0); |
| 2672 | pci_restore_state(pdev); |
| 2673 | |
| 2674 | /* Check if card is ok and fw is ready */ |
| 2675 | status = be_cmd_POST(adapter); |
| 2676 | if (status) |
| 2677 | return PCI_ERS_RESULT_DISCONNECT; |
| 2678 | |
| 2679 | return PCI_ERS_RESULT_RECOVERED; |
| 2680 | } |
| 2681 | |
| 2682 | static void be_eeh_resume(struct pci_dev *pdev) |
| 2683 | { |
| 2684 | int status = 0; |
| 2685 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 2686 | struct net_device *netdev = adapter->netdev; |
| 2687 | |
| 2688 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 2689 | |
| 2690 | pci_save_state(pdev); |
| 2691 | |
| 2692 | /* tell fw we're ready to fire cmds */ |
| 2693 | status = be_cmd_fw_init(adapter); |
| 2694 | if (status) |
| 2695 | goto err; |
| 2696 | |
| 2697 | status = be_setup(adapter); |
| 2698 | if (status) |
| 2699 | goto err; |
| 2700 | |
| 2701 | if (netif_running(netdev)) { |
| 2702 | status = be_open(netdev); |
| 2703 | if (status) |
| 2704 | goto err; |
| 2705 | } |
| 2706 | netif_device_attach(netdev); |
| 2707 | return; |
| 2708 | err: |
| 2709 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | static struct pci_error_handlers be_eeh_handlers = { |
| 2713 | .error_detected = be_eeh_err_detected, |
| 2714 | .slot_reset = be_eeh_reset, |
| 2715 | .resume = be_eeh_resume, |
| 2716 | }; |
| 2717 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2718 | static struct pci_driver be_driver = { |
| 2719 | .name = DRV_NAME, |
| 2720 | .id_table = be_dev_ids, |
| 2721 | .probe = be_probe, |
| 2722 | .remove = be_remove, |
| 2723 | .suspend = be_suspend, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 2724 | .resume = be_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 2725 | .shutdown = be_shutdown, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 2726 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2727 | }; |
| 2728 | |
| 2729 | static int __init be_init_module(void) |
| 2730 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2731 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 2732 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2733 | printk(KERN_WARNING DRV_NAME |
| 2734 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 2735 | " Using 2048\n"); |
| 2736 | rx_frag_size = 2048; |
| 2737 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2738 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2739 | if (num_vfs > 32) { |
| 2740 | printk(KERN_WARNING DRV_NAME |
| 2741 | " : Module param num_vfs must not be greater than 32." |
| 2742 | "Using 32\n"); |
| 2743 | num_vfs = 32; |
| 2744 | } |
| 2745 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2746 | return pci_register_driver(&be_driver); |
| 2747 | } |
| 2748 | module_init(be_init_module); |
| 2749 | |
| 2750 | static void __exit be_exit_module(void) |
| 2751 | { |
| 2752 | pci_unregister_driver(&be_driver); |
| 2753 | } |
| 2754 | module_exit(be_exit_module); |