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