Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2011 Emulex |
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: |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 18 | #include <linux/prefetch.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 19 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 20 | #include "be_cmds.h" |
Stephen Hemminger | 65f71b8 | 2009-03-27 00:25:24 -0700 | [diff] [blame] | 21 | #include <asm/div64.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 22 | |
| 23 | MODULE_VERSION(DRV_VER); |
| 24 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
| 25 | MODULE_DESCRIPTION(DRV_DESC " " DRV_VER); |
| 26 | MODULE_AUTHOR("ServerEngines Corporation"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 29 | static ushort rx_frag_size = 2048; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 30 | static unsigned int num_vfs; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 31 | module_param(rx_frag_size, ushort, S_IRUGO); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 32 | module_param(num_vfs, uint, S_IRUGO); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 33 | 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] | 34 | MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 35 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 36 | static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = { |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 37 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Ajit Khaparde | 59fd5d8 | 2009-10-29 01:11:06 -0700 | [diff] [blame] | 38 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 39 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 40 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 41 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)}, |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 42 | { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 43 | { 0 } |
| 44 | }; |
| 45 | MODULE_DEVICE_TABLE(pci, be_dev_ids); |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 46 | /* UE Status Low CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 47 | static const char * const ue_status_low_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 48 | "CEV", |
| 49 | "CTX", |
| 50 | "DBUF", |
| 51 | "ERX", |
| 52 | "Host", |
| 53 | "MPU", |
| 54 | "NDMA", |
| 55 | "PTC ", |
| 56 | "RDMA ", |
| 57 | "RXF ", |
| 58 | "RXIPS ", |
| 59 | "RXULP0 ", |
| 60 | "RXULP1 ", |
| 61 | "RXULP2 ", |
| 62 | "TIM ", |
| 63 | "TPOST ", |
| 64 | "TPRE ", |
| 65 | "TXIPS ", |
| 66 | "TXULP0 ", |
| 67 | "TXULP1 ", |
| 68 | "UC ", |
| 69 | "WDMA ", |
| 70 | "TXULP2 ", |
| 71 | "HOST1 ", |
| 72 | "P0_OB_LINK ", |
| 73 | "P1_OB_LINK ", |
| 74 | "HOST_GPIO ", |
| 75 | "MBOX ", |
| 76 | "AXGMAC0", |
| 77 | "AXGMAC1", |
| 78 | "JTAG", |
| 79 | "MPU_INTPEND" |
| 80 | }; |
| 81 | /* UE Status High CSR */ |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 82 | static const char * const ue_status_hi_desc[] = { |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 83 | "LPCMEMHOST", |
| 84 | "MGMT_MAC", |
| 85 | "PCS0ONLINE", |
| 86 | "MPU_IRAM", |
| 87 | "PCS1ONLINE", |
| 88 | "PCTL0", |
| 89 | "PCTL1", |
| 90 | "PMEM", |
| 91 | "RR", |
| 92 | "TXPB", |
| 93 | "RXPP", |
| 94 | "XAUI", |
| 95 | "TXP", |
| 96 | "ARM", |
| 97 | "IPC", |
| 98 | "HOST2", |
| 99 | "HOST3", |
| 100 | "HOST4", |
| 101 | "HOST5", |
| 102 | "HOST6", |
| 103 | "HOST7", |
| 104 | "HOST8", |
| 105 | "HOST9", |
Joe Perches | 42c8b11 | 2011-07-09 02:56:56 -0700 | [diff] [blame] | 106 | "NETC", |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 107 | "Unknown", |
| 108 | "Unknown", |
| 109 | "Unknown", |
| 110 | "Unknown", |
| 111 | "Unknown", |
| 112 | "Unknown", |
| 113 | "Unknown", |
| 114 | "Unknown" |
| 115 | }; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 116 | |
| 117 | static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q) |
| 118 | { |
| 119 | struct be_dma_mem *mem = &q->dma_mem; |
| 120 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 121 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 122 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q, |
| 126 | u16 len, u16 entry_size) |
| 127 | { |
| 128 | struct be_dma_mem *mem = &q->dma_mem; |
| 129 | |
| 130 | memset(q, 0, sizeof(*q)); |
| 131 | q->len = len; |
| 132 | q->entry_size = entry_size; |
| 133 | mem->size = len * entry_size; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 134 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma, |
| 135 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 136 | if (!mem->va) |
| 137 | return -1; |
| 138 | memset(mem->va, 0, mem->size); |
| 139 | return 0; |
| 140 | } |
| 141 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 142 | static void be_intr_set(struct be_adapter *adapter, bool enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 143 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 144 | u8 __iomem *addr = adapter->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 145 | u32 reg = ioread32(addr); |
| 146 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 147 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 148 | if (adapter->eeh_err) |
| 149 | return; |
| 150 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 151 | if (!enabled && enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 152 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 153 | else if (enabled && !enable) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 154 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 155 | else |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 156 | return; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 157 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 158 | iowrite32(reg, addr); |
| 159 | } |
| 160 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 161 | 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] | 162 | { |
| 163 | u32 val = 0; |
| 164 | val |= qid & DB_RQ_RING_ID_MASK; |
| 165 | val |= posted << DB_RQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 166 | |
| 167 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 168 | iowrite32(val, adapter->db + DB_RQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 171 | 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] | 172 | { |
| 173 | u32 val = 0; |
| 174 | val |= qid & DB_TXULP_RING_ID_MASK; |
| 175 | val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 176 | |
| 177 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 178 | iowrite32(val, adapter->db + DB_TXULP1_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 181 | static void be_eq_notify(struct be_adapter *adapter, u16 qid, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 182 | bool arm, bool clear_int, u16 num_popped) |
| 183 | { |
| 184 | u32 val = 0; |
| 185 | val |= qid & DB_EQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 186 | val |= ((qid & DB_EQ_RING_ID_EXT_MASK) << |
| 187 | DB_EQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 188 | |
| 189 | if (adapter->eeh_err) |
| 190 | return; |
| 191 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 192 | if (arm) |
| 193 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 194 | if (clear_int) |
| 195 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 196 | val |= 1 << DB_EQ_EVNT_SHIFT; |
| 197 | val |= num_popped << DB_EQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 198 | iowrite32(val, adapter->db + DB_EQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 201 | 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] | 202 | { |
| 203 | u32 val = 0; |
| 204 | val |= qid & DB_CQ_RING_ID_MASK; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 205 | val |= ((qid & DB_CQ_RING_ID_EXT_MASK) << |
| 206 | DB_CQ_RING_ID_EXT_MASK_SHIFT); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 207 | |
| 208 | if (adapter->eeh_err) |
| 209 | return; |
| 210 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 211 | if (arm) |
| 212 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 213 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 214 | iowrite32(val, adapter->db + DB_CQ_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 217 | static int be_mac_addr_set(struct net_device *netdev, void *p) |
| 218 | { |
| 219 | struct be_adapter *adapter = netdev_priv(netdev); |
| 220 | struct sockaddr *addr = p; |
| 221 | int status = 0; |
| 222 | |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 223 | if (!is_valid_ether_addr(addr->sa_data)) |
| 224 | return -EADDRNOTAVAIL; |
| 225 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 226 | /* MAC addr configuration will be done in hardware for VFs |
| 227 | * by their corresponding PFs. Just copy to netdev addr here |
| 228 | */ |
| 229 | if (!be_physfn(adapter)) |
| 230 | goto netdev_addr; |
| 231 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 232 | status = be_cmd_pmac_del(adapter, adapter->if_handle, |
| 233 | adapter->pmac_id, 0); |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 234 | if (status) |
| 235 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 236 | |
Sathya Perla | a65027e | 2009-08-17 00:58:04 +0000 | [diff] [blame] | 237 | status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 238 | adapter->if_handle, &adapter->pmac_id, 0); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 239 | netdev_addr: |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 240 | if (!status) |
| 241 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 242 | |
| 243 | return status; |
| 244 | } |
| 245 | |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 246 | static void populate_be2_stats(struct be_adapter *adapter) |
| 247 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 248 | struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter); |
| 249 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 250 | struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 251 | struct be_port_rxf_stats_v0 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 252 | &rxf_stats->port[adapter->port_num]; |
| 253 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 254 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 255 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 256 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 257 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 258 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 259 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 260 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 261 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 262 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 263 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 264 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 265 | drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow; |
| 266 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 267 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 268 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 269 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 270 | drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 271 | drvs->rx_dropped_header_too_small = |
| 272 | port_stats->rx_dropped_header_too_small; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 273 | drvs->rx_address_match_errors = port_stats->rx_address_match_errors; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 274 | drvs->rx_alignment_symbol_errors = |
| 275 | port_stats->rx_alignment_symbol_errors; |
| 276 | |
| 277 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 278 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 279 | |
| 280 | if (adapter->port_num) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 281 | drvs->jabber_events = rxf_stats->port1_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 282 | else |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 283 | drvs->jabber_events = rxf_stats->port0_jabber_events; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 284 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 285 | drvs->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb; |
| 286 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 287 | drvs->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring; |
| 288 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 289 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 290 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 291 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 292 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 293 | } |
| 294 | |
| 295 | static void populate_be3_stats(struct be_adapter *adapter) |
| 296 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 297 | struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter); |
| 298 | struct be_pmem_stats *pmem_sts = &hw_stats->pmem; |
| 299 | struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 300 | struct be_port_rxf_stats_v1 *port_stats = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 301 | &rxf_stats->port[adapter->port_num]; |
| 302 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 303 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 304 | be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats)); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 305 | drvs->rx_pause_frames = port_stats->rx_pause_frames; |
| 306 | drvs->rx_crc_errors = port_stats->rx_crc_errors; |
| 307 | drvs->rx_control_frames = port_stats->rx_control_frames; |
| 308 | drvs->rx_in_range_errors = port_stats->rx_in_range_errors; |
| 309 | drvs->rx_frame_too_long = port_stats->rx_frame_too_long; |
| 310 | drvs->rx_dropped_runt = port_stats->rx_dropped_runt; |
| 311 | drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs; |
| 312 | drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs; |
| 313 | drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs; |
| 314 | drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length; |
| 315 | drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small; |
| 316 | drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short; |
| 317 | drvs->rx_out_range_errors = port_stats->rx_out_range_errors; |
| 318 | drvs->rx_dropped_header_too_small = |
| 319 | port_stats->rx_dropped_header_too_small; |
| 320 | drvs->rx_input_fifo_overflow_drop = |
| 321 | port_stats->rx_input_fifo_overflow_drop; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 322 | drvs->rx_address_match_errors = port_stats->rx_address_match_errors; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 323 | drvs->rx_alignment_symbol_errors = |
| 324 | port_stats->rx_alignment_symbol_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 325 | drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 326 | drvs->tx_pauseframes = port_stats->tx_pauseframes; |
| 327 | drvs->tx_controlframes = port_stats->tx_controlframes; |
| 328 | drvs->jabber_events = port_stats->jabber_events; |
| 329 | drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf; |
| 330 | drvs->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb; |
| 331 | drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr; |
| 332 | drvs->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring; |
| 333 | drvs->forwarded_packets = rxf_stats->forwarded_packets; |
| 334 | drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 335 | drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr; |
| 336 | drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 337 | adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops; |
| 338 | } |
| 339 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 340 | static void populate_lancer_stats(struct be_adapter *adapter) |
| 341 | { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 342 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 343 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 344 | struct lancer_pport_stats *pport_stats = |
| 345 | pport_stats_from_cmd(adapter); |
| 346 | |
| 347 | be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats)); |
| 348 | drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo; |
| 349 | drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo; |
| 350 | drvs->rx_control_frames = pport_stats->rx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 351 | drvs->rx_in_range_errors = pport_stats->rx_in_range_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 352 | drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 353 | drvs->rx_dropped_runt = pport_stats->rx_dropped_runt; |
| 354 | drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors; |
| 355 | drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors; |
| 356 | drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors; |
| 357 | drvs->rx_dropped_tcp_length = |
| 358 | pport_stats->rx_dropped_invalid_tcp_length; |
| 359 | drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small; |
| 360 | drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short; |
| 361 | drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors; |
| 362 | drvs->rx_dropped_header_too_small = |
| 363 | pport_stats->rx_dropped_header_too_small; |
| 364 | drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
| 365 | drvs->rx_address_match_errors = pport_stats->rx_address_match_errors; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 366 | drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 367 | drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 368 | drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo; |
| 369 | drvs->tx_controlframes = pport_stats->tx_control_frames_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 370 | drvs->jabber_events = pport_stats->rx_jabbers; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 371 | drvs->rx_drops_invalid_ring = pport_stats->rx_drops_invalid_queue; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 372 | drvs->forwarded_packets = pport_stats->num_forwards_lo; |
| 373 | drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 374 | drvs->rx_drops_too_many_frags = |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 375 | pport_stats->rx_drops_too_many_frags_lo; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 376 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 377 | |
| 378 | void be_parse_stats(struct be_adapter *adapter) |
| 379 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 380 | struct be_erx_stats_v1 *erx = be_erx_stats_from_cmd(adapter); |
| 381 | struct be_rx_obj *rxo; |
| 382 | int i; |
| 383 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 384 | if (adapter->generation == BE_GEN3) { |
| 385 | if (lancer_chip(adapter)) |
| 386 | populate_lancer_stats(adapter); |
| 387 | else |
| 388 | populate_be3_stats(adapter); |
| 389 | } else { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 390 | populate_be2_stats(adapter); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 391 | } |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 392 | |
| 393 | /* as erx_v1 is longer than v0, ok to use v1 defn for v0 access */ |
| 394 | for_all_rx_queues(adapter, rxo, i) |
| 395 | rx_stats(rxo)->rx_drops_no_frags = |
| 396 | erx->rx_drops_no_fragments[rxo->q.id]; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 399 | static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev, |
| 400 | struct rtnl_link_stats64 *stats) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 401 | { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 402 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 403 | struct be_drv_stats *drvs = &adapter->drv_stats; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 404 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 405 | struct be_tx_obj *txo; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 406 | u64 pkts, bytes; |
| 407 | unsigned int start; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 408 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 409 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 410 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 411 | const struct be_rx_stats *rx_stats = rx_stats(rxo); |
| 412 | do { |
| 413 | start = u64_stats_fetch_begin_bh(&rx_stats->sync); |
| 414 | pkts = rx_stats(rxo)->rx_pkts; |
| 415 | bytes = rx_stats(rxo)->rx_bytes; |
| 416 | } while (u64_stats_fetch_retry_bh(&rx_stats->sync, start)); |
| 417 | stats->rx_packets += pkts; |
| 418 | stats->rx_bytes += bytes; |
| 419 | stats->multicast += rx_stats(rxo)->rx_mcast_pkts; |
| 420 | stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs + |
| 421 | rx_stats(rxo)->rx_drops_no_frags; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 424 | for_all_tx_queues(adapter, txo, i) { |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 425 | const struct be_tx_stats *tx_stats = tx_stats(txo); |
| 426 | do { |
| 427 | start = u64_stats_fetch_begin_bh(&tx_stats->sync); |
| 428 | pkts = tx_stats(txo)->tx_pkts; |
| 429 | bytes = tx_stats(txo)->tx_bytes; |
| 430 | } while (u64_stats_fetch_retry_bh(&tx_stats->sync, start)); |
| 431 | stats->tx_packets += pkts; |
| 432 | stats->tx_bytes += bytes; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 433 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 434 | |
| 435 | /* bad pkts received */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 436 | stats->rx_errors = drvs->rx_crc_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 437 | drvs->rx_alignment_symbol_errors + |
| 438 | drvs->rx_in_range_errors + |
| 439 | drvs->rx_out_range_errors + |
| 440 | drvs->rx_frame_too_long + |
| 441 | drvs->rx_dropped_too_small + |
| 442 | drvs->rx_dropped_too_short + |
| 443 | drvs->rx_dropped_header_too_small + |
| 444 | drvs->rx_dropped_tcp_length + |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 445 | drvs->rx_dropped_runt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 446 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 447 | /* detailed rx errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 448 | stats->rx_length_errors = drvs->rx_in_range_errors + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 449 | drvs->rx_out_range_errors + |
| 450 | drvs->rx_frame_too_long; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 451 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 452 | stats->rx_crc_errors = drvs->rx_crc_errors; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 453 | |
| 454 | /* frame alignment errors */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 455 | stats->rx_frame_errors = drvs->rx_alignment_symbol_errors; |
Sathya Perla | 6811086 | 2009-06-10 02:21:16 +0000 | [diff] [blame] | 456 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 457 | /* receiver fifo overrun */ |
| 458 | /* drops_no_pbuf is no per i/f, it's per BE card */ |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 459 | stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 460 | drvs->rx_input_fifo_overflow_drop + |
| 461 | drvs->rx_drops_no_pbuf; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 462 | return stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 465 | void be_link_status_update(struct be_adapter *adapter, u32 link_status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 466 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 467 | struct net_device *netdev = adapter->netdev; |
| 468 | |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 469 | /* when link status changes, link speed must be re-queried from card */ |
| 470 | adapter->link_speed = -1; |
| 471 | if ((link_status & LINK_STATUS_MASK) == LINK_UP) { |
| 472 | netif_carrier_on(netdev); |
| 473 | dev_info(&adapter->pdev->dev, "%s: Link up\n", netdev->name); |
| 474 | } else { |
| 475 | netif_carrier_off(netdev); |
| 476 | dev_info(&adapter->pdev->dev, "%s: Link down\n", netdev->name); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 477 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 480 | static void be_tx_stats_update(struct be_tx_obj *txo, |
Ajit Khaparde | 91992e4 | 2010-02-19 13:57:12 +0000 | [diff] [blame] | 481 | u32 wrb_cnt, u32 copied, u32 gso_segs, bool stopped) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 482 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 483 | struct be_tx_stats *stats = tx_stats(txo); |
| 484 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 485 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 486 | stats->tx_reqs++; |
| 487 | stats->tx_wrbs += wrb_cnt; |
| 488 | stats->tx_bytes += copied; |
| 489 | stats->tx_pkts += (gso_segs ? gso_segs : 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 490 | if (stopped) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 491 | stats->tx_stops++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 492 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* Determine number of WRB entries needed to xmit data in an skb */ |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 496 | static u32 wrb_cnt_for_skb(struct be_adapter *adapter, struct sk_buff *skb, |
| 497 | bool *dummy) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 498 | { |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 499 | int cnt = (skb->len > skb->data_len); |
| 500 | |
| 501 | cnt += skb_shinfo(skb)->nr_frags; |
| 502 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 503 | /* to account for hdr wrb */ |
| 504 | cnt++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 505 | if (lancer_chip(adapter) || !(cnt & 1)) { |
| 506 | *dummy = false; |
| 507 | } else { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 508 | /* add a dummy to make it an even num */ |
| 509 | cnt++; |
| 510 | *dummy = true; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 511 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 512 | BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT); |
| 513 | return cnt; |
| 514 | } |
| 515 | |
| 516 | static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len) |
| 517 | { |
| 518 | wrb->frag_pa_hi = upper_32_bits(addr); |
| 519 | wrb->frag_pa_lo = addr & 0xFFFFFFFF; |
| 520 | wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK; |
| 521 | } |
| 522 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 523 | static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr, |
| 524 | struct sk_buff *skb, u32 wrb_cnt, u32 len) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 525 | { |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 526 | u8 vlan_prio = 0; |
| 527 | u16 vlan_tag = 0; |
| 528 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 529 | memset(hdr, 0, sizeof(*hdr)); |
| 530 | |
| 531 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1); |
| 532 | |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 533 | if (skb_is_gso(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 534 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1); |
| 535 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss, |
| 536 | hdr, skb_shinfo(skb)->gso_size); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 537 | if (skb_is_gso_v6(skb) && !lancer_chip(adapter)) |
Ajit Khaparde | 49e4b847 | 2010-06-14 04:56:07 +0000 | [diff] [blame] | 538 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso6, hdr, 1); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 539 | if (lancer_chip(adapter) && adapter->sli_family == |
| 540 | LANCER_A0_SLI_FAMILY) { |
| 541 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, ipcs, hdr, 1); |
| 542 | if (is_tcp_pkt(skb)) |
| 543 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, |
| 544 | tcpcs, hdr, 1); |
| 545 | else if (is_udp_pkt(skb)) |
| 546 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, |
| 547 | udpcs, hdr, 1); |
| 548 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 549 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 550 | if (is_tcp_pkt(skb)) |
| 551 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1); |
| 552 | else if (is_udp_pkt(skb)) |
| 553 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1); |
| 554 | } |
| 555 | |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 556 | if (vlan_tx_tag_present(skb)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 557 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 558 | vlan_tag = vlan_tx_tag_get(skb); |
| 559 | vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 560 | /* If vlan priority provided by OS is NOT in available bmap */ |
| 561 | if (!(adapter->vlan_prio_bmap & (1 << vlan_prio))) |
| 562 | vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) | |
| 563 | adapter->recommended_prio; |
| 564 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag, hdr, vlan_tag); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1); |
| 568 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, 1); |
| 569 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt); |
| 570 | AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len); |
| 571 | } |
| 572 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 573 | static void unmap_tx_frag(struct device *dev, struct be_eth_wrb *wrb, |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 574 | bool unmap_single) |
| 575 | { |
| 576 | dma_addr_t dma; |
| 577 | |
| 578 | be_dws_le_to_cpu(wrb, sizeof(*wrb)); |
| 579 | |
| 580 | dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo; |
FUJITA Tomonori | b681ee7 | 2010-04-04 21:40:18 +0000 | [diff] [blame] | 581 | if (wrb->frag_len) { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 582 | if (unmap_single) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 583 | dma_unmap_single(dev, dma, wrb->frag_len, |
| 584 | DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 585 | else |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 586 | dma_unmap_page(dev, dma, wrb->frag_len, DMA_TO_DEVICE); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 587 | } |
| 588 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 589 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 590 | static int make_tx_wrbs(struct be_adapter *adapter, struct be_queue_info *txq, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 591 | struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb) |
| 592 | { |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 593 | dma_addr_t busaddr; |
| 594 | int i, copied = 0; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 595 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 596 | struct sk_buff *first_skb = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 597 | struct be_eth_wrb *wrb; |
| 598 | struct be_eth_hdr_wrb *hdr; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 599 | bool map_single = false; |
| 600 | u16 map_head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 601 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 602 | hdr = queue_head_node(txq); |
| 603 | queue_head_inc(txq); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 604 | map_head = txq->head; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 605 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 606 | if (skb->len > skb->data_len) { |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 607 | int len = skb_headlen(skb); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 608 | busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE); |
| 609 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 610 | goto dma_err; |
| 611 | map_single = true; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 612 | wrb = queue_head_node(txq); |
| 613 | wrb_fill(wrb, busaddr, len); |
| 614 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 615 | queue_head_inc(txq); |
| 616 | copied += len; |
| 617 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 618 | |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 619 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 620 | struct skb_frag_struct *frag = |
| 621 | &skb_shinfo(skb)->frags[i]; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 622 | busaddr = dma_map_page(dev, frag->page, frag->page_offset, |
| 623 | frag->size, DMA_TO_DEVICE); |
| 624 | if (dma_mapping_error(dev, busaddr)) |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 625 | goto dma_err; |
David S. Miller | ebc8d2a | 2009-06-09 01:01:31 -0700 | [diff] [blame] | 626 | wrb = queue_head_node(txq); |
| 627 | wrb_fill(wrb, busaddr, frag->size); |
| 628 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 629 | queue_head_inc(txq); |
| 630 | copied += frag->size; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | if (dummy_wrb) { |
| 634 | wrb = queue_head_node(txq); |
| 635 | wrb_fill(wrb, 0, 0); |
| 636 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 637 | queue_head_inc(txq); |
| 638 | } |
| 639 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 640 | wrb_fill_hdr(adapter, hdr, first_skb, wrb_cnt, copied); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 641 | be_dws_cpu_to_le(hdr, sizeof(*hdr)); |
| 642 | |
| 643 | return copied; |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 644 | dma_err: |
| 645 | txq->head = map_head; |
| 646 | while (copied) { |
| 647 | wrb = queue_head_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 648 | unmap_tx_frag(dev, wrb, map_single); |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 649 | map_single = false; |
| 650 | copied -= wrb->frag_len; |
| 651 | queue_head_inc(txq); |
| 652 | } |
| 653 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 656 | static netdev_tx_t be_xmit(struct sk_buff *skb, |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 657 | struct net_device *netdev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 658 | { |
| 659 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 660 | struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)]; |
| 661 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 662 | u32 wrb_cnt = 0, copied = 0; |
| 663 | u32 start = txq->head; |
| 664 | bool dummy_wrb, stopped = false; |
| 665 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 666 | wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 667 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 668 | copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 669 | if (copied) { |
| 670 | /* record the sent skb in the sent_skb table */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 671 | BUG_ON(txo->sent_skb_list[start]); |
| 672 | txo->sent_skb_list[start] = skb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 673 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 674 | /* Ensure txq has space for the next skb; Else stop the queue |
| 675 | * *BEFORE* ringing the tx doorbell, so that we serialze the |
| 676 | * tx compls of the current transmit which'll wake up the queue |
| 677 | */ |
Sathya Perla | 7101e11 | 2010-03-22 20:41:12 +0000 | [diff] [blame] | 678 | atomic_add(wrb_cnt, &txq->used); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 679 | if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >= |
| 680 | txq->len) { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 681 | netif_stop_subqueue(netdev, skb_get_queue_mapping(skb)); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 682 | stopped = true; |
| 683 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 684 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 685 | be_txq_notify(adapter, txq->id, wrb_cnt); |
| 686 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 687 | be_tx_stats_update(txo, wrb_cnt, copied, |
Ajit Khaparde | 91992e4 | 2010-02-19 13:57:12 +0000 | [diff] [blame] | 688 | skb_shinfo(skb)->gso_segs, stopped); |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 689 | } else { |
| 690 | txq->head = start; |
| 691 | dev_kfree_skb_any(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 692 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 693 | return NETDEV_TX_OK; |
| 694 | } |
| 695 | |
| 696 | static int be_change_mtu(struct net_device *netdev, int new_mtu) |
| 697 | { |
| 698 | struct be_adapter *adapter = netdev_priv(netdev); |
| 699 | if (new_mtu < BE_MIN_MTU || |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 700 | new_mtu > (BE_MAX_JUMBO_FRAME_SIZE - |
| 701 | (ETH_HLEN + ETH_FCS_LEN))) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 702 | dev_info(&adapter->pdev->dev, |
| 703 | "MTU must be between %d and %d bytes\n", |
Ajit Khaparde | 34a89b8 | 2010-02-09 01:32:43 +0000 | [diff] [blame] | 704 | BE_MIN_MTU, |
| 705 | (BE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN))); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | } |
| 708 | dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n", |
| 709 | netdev->mtu, new_mtu); |
| 710 | netdev->mtu = new_mtu; |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | /* |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 715 | * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE. |
| 716 | * If the user configures more, place BE in vlan promiscuous mode. |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 717 | */ |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 718 | static int be_vid_config(struct be_adapter *adapter, bool vf, u32 vf_num) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 719 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 720 | u16 vtag[BE_NUM_VLANS_SUPPORTED]; |
| 721 | u16 ntags = 0, i; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 722 | int status = 0; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 723 | u32 if_handle; |
| 724 | |
| 725 | if (vf) { |
| 726 | if_handle = adapter->vf_cfg[vf_num].vf_if_handle; |
| 727 | vtag[0] = cpu_to_le16(adapter->vf_cfg[vf_num].vf_vlan_tag); |
| 728 | status = be_cmd_vlan_config(adapter, if_handle, vtag, 1, 1, 0); |
| 729 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 730 | |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 731 | /* No need to further configure vids if in promiscuous mode */ |
| 732 | if (adapter->promiscuous) |
| 733 | return 0; |
| 734 | |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 735 | if (adapter->vlans_added <= adapter->max_vlans) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 736 | /* Construct VLAN Table to give to HW */ |
Jesse Gross | b738127 | 2010-10-20 13:56:02 +0000 | [diff] [blame] | 737 | for (i = 0; i < VLAN_N_VID; i++) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 738 | if (adapter->vlan_tag[i]) { |
| 739 | vtag[ntags] = cpu_to_le16(i); |
| 740 | ntags++; |
| 741 | } |
| 742 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 743 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 744 | vtag, ntags, 1, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 745 | } else { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 746 | status = be_cmd_vlan_config(adapter, adapter->if_handle, |
| 747 | NULL, 0, 1, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 748 | } |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 749 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 750 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 753 | static void be_vlan_add_vid(struct net_device *netdev, u16 vid) |
| 754 | { |
| 755 | struct be_adapter *adapter = netdev_priv(netdev); |
| 756 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 757 | adapter->vlans_added++; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 758 | if (!be_physfn(adapter)) |
| 759 | return; |
| 760 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 761 | adapter->vlan_tag[vid] = 1; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 762 | if (adapter->vlans_added <= (adapter->max_vlans + 1)) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 763 | be_vid_config(adapter, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void be_vlan_rem_vid(struct net_device *netdev, u16 vid) |
| 767 | { |
| 768 | struct be_adapter *adapter = netdev_priv(netdev); |
| 769 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 770 | adapter->vlans_added--; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 771 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 772 | if (!be_physfn(adapter)) |
| 773 | return; |
| 774 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 775 | adapter->vlan_tag[vid] = 0; |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 776 | if (adapter->vlans_added <= adapter->max_vlans) |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 777 | be_vid_config(adapter, false, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 780 | static void be_set_multicast_list(struct net_device *netdev) |
| 781 | { |
| 782 | struct be_adapter *adapter = netdev_priv(netdev); |
| 783 | |
| 784 | if (netdev->flags & IFF_PROMISC) { |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 785 | be_cmd_rx_filter(adapter, IFF_PROMISC, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 786 | adapter->promiscuous = true; |
| 787 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 788 | } |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 789 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 790 | /* BE was previously in promiscuous mode; disable it */ |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 791 | if (adapter->promiscuous) { |
| 792 | adapter->promiscuous = false; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 793 | be_cmd_rx_filter(adapter, IFF_PROMISC, OFF); |
Sathya Perla | c0e64ef | 2011-08-02 19:57:43 +0000 | [diff] [blame] | 794 | |
| 795 | if (adapter->vlans_added) |
| 796 | be_vid_config(adapter, false, 0); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 799 | /* Enable multicast promisc if num configured exceeds what we support */ |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 800 | if (netdev->flags & IFF_ALLMULTI || |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 801 | netdev_mc_count(netdev) > BE_MAX_MC) { |
| 802 | be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 803 | goto done; |
| 804 | } |
| 805 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 806 | be_cmd_rx_filter(adapter, IFF_MULTICAST, ON); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 807 | done: |
| 808 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 811 | static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 812 | { |
| 813 | struct be_adapter *adapter = netdev_priv(netdev); |
| 814 | int status; |
| 815 | |
| 816 | if (!adapter->sriov_enabled) |
| 817 | return -EPERM; |
| 818 | |
| 819 | if (!is_valid_ether_addr(mac) || (vf >= num_vfs)) |
| 820 | return -EINVAL; |
| 821 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 822 | if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID) |
| 823 | status = be_cmd_pmac_del(adapter, |
| 824 | adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 825 | adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 826 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 827 | status = be_cmd_pmac_add(adapter, mac, |
| 828 | adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 829 | &adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 830 | |
| 831 | if (status) |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 832 | dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n", |
| 833 | mac, vf); |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 834 | else |
| 835 | memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN); |
| 836 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 837 | return status; |
| 838 | } |
| 839 | |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 840 | static int be_get_vf_config(struct net_device *netdev, int vf, |
| 841 | struct ifla_vf_info *vi) |
| 842 | { |
| 843 | struct be_adapter *adapter = netdev_priv(netdev); |
| 844 | |
| 845 | if (!adapter->sriov_enabled) |
| 846 | return -EPERM; |
| 847 | |
| 848 | if (vf >= num_vfs) |
| 849 | return -EINVAL; |
| 850 | |
| 851 | vi->vf = vf; |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 852 | vi->tx_rate = adapter->vf_cfg[vf].vf_tx_rate; |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 853 | vi->vlan = adapter->vf_cfg[vf].vf_vlan_tag; |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 854 | vi->qos = 0; |
| 855 | memcpy(&vi->mac, adapter->vf_cfg[vf].vf_mac_addr, ETH_ALEN); |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 860 | static int be_set_vf_vlan(struct net_device *netdev, |
| 861 | int vf, u16 vlan, u8 qos) |
| 862 | { |
| 863 | struct be_adapter *adapter = netdev_priv(netdev); |
| 864 | int status = 0; |
| 865 | |
| 866 | if (!adapter->sriov_enabled) |
| 867 | return -EPERM; |
| 868 | |
| 869 | if ((vf >= num_vfs) || (vlan > 4095)) |
| 870 | return -EINVAL; |
| 871 | |
| 872 | if (vlan) { |
| 873 | adapter->vf_cfg[vf].vf_vlan_tag = vlan; |
| 874 | adapter->vlans_added++; |
| 875 | } else { |
| 876 | adapter->vf_cfg[vf].vf_vlan_tag = 0; |
| 877 | adapter->vlans_added--; |
| 878 | } |
| 879 | |
| 880 | status = be_vid_config(adapter, true, vf); |
| 881 | |
| 882 | if (status) |
| 883 | dev_info(&adapter->pdev->dev, |
| 884 | "VLAN %d config on VF %d failed\n", vlan, vf); |
| 885 | return status; |
| 886 | } |
| 887 | |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 888 | static int be_set_vf_tx_rate(struct net_device *netdev, |
| 889 | int vf, int rate) |
| 890 | { |
| 891 | struct be_adapter *adapter = netdev_priv(netdev); |
| 892 | int status = 0; |
| 893 | |
| 894 | if (!adapter->sriov_enabled) |
| 895 | return -EPERM; |
| 896 | |
| 897 | if ((vf >= num_vfs) || (rate < 0)) |
| 898 | return -EINVAL; |
| 899 | |
| 900 | if (rate > 10000) |
| 901 | rate = 10000; |
| 902 | |
| 903 | adapter->vf_cfg[vf].vf_tx_rate = rate; |
Ajit Khaparde | 856c401 | 2011-02-11 13:32:32 +0000 | [diff] [blame] | 904 | status = be_cmd_set_qos(adapter, rate / 10, vf + 1); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 905 | |
| 906 | if (status) |
| 907 | dev_info(&adapter->pdev->dev, |
| 908 | "tx rate %d on VF %d failed\n", rate, vf); |
| 909 | return status; |
| 910 | } |
| 911 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 912 | static void be_rx_eqd_update(struct be_adapter *adapter, struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 913 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 914 | struct be_eq_obj *rx_eq = &rxo->rx_eq; |
| 915 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 916 | ulong now = jiffies; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 917 | ulong delta = now - stats->rx_jiffies; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 918 | u64 pkts; |
| 919 | unsigned int start, eqd; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 920 | |
| 921 | if (!rx_eq->enable_aic) |
| 922 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 923 | |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 924 | /* Wrapped around */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 925 | if (time_before(now, stats->rx_jiffies)) { |
| 926 | stats->rx_jiffies = now; |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 927 | return; |
| 928 | } |
| 929 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 930 | /* Update once a second */ |
| 931 | if (delta < HZ) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 932 | return; |
| 933 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 934 | do { |
| 935 | start = u64_stats_fetch_begin_bh(&stats->sync); |
| 936 | pkts = stats->rx_pkts; |
| 937 | } while (u64_stats_fetch_retry_bh(&stats->sync, start)); |
| 938 | |
Eric Dumazet | 68c3e5a | 2011-08-09 06:23:07 +0000 | [diff] [blame] | 939 | stats->rx_pps = (unsigned long)(pkts - stats->rx_pkts_prev) / (delta / HZ); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 940 | stats->rx_pkts_prev = pkts; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 941 | stats->rx_jiffies = now; |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 942 | eqd = stats->rx_pps / 110000; |
| 943 | eqd = eqd << 3; |
| 944 | if (eqd > rx_eq->max_eqd) |
| 945 | eqd = rx_eq->max_eqd; |
| 946 | if (eqd < rx_eq->min_eqd) |
| 947 | eqd = rx_eq->min_eqd; |
| 948 | if (eqd < 10) |
| 949 | eqd = 0; |
| 950 | if (eqd != rx_eq->cur_eqd) { |
| 951 | be_cmd_modify_eqd(adapter, rx_eq->q.id, eqd); |
| 952 | rx_eq->cur_eqd = eqd; |
| 953 | } |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 956 | static void be_rx_stats_update(struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 957 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 958 | { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 959 | struct be_rx_stats *stats = rx_stats(rxo); |
Sathya Perla | 4097f66 | 2009-03-24 16:40:13 -0700 | [diff] [blame] | 960 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 961 | u64_stats_update_begin(&stats->sync); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 962 | stats->rx_compl++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 963 | stats->rx_bytes += rxcp->pkt_size; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 964 | stats->rx_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 965 | if (rxcp->pkt_type == BE_MULTICAST_PACKET) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 966 | stats->rx_mcast_pkts++; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 967 | if (rxcp->err) |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 968 | stats->rx_compl_err++; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 969 | u64_stats_update_end(&stats->sync); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 972 | static inline bool csum_passed(struct be_rx_compl_info *rxcp) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 973 | { |
Padmanabh Ratnakar | 19fad86 | 2011-03-07 03:08:16 +0000 | [diff] [blame] | 974 | /* L4 checksum is not reliable for non TCP/UDP packets. |
| 975 | * Also ignore ipcksm for ipv6 pkts */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 976 | return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum && |
| 977 | (rxcp->ip_csum || rxcp->ipv6); |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 980 | static struct be_rx_page_info * |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 981 | get_rx_page_info(struct be_adapter *adapter, |
| 982 | struct be_rx_obj *rxo, |
| 983 | u16 frag_idx) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 984 | { |
| 985 | struct be_rx_page_info *rx_page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 986 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 987 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 988 | rx_page_info = &rxo->page_info_tbl[frag_idx]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 989 | BUG_ON(!rx_page_info->page); |
| 990 | |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 991 | if (rx_page_info->last_page_user) { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 992 | dma_unmap_page(&adapter->pdev->dev, |
| 993 | dma_unmap_addr(rx_page_info, bus), |
| 994 | adapter->big_page_size, DMA_FROM_DEVICE); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 995 | rx_page_info->last_page_user = false; |
| 996 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 997 | |
| 998 | atomic_dec(&rxq->used); |
| 999 | return rx_page_info; |
| 1000 | } |
| 1001 | |
| 1002 | /* Throwaway the data in the Rx completion */ |
| 1003 | static void be_rx_compl_discard(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1004 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1005 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1006 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1007 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1008 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1009 | u16 i, num_rcvd = rxcp->num_rcvd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1010 | |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1011 | for (i = 0; i < num_rcvd; i++) { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1012 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Padmanabh Ratnakar | e80d9da | 2011-03-07 03:07:58 +0000 | [diff] [blame] | 1013 | put_page(page_info->page); |
| 1014 | memset(page_info, 0, sizeof(*page_info)); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1015 | index_inc(&rxcp->rxq_idx, rxq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /* |
| 1020 | * skb_fill_rx_data forms a complete skb for an ether frame |
| 1021 | * indicated by rxcp. |
| 1022 | */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1023 | static void skb_fill_rx_data(struct be_adapter *adapter, struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1024 | struct sk_buff *skb, struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1025 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1026 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1027 | struct be_rx_page_info *page_info; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1028 | u16 i, j; |
| 1029 | u16 hdr_len, curr_frag_len, remaining; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1030 | u8 *start; |
| 1031 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1032 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1033 | start = page_address(page_info->page) + page_info->page_offset; |
| 1034 | prefetch(start); |
| 1035 | |
| 1036 | /* Copy data in the first descriptor of this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1037 | curr_frag_len = min(rxcp->pkt_size, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1038 | |
| 1039 | /* Copy the header portion into skb_data */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1040 | hdr_len = min(BE_HDR_LEN, curr_frag_len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1041 | memcpy(skb->data, start, hdr_len); |
| 1042 | skb->len = curr_frag_len; |
| 1043 | if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */ |
| 1044 | /* Complete packet has now been moved to data */ |
| 1045 | put_page(page_info->page); |
| 1046 | skb->data_len = 0; |
| 1047 | skb->tail += curr_frag_len; |
| 1048 | } else { |
| 1049 | skb_shinfo(skb)->nr_frags = 1; |
| 1050 | skb_shinfo(skb)->frags[0].page = page_info->page; |
| 1051 | skb_shinfo(skb)->frags[0].page_offset = |
| 1052 | page_info->page_offset + hdr_len; |
| 1053 | skb_shinfo(skb)->frags[0].size = curr_frag_len - hdr_len; |
| 1054 | skb->data_len = curr_frag_len - hdr_len; |
| 1055 | skb->tail += hdr_len; |
| 1056 | } |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1057 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1058 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1059 | if (rxcp->pkt_size <= rx_frag_size) { |
| 1060 | BUG_ON(rxcp->num_rcvd != 1); |
| 1061 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /* More frags present for this completion */ |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1065 | index_inc(&rxcp->rxq_idx, rxq->len); |
| 1066 | remaining = rxcp->pkt_size - curr_frag_len; |
| 1067 | for (i = 1, j = 0; i < rxcp->num_rcvd; i++) { |
| 1068 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
| 1069 | curr_frag_len = min(remaining, rx_frag_size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1070 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1071 | /* Coalesce all frags from the same physical page in one slot */ |
| 1072 | if (page_info->page_offset == 0) { |
| 1073 | /* Fresh page */ |
| 1074 | j++; |
| 1075 | skb_shinfo(skb)->frags[j].page = page_info->page; |
| 1076 | skb_shinfo(skb)->frags[j].page_offset = |
| 1077 | page_info->page_offset; |
| 1078 | skb_shinfo(skb)->frags[j].size = 0; |
| 1079 | skb_shinfo(skb)->nr_frags++; |
| 1080 | } else { |
| 1081 | put_page(page_info->page); |
| 1082 | } |
| 1083 | |
| 1084 | skb_shinfo(skb)->frags[j].size += curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1085 | skb->len += curr_frag_len; |
| 1086 | skb->data_len += curr_frag_len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1087 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1088 | remaining -= curr_frag_len; |
| 1089 | index_inc(&rxcp->rxq_idx, rxq->len); |
Ajit Khaparde | 205859a | 2010-02-09 01:34:21 +0000 | [diff] [blame] | 1090 | page_info->page = NULL; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1091 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1092 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1095 | /* Process the RX completion indicated by rxcp when GRO is disabled */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1096 | static void be_rx_compl_process(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1097 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1098 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1099 | { |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1100 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1101 | struct sk_buff *skb; |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1102 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1103 | skb = netdev_alloc_skb_ip_align(netdev, BE_HDR_LEN); |
Sathya Perla | a058a63 | 2010-02-17 01:34:22 +0000 | [diff] [blame] | 1104 | if (unlikely(!skb)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1105 | rx_stats(rxo)->rx_drops_no_skbs++; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1106 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1107 | return; |
| 1108 | } |
| 1109 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1110 | skb_fill_rx_data(adapter, rxo, skb, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1111 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1112 | if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp))) |
Ajit Khaparde | 728a997 | 2009-04-13 15:41:22 -0700 | [diff] [blame] | 1113 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Somnath Kotur | c6ce2f4 | 2010-10-25 01:11:58 +0000 | [diff] [blame] | 1114 | else |
| 1115 | skb_checksum_none_assert(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1116 | |
| 1117 | skb->truesize = skb->len + sizeof(struct sk_buff); |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 1118 | skb->protocol = eth_type_trans(skb, netdev); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1119 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1120 | skb->rxhash = rxcp->rss_hash; |
| 1121 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1122 | |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1123 | if (unlikely(rxcp->vlanf)) |
| 1124 | __vlan_hwaccel_put_tag(skb, rxcp->vlan_tag); |
| 1125 | |
| 1126 | netif_receive_skb(skb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1129 | /* Process the RX completion indicated by rxcp when GRO is enabled */ |
| 1130 | static void be_rx_compl_process_gro(struct be_adapter *adapter, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1131 | struct be_rx_obj *rxo, |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1132 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1133 | { |
| 1134 | struct be_rx_page_info *page_info; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1135 | struct sk_buff *skb = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1136 | struct be_queue_info *rxq = &rxo->q; |
| 1137 | struct be_eq_obj *eq_obj = &rxo->rx_eq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1138 | u16 remaining, curr_frag_len; |
| 1139 | u16 i, j; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 1140 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1141 | skb = napi_get_frags(&eq_obj->napi); |
| 1142 | if (!skb) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1143 | be_rx_compl_discard(adapter, rxo, rxcp); |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1144 | return; |
| 1145 | } |
| 1146 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1147 | remaining = rxcp->pkt_size; |
| 1148 | for (i = 0, j = -1; i < rxcp->num_rcvd; i++) { |
| 1149 | page_info = get_rx_page_info(adapter, rxo, rxcp->rxq_idx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1150 | |
| 1151 | curr_frag_len = min(remaining, rx_frag_size); |
| 1152 | |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1153 | /* Coalesce all frags from the same physical page in one slot */ |
| 1154 | if (i == 0 || page_info->page_offset == 0) { |
| 1155 | /* First frag or Fresh page */ |
| 1156 | j++; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1157 | skb_shinfo(skb)->frags[j].page = page_info->page; |
| 1158 | skb_shinfo(skb)->frags[j].page_offset = |
| 1159 | page_info->page_offset; |
| 1160 | skb_shinfo(skb)->frags[j].size = 0; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1161 | } else { |
| 1162 | put_page(page_info->page); |
| 1163 | } |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1164 | skb_shinfo(skb)->frags[j].size += curr_frag_len; |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1165 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1166 | remaining -= curr_frag_len; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1167 | index_inc(&rxcp->rxq_idx, rxq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1168 | memset(page_info, 0, sizeof(*page_info)); |
| 1169 | } |
Ajit Khaparde | bd46cb6 | 2009-06-26 02:51:07 +0000 | [diff] [blame] | 1170 | BUG_ON(j > MAX_SKB_FRAGS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1171 | |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1172 | skb_shinfo(skb)->nr_frags = j + 1; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1173 | skb->len = rxcp->pkt_size; |
| 1174 | skb->data_len = rxcp->pkt_size; |
| 1175 | skb->truesize += rxcp->pkt_size; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1176 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1177 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1178 | skb->rxhash = rxcp->rss_hash; |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 1179 | |
Ajit Khaparde | 4c5102f | 2011-07-12 22:10:01 -0700 | [diff] [blame] | 1180 | if (unlikely(rxcp->vlanf)) |
| 1181 | __vlan_hwaccel_put_tag(skb, rxcp->vlan_tag); |
| 1182 | |
| 1183 | napi_gro_frags(&eq_obj->napi); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1186 | static void be_parse_rx_compl_v1(struct be_adapter *adapter, |
| 1187 | struct be_eth_rx_compl *compl, |
| 1188 | struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1189 | { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1190 | rxcp->pkt_size = |
| 1191 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, pktsize, compl); |
| 1192 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtp, compl); |
| 1193 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, err, compl); |
| 1194 | rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, tcpf, compl); |
Padmanabh Ratnakar | 9ecb42f | 2011-03-15 14:57:09 -0700 | [diff] [blame] | 1195 | rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, udpf, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1196 | rxcp->ip_csum = |
| 1197 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ipcksm, compl); |
| 1198 | rxcp->l4_csum = |
| 1199 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, l4_cksm, compl); |
| 1200 | rxcp->ipv6 = |
| 1201 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ip_version, compl); |
| 1202 | rxcp->rxq_idx = |
| 1203 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, fragndx, compl); |
| 1204 | rxcp->num_rcvd = |
| 1205 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, numfrags, compl); |
| 1206 | rxcp->pkt_type = |
| 1207 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1208 | rxcp->rss_hash = |
| 1209 | AMAP_GET_BITS(struct amap_eth_rx_compl_v1, rsshash, rxcp); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1210 | if (rxcp->vlanf) { |
| 1211 | rxcp->vtm = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtm, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1212 | compl); |
| 1213 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vlan_tag, |
| 1214 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1215 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1216 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, port, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1217 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1218 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1219 | static void be_parse_rx_compl_v0(struct be_adapter *adapter, |
| 1220 | struct be_eth_rx_compl *compl, |
| 1221 | struct be_rx_compl_info *rxcp) |
| 1222 | { |
| 1223 | rxcp->pkt_size = |
| 1224 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, pktsize, compl); |
| 1225 | rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtp, compl); |
| 1226 | rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, err, compl); |
| 1227 | rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, tcpf, compl); |
Padmanabh Ratnakar | 9ecb42f | 2011-03-15 14:57:09 -0700 | [diff] [blame] | 1228 | rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, udpf, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1229 | rxcp->ip_csum = |
| 1230 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ipcksm, compl); |
| 1231 | rxcp->l4_csum = |
| 1232 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, l4_cksm, compl); |
| 1233 | rxcp->ipv6 = |
| 1234 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ip_version, compl); |
| 1235 | rxcp->rxq_idx = |
| 1236 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, fragndx, compl); |
| 1237 | rxcp->num_rcvd = |
| 1238 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, numfrags, compl); |
| 1239 | rxcp->pkt_type = |
| 1240 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, cast_enc, compl); |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 1241 | rxcp->rss_hash = |
| 1242 | AMAP_GET_BITS(struct amap_eth_rx_compl_v0, rsshash, rxcp); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1243 | if (rxcp->vlanf) { |
| 1244 | rxcp->vtm = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtm, |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1245 | compl); |
| 1246 | rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vlan_tag, |
| 1247 | compl); |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1248 | } |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1249 | rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, port, compl); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo) |
| 1253 | { |
| 1254 | struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq); |
| 1255 | struct be_rx_compl_info *rxcp = &rxo->rxcp; |
| 1256 | struct be_adapter *adapter = rxo->adapter; |
| 1257 | |
| 1258 | /* For checking the valid bit it is Ok to use either definition as the |
| 1259 | * valid bit is at the same position in both v0 and v1 Rx compl */ |
| 1260 | if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] == 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1261 | return NULL; |
| 1262 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1263 | rmb(); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1264 | be_dws_le_to_cpu(compl, sizeof(*compl)); |
| 1265 | |
| 1266 | if (adapter->be3_native) |
| 1267 | be_parse_rx_compl_v1(adapter, compl, rxcp); |
| 1268 | else |
| 1269 | be_parse_rx_compl_v0(adapter, compl, rxcp); |
| 1270 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1271 | if (rxcp->vlanf) { |
| 1272 | /* vlanf could be wrongly set in some cards. |
| 1273 | * ignore if vtm is not set */ |
| 1274 | if ((adapter->function_mode & 0x400) && !rxcp->vtm) |
| 1275 | rxcp->vlanf = 0; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1276 | |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1277 | if (!lancer_chip(adapter)) |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1278 | rxcp->vlan_tag = swab16(rxcp->vlan_tag); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1279 | |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 1280 | if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) && |
David S. Miller | 3c709f8 | 2011-05-11 14:26:15 -0400 | [diff] [blame] | 1281 | !adapter->vlan_tag[rxcp->vlan_tag]) |
Sathya Perla | 15d7218 | 2011-03-21 20:49:26 +0000 | [diff] [blame] | 1282 | rxcp->vlanf = 0; |
| 1283 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1284 | |
| 1285 | /* As the compl has been parsed, reset it; we wont touch it again */ |
| 1286 | compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1287 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1288 | queue_tail_inc(&rxo->cq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1289 | return rxcp; |
| 1290 | } |
| 1291 | |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1292 | static inline struct page *be_alloc_pages(u32 size, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1293 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1294 | u32 order = get_order(size); |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1295 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1296 | if (order > 0) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1297 | gfp |= __GFP_COMP; |
| 1298 | return alloc_pages(gfp, order); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /* |
| 1302 | * Allocate a page, split it to fragments of size rx_frag_size and post as |
| 1303 | * receive buffers to BE |
| 1304 | */ |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1305 | static void be_post_rx_frags(struct be_rx_obj *rxo, gfp_t gfp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1306 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1307 | struct be_adapter *adapter = rxo->adapter; |
| 1308 | struct be_rx_page_info *page_info_tbl = rxo->page_info_tbl; |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1309 | struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1310 | struct be_queue_info *rxq = &rxo->q; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1311 | struct page *pagep = NULL; |
| 1312 | struct be_eth_rx_d *rxd; |
| 1313 | u64 page_dmaaddr = 0, frag_dmaaddr; |
| 1314 | u32 posted, page_offset = 0; |
| 1315 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1316 | page_info = &rxo->page_info_tbl[rxq->head]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1317 | for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) { |
| 1318 | if (!pagep) { |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1319 | pagep = be_alloc_pages(adapter->big_page_size, gfp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1320 | if (unlikely(!pagep)) { |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1321 | rx_stats(rxo)->rx_post_fail++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1322 | break; |
| 1323 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1324 | page_dmaaddr = dma_map_page(&adapter->pdev->dev, pagep, |
| 1325 | 0, adapter->big_page_size, |
| 1326 | DMA_FROM_DEVICE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1327 | page_info->page_offset = 0; |
| 1328 | } else { |
| 1329 | get_page(pagep); |
| 1330 | page_info->page_offset = page_offset + rx_frag_size; |
| 1331 | } |
| 1332 | page_offset = page_info->page_offset; |
| 1333 | page_info->page = pagep; |
FUJITA Tomonori | fac6da5 | 2010-04-01 16:53:22 +0000 | [diff] [blame] | 1334 | dma_unmap_addr_set(page_info, bus, page_dmaaddr); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1335 | frag_dmaaddr = page_dmaaddr + page_info->page_offset; |
| 1336 | |
| 1337 | rxd = queue_head_node(rxq); |
| 1338 | rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF); |
| 1339 | rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1340 | |
| 1341 | /* Any space left in the current big page for another frag? */ |
| 1342 | if ((page_offset + rx_frag_size + rx_frag_size) > |
| 1343 | adapter->big_page_size) { |
| 1344 | pagep = NULL; |
| 1345 | page_info->last_page_user = true; |
| 1346 | } |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1347 | |
| 1348 | prev_page_info = page_info; |
| 1349 | queue_head_inc(rxq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1350 | page_info = &page_info_tbl[rxq->head]; |
| 1351 | } |
| 1352 | if (pagep) |
Sathya Perla | 26d92f9 | 2010-01-21 22:52:08 -0800 | [diff] [blame] | 1353 | prev_page_info->last_page_user = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1354 | |
| 1355 | if (posted) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1356 | atomic_add(posted, &rxq->used); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1357 | be_rxq_notify(adapter, rxq->id, posted); |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1358 | } else if (atomic_read(&rxq->used) == 0) { |
| 1359 | /* Let be_worker replenish when memory is available */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1360 | rxo->rx_post_starved = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1361 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1364 | 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] | 1365 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1366 | struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq); |
| 1367 | |
| 1368 | if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0) |
| 1369 | return NULL; |
| 1370 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1371 | rmb(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1372 | be_dws_le_to_cpu(txcp, sizeof(*txcp)); |
| 1373 | |
| 1374 | txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0; |
| 1375 | |
| 1376 | queue_tail_inc(tx_cq); |
| 1377 | return txcp; |
| 1378 | } |
| 1379 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1380 | static u16 be_tx_compl_process(struct be_adapter *adapter, |
| 1381 | struct be_tx_obj *txo, u16 last_index) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1382 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1383 | struct be_queue_info *txq = &txo->q; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1384 | struct be_eth_wrb *wrb; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1385 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1386 | struct sk_buff *sent_skb; |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1387 | u16 cur_index, num_wrbs = 1; /* account for hdr wrb */ |
| 1388 | bool unmap_skb_hdr = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1389 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1390 | sent_skb = sent_skbs[txq->tail]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1391 | BUG_ON(!sent_skb); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1392 | sent_skbs[txq->tail] = NULL; |
| 1393 | |
| 1394 | /* skip header wrb */ |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1395 | queue_tail_inc(txq); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1396 | |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1397 | do { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1398 | cur_index = txq->tail; |
Alexander Duyck | a73b796 | 2009-12-02 16:48:18 +0000 | [diff] [blame] | 1399 | wrb = queue_tail_node(txq); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 1400 | unmap_tx_frag(&adapter->pdev->dev, wrb, |
| 1401 | (unmap_skb_hdr && skb_headlen(sent_skb))); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1402 | unmap_skb_hdr = false; |
| 1403 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1404 | num_wrbs++; |
| 1405 | queue_tail_inc(txq); |
Sathya Perla | ec43b1a | 2010-03-22 20:41:34 +0000 | [diff] [blame] | 1406 | } while (cur_index != last_index); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1407 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1408 | kfree_skb(sent_skb); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1409 | return num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1412 | static inline struct be_eq_entry *event_get(struct be_eq_obj *eq_obj) |
| 1413 | { |
| 1414 | struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q); |
| 1415 | |
| 1416 | if (!eqe->evt) |
| 1417 | return NULL; |
| 1418 | |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 1419 | rmb(); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1420 | eqe->evt = le32_to_cpu(eqe->evt); |
| 1421 | queue_tail_inc(&eq_obj->q); |
| 1422 | return eqe; |
| 1423 | } |
| 1424 | |
| 1425 | static int event_handle(struct be_adapter *adapter, |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1426 | struct be_eq_obj *eq_obj, |
| 1427 | bool rearm) |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1428 | { |
| 1429 | struct be_eq_entry *eqe; |
| 1430 | u16 num = 0; |
| 1431 | |
| 1432 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1433 | eqe->evt = 0; |
| 1434 | num++; |
| 1435 | } |
| 1436 | |
| 1437 | /* Deal with any spurious interrupts that come |
| 1438 | * without events |
| 1439 | */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1440 | if (!num) |
| 1441 | rearm = true; |
| 1442 | |
| 1443 | be_eq_notify(adapter, eq_obj->q.id, rearm, true, num); |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1444 | if (num) |
| 1445 | napi_schedule(&eq_obj->napi); |
| 1446 | |
| 1447 | return num; |
| 1448 | } |
| 1449 | |
| 1450 | /* Just read and notify events without processing them. |
| 1451 | * Used at the time of destroying event queues */ |
| 1452 | static void be_eq_clean(struct be_adapter *adapter, |
| 1453 | struct be_eq_obj *eq_obj) |
| 1454 | { |
| 1455 | struct be_eq_entry *eqe; |
| 1456 | u16 num = 0; |
| 1457 | |
| 1458 | while ((eqe = event_get(eq_obj)) != NULL) { |
| 1459 | eqe->evt = 0; |
| 1460 | num++; |
| 1461 | } |
| 1462 | |
| 1463 | if (num) |
| 1464 | be_eq_notify(adapter, eq_obj->q.id, false, true, num); |
| 1465 | } |
| 1466 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1467 | static void be_rx_q_clean(struct be_adapter *adapter, struct be_rx_obj *rxo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1468 | { |
| 1469 | struct be_rx_page_info *page_info; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1470 | struct be_queue_info *rxq = &rxo->q; |
| 1471 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1472 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1473 | u16 tail; |
| 1474 | |
| 1475 | /* First cleanup pending rx completions */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1476 | while ((rxcp = be_rx_compl_get(rxo)) != NULL) { |
| 1477 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 1478 | be_cq_notify(adapter, rx_cq->id, false, 1); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /* Then free posted rx buffer that were not used */ |
| 1482 | tail = (rxq->head + rxq->len - atomic_read(&rxq->used)) % rxq->len; |
Sathya Perla | cdab23b | 2009-08-10 03:43:23 +0000 | [diff] [blame] | 1483 | for (; atomic_read(&rxq->used) > 0; index_inc(&tail, rxq->len)) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1484 | page_info = get_rx_page_info(adapter, rxo, tail); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1485 | put_page(page_info->page); |
| 1486 | memset(page_info, 0, sizeof(*page_info)); |
| 1487 | } |
| 1488 | BUG_ON(atomic_read(&rxq->used)); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1489 | rxq->tail = rxq->head = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1492 | static void be_tx_compl_clean(struct be_adapter *adapter, |
| 1493 | struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1494 | { |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1495 | struct be_queue_info *tx_cq = &txo->cq; |
| 1496 | struct be_queue_info *txq = &txo->q; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1497 | struct be_eth_tx_compl *txcp; |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1498 | u16 end_idx, cmpl = 0, timeo = 0, num_wrbs = 0; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1499 | struct sk_buff **sent_skbs = txo->sent_skb_list; |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1500 | struct sk_buff *sent_skb; |
| 1501 | bool dummy_wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1502 | |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1503 | /* Wait for a max of 200ms for all the tx-completions to arrive. */ |
| 1504 | do { |
| 1505 | while ((txcp = be_tx_compl_get(tx_cq))) { |
| 1506 | end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1507 | wrb_index, txcp); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1508 | num_wrbs += be_tx_compl_process(adapter, txo, end_idx); |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1509 | cmpl++; |
| 1510 | } |
| 1511 | if (cmpl) { |
| 1512 | be_cq_notify(adapter, tx_cq->id, false, cmpl); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1513 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1514 | cmpl = 0; |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1515 | num_wrbs = 0; |
Sathya Perla | a8e9179 | 2009-08-10 03:42:43 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | if (atomic_read(&txq->used) == 0 || ++timeo > 200) |
| 1519 | break; |
| 1520 | |
| 1521 | mdelay(1); |
| 1522 | } while (true); |
| 1523 | |
| 1524 | if (atomic_read(&txq->used)) |
| 1525 | dev_err(&adapter->pdev->dev, "%d pending tx-completions\n", |
| 1526 | atomic_read(&txq->used)); |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1527 | |
| 1528 | /* free posted tx for which compls will never arrive */ |
| 1529 | while (atomic_read(&txq->used)) { |
| 1530 | sent_skb = sent_skbs[txq->tail]; |
| 1531 | end_idx = txq->tail; |
| 1532 | index_adv(&end_idx, |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1533 | wrb_cnt_for_skb(adapter, sent_skb, &dummy_wrb) - 1, |
| 1534 | txq->len); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1535 | num_wrbs = be_tx_compl_process(adapter, txo, end_idx); |
Padmanabh Ratnakar | 4d586b8 | 2011-05-10 05:13:57 +0000 | [diff] [blame] | 1536 | atomic_sub(num_wrbs, &txq->used); |
Sathya Perla | b03388d | 2010-02-18 00:37:17 +0000 | [diff] [blame] | 1537 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1540 | static void be_mcc_queues_destroy(struct be_adapter *adapter) |
| 1541 | { |
| 1542 | struct be_queue_info *q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1543 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1544 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1545 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1546 | be_cmd_q_destroy(adapter, q, QTYPE_MCCQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1547 | be_queue_free(adapter, q); |
| 1548 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1549 | q = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1550 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1551 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1552 | be_queue_free(adapter, q); |
| 1553 | } |
| 1554 | |
| 1555 | /* Must be called only after TX qs are created as MCC shares TX EQ */ |
| 1556 | static int be_mcc_queues_create(struct be_adapter *adapter) |
| 1557 | { |
| 1558 | struct be_queue_info *q, *cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1559 | |
| 1560 | /* Alloc MCC compl queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1561 | cq = &adapter->mcc_obj.cq; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1562 | if (be_queue_alloc(adapter, cq, MCC_CQ_LEN, |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 1563 | sizeof(struct be_mcc_compl))) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1564 | goto err; |
| 1565 | |
| 1566 | /* Ask BE to create MCC compl queue; share TX's eq */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1567 | 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] | 1568 | goto mcc_cq_free; |
| 1569 | |
| 1570 | /* Alloc MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1571 | q = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1572 | if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 1573 | goto mcc_cq_destroy; |
| 1574 | |
| 1575 | /* Ask BE to create MCC queue */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1576 | if (be_cmd_mccq_create(adapter, q, cq)) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1577 | goto mcc_q_free; |
| 1578 | |
| 1579 | return 0; |
| 1580 | |
| 1581 | mcc_q_free: |
| 1582 | be_queue_free(adapter, q); |
| 1583 | mcc_cq_destroy: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1584 | be_cmd_q_destroy(adapter, cq, QTYPE_CQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1585 | mcc_cq_free: |
| 1586 | be_queue_free(adapter, cq); |
| 1587 | err: |
| 1588 | return -1; |
| 1589 | } |
| 1590 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1591 | static void be_tx_queues_destroy(struct be_adapter *adapter) |
| 1592 | { |
| 1593 | struct be_queue_info *q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1594 | struct be_tx_obj *txo; |
| 1595 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1596 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1597 | for_all_tx_queues(adapter, txo, i) { |
| 1598 | q = &txo->q; |
| 1599 | if (q->created) |
| 1600 | be_cmd_q_destroy(adapter, q, QTYPE_TXQ); |
| 1601 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1602 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1603 | q = &txo->cq; |
| 1604 | if (q->created) |
| 1605 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 1606 | be_queue_free(adapter, q); |
| 1607 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1608 | |
Sathya Perla | 859b1e4 | 2009-08-10 03:43:51 +0000 | [diff] [blame] | 1609 | /* Clear any residual events */ |
| 1610 | be_eq_clean(adapter, &adapter->tx_eq); |
| 1611 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1612 | q = &adapter->tx_eq.q; |
| 1613 | if (q->created) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1614 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1615 | be_queue_free(adapter, q); |
| 1616 | } |
| 1617 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1618 | /* One TX event queue is shared by all TX compl qs */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1619 | static int be_tx_queues_create(struct be_adapter *adapter) |
| 1620 | { |
| 1621 | struct be_queue_info *eq, *q, *cq; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1622 | struct be_tx_obj *txo; |
| 1623 | u8 i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1624 | |
| 1625 | adapter->tx_eq.max_eqd = 0; |
| 1626 | adapter->tx_eq.min_eqd = 0; |
| 1627 | adapter->tx_eq.cur_eqd = 96; |
| 1628 | adapter->tx_eq.enable_aic = false; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1629 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1630 | eq = &adapter->tx_eq.q; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1631 | if (be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 1632 | sizeof(struct be_eq_entry))) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1633 | return -1; |
| 1634 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1635 | if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1636 | goto err; |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1637 | adapter->tx_eq.eq_idx = adapter->eq_next_idx++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1638 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1639 | for_all_tx_queues(adapter, txo, i) { |
| 1640 | cq = &txo->cq; |
| 1641 | if (be_queue_alloc(adapter, cq, TX_CQ_LEN, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1642 | sizeof(struct be_eth_tx_compl))) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1643 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1644 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1645 | if (be_cmd_cq_create(adapter, cq, eq, false, false, 3)) |
| 1646 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1647 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1648 | q = &txo->q; |
| 1649 | if (be_queue_alloc(adapter, q, TX_Q_LEN, |
| 1650 | sizeof(struct be_eth_wrb))) |
| 1651 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1652 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1653 | if (be_cmd_txq_create(adapter, q, cq)) |
| 1654 | goto err; |
| 1655 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1656 | return 0; |
| 1657 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1658 | err: |
| 1659 | be_tx_queues_destroy(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1660 | return -1; |
| 1661 | } |
| 1662 | |
| 1663 | static void be_rx_queues_destroy(struct be_adapter *adapter) |
| 1664 | { |
| 1665 | struct be_queue_info *q; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1666 | struct be_rx_obj *rxo; |
| 1667 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1668 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1669 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1670 | be_queue_free(adapter, &rxo->q); |
Sathya Perla | 8942042 | 2010-02-17 01:35:26 +0000 | [diff] [blame] | 1671 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1672 | q = &rxo->cq; |
| 1673 | if (q->created) |
| 1674 | be_cmd_q_destroy(adapter, q, QTYPE_CQ); |
| 1675 | be_queue_free(adapter, q); |
| 1676 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1677 | q = &rxo->rx_eq.q; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1678 | if (q->created) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1679 | be_cmd_q_destroy(adapter, q, QTYPE_EQ); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1680 | be_queue_free(adapter, q); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1681 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1684 | static u32 be_num_rxqs_want(struct be_adapter *adapter) |
| 1685 | { |
Sathya Perla | c814fd3 | 2011-06-26 20:41:25 +0000 | [diff] [blame] | 1686 | if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) && |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1687 | !adapter->sriov_enabled && !(adapter->function_mode & 0x400)) { |
| 1688 | return 1 + MAX_RSS_QS; /* one default non-RSS queue */ |
| 1689 | } else { |
| 1690 | dev_warn(&adapter->pdev->dev, |
| 1691 | "No support for multiple RX queues\n"); |
| 1692 | return 1; |
| 1693 | } |
| 1694 | } |
| 1695 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1696 | static int be_rx_queues_create(struct be_adapter *adapter) |
| 1697 | { |
| 1698 | struct be_queue_info *eq, *q, *cq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1699 | struct be_rx_obj *rxo; |
| 1700 | int rc, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1701 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 1702 | adapter->num_rx_qs = min(be_num_rxqs_want(adapter), |
| 1703 | msix_enabled(adapter) ? |
| 1704 | adapter->num_msix_vec - 1 : 1); |
| 1705 | if (adapter->num_rx_qs != MAX_RX_QS) |
| 1706 | dev_warn(&adapter->pdev->dev, |
| 1707 | "Can create only %d RX queues", adapter->num_rx_qs); |
| 1708 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1709 | adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1710 | for_all_rx_queues(adapter, rxo, i) { |
| 1711 | rxo->adapter = adapter; |
| 1712 | rxo->rx_eq.max_eqd = BE_MAX_EQD; |
| 1713 | rxo->rx_eq.enable_aic = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1714 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1715 | /* EQ */ |
| 1716 | eq = &rxo->rx_eq.q; |
| 1717 | rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN, |
| 1718 | sizeof(struct be_eq_entry)); |
| 1719 | if (rc) |
| 1720 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1721 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1722 | rc = be_cmd_eq_create(adapter, eq, rxo->rx_eq.cur_eqd); |
| 1723 | if (rc) |
| 1724 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1725 | |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1726 | rxo->rx_eq.eq_idx = adapter->eq_next_idx++; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1727 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1728 | /* CQ */ |
| 1729 | cq = &rxo->cq; |
| 1730 | rc = be_queue_alloc(adapter, cq, RX_CQ_LEN, |
| 1731 | sizeof(struct be_eth_rx_compl)); |
| 1732 | if (rc) |
| 1733 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1734 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1735 | rc = be_cmd_cq_create(adapter, cq, eq, false, false, 3); |
| 1736 | if (rc) |
| 1737 | goto err; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1738 | |
| 1739 | /* Rx Q - will be created in be_open() */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1740 | q = &rxo->q; |
| 1741 | rc = be_queue_alloc(adapter, q, RX_Q_LEN, |
| 1742 | sizeof(struct be_eth_rx_d)); |
| 1743 | if (rc) |
| 1744 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1745 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1746 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1749 | err: |
| 1750 | be_rx_queues_destroy(adapter); |
| 1751 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1752 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1753 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1754 | static bool event_peek(struct be_eq_obj *eq_obj) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1755 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1756 | struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q); |
| 1757 | if (!eqe->evt) |
| 1758 | return false; |
| 1759 | else |
| 1760 | return true; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1763 | static irqreturn_t be_intx(int irq, void *dev) |
| 1764 | { |
| 1765 | struct be_adapter *adapter = dev; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1766 | struct be_rx_obj *rxo; |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1767 | int isr, i, tx = 0 , rx = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1768 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1769 | if (lancer_chip(adapter)) { |
| 1770 | if (event_peek(&adapter->tx_eq)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1771 | tx = event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1772 | for_all_rx_queues(adapter, rxo, i) { |
| 1773 | if (event_peek(&rxo->rx_eq)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1774 | rx |= event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1775 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1776 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1777 | if (!(tx || rx)) |
| 1778 | return IRQ_NONE; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1779 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1780 | } else { |
| 1781 | isr = ioread32(adapter->csr + CEV_ISR0_OFFSET + |
| 1782 | (adapter->tx_eq.q.id / 8) * CEV_ISR_SIZE); |
| 1783 | if (!isr) |
| 1784 | return IRQ_NONE; |
| 1785 | |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1786 | if ((1 << adapter->tx_eq.eq_idx & isr)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1787 | event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1788 | |
| 1789 | for_all_rx_queues(adapter, rxo, i) { |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 1790 | if ((1 << rxo->rx_eq.eq_idx & isr)) |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1791 | event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1792 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1793 | } |
Sathya Perla | c001c21 | 2009-07-01 01:06:07 +0000 | [diff] [blame] | 1794 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1795 | return IRQ_HANDLED; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | static irqreturn_t be_msix_rx(int irq, void *dev) |
| 1799 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1800 | struct be_rx_obj *rxo = dev; |
| 1801 | struct be_adapter *adapter = rxo->adapter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1802 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1803 | event_handle(adapter, &rxo->rx_eq, true); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1804 | |
| 1805 | return IRQ_HANDLED; |
| 1806 | } |
| 1807 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1808 | static irqreturn_t be_msix_tx_mcc(int irq, void *dev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1809 | { |
| 1810 | struct be_adapter *adapter = dev; |
| 1811 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1812 | event_handle(adapter, &adapter->tx_eq, false); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1813 | |
| 1814 | return IRQ_HANDLED; |
| 1815 | } |
| 1816 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1817 | static inline bool do_gro(struct be_rx_compl_info *rxcp) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1818 | { |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1819 | return (rxcp->tcpf && !rxcp->err) ? true : false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
stephen hemminger | 49b0522 | 2010-10-21 07:50:48 +0000 | [diff] [blame] | 1822 | static int be_poll_rx(struct napi_struct *napi, int budget) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1823 | { |
| 1824 | struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1825 | struct be_rx_obj *rxo = container_of(rx_eq, struct be_rx_obj, rx_eq); |
| 1826 | struct be_adapter *adapter = rxo->adapter; |
| 1827 | struct be_queue_info *rx_cq = &rxo->cq; |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1828 | struct be_rx_compl_info *rxcp; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1829 | u32 work_done; |
| 1830 | |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1831 | rx_stats(rxo)->rx_polls++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1832 | for (work_done = 0; work_done < budget; work_done++) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1833 | rxcp = be_rx_compl_get(rxo); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1834 | if (!rxcp) |
| 1835 | break; |
| 1836 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1837 | /* Is it a flush compl that has no data */ |
| 1838 | if (unlikely(rxcp->num_rcvd == 0)) |
| 1839 | goto loop_continue; |
| 1840 | |
| 1841 | /* Discard compl with partial DMA Lancer B0 */ |
| 1842 | if (unlikely(!rxcp->pkt_size)) { |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 1843 | be_rx_compl_discard(adapter, rxo, rxcp); |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1844 | goto loop_continue; |
Sathya Perla | 6464281 | 2010-12-01 01:04:17 +0000 | [diff] [blame] | 1845 | } |
Padmanabh Ratnakar | 009dd87 | 2011-05-10 05:12:17 +0000 | [diff] [blame] | 1846 | |
Sathya Perla | 12004ae | 2011-08-02 19:57:46 +0000 | [diff] [blame] | 1847 | /* On BE drop pkts that arrive due to imperfect filtering in |
| 1848 | * promiscuous mode on some skews |
| 1849 | */ |
| 1850 | if (unlikely(rxcp->port != adapter->port_num && |
| 1851 | !lancer_chip(adapter))) { |
| 1852 | be_rx_compl_discard(adapter, rxo, rxcp); |
| 1853 | goto loop_continue; |
| 1854 | } |
| 1855 | |
| 1856 | if (do_gro(rxcp)) |
| 1857 | be_rx_compl_process_gro(adapter, rxo, rxcp); |
| 1858 | else |
| 1859 | be_rx_compl_process(adapter, rxo, rxcp); |
| 1860 | loop_continue: |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 1861 | be_rx_stats_update(rxo, rxcp); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1864 | /* Refill the queue */ |
Sathya Perla | 857c990 | 2011-08-22 19:41:51 +0000 | [diff] [blame^] | 1865 | if (work_done && atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM) |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 1866 | be_post_rx_frags(rxo, GFP_ATOMIC); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1867 | |
| 1868 | /* All consumed */ |
| 1869 | if (work_done < budget) { |
| 1870 | napi_complete(napi); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1871 | be_cq_notify(adapter, rx_cq->id, true, work_done); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1872 | } else { |
| 1873 | /* More to be consumed; continue with interrupts disabled */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1874 | be_cq_notify(adapter, rx_cq->id, false, work_done); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1875 | } |
| 1876 | return work_done; |
| 1877 | } |
| 1878 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1879 | /* As TX and MCC share the same EQ check for both TX and MCC completions. |
| 1880 | * For TX/MCC we don't honour budget; consume everything |
| 1881 | */ |
| 1882 | static int be_poll_tx_mcc(struct napi_struct *napi, int budget) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1883 | { |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1884 | struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi); |
| 1885 | struct be_adapter *adapter = |
| 1886 | container_of(tx_eq, struct be_adapter, tx_eq); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1887 | struct be_tx_obj *txo; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1888 | struct be_eth_tx_compl *txcp; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1889 | int tx_compl, mcc_compl, status = 0; |
| 1890 | u8 i; |
| 1891 | u16 num_wrbs; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1892 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1893 | for_all_tx_queues(adapter, txo, i) { |
| 1894 | tx_compl = 0; |
| 1895 | num_wrbs = 0; |
| 1896 | while ((txcp = be_tx_compl_get(&txo->cq))) { |
| 1897 | num_wrbs += be_tx_compl_process(adapter, txo, |
| 1898 | AMAP_GET_BITS(struct amap_eth_tx_compl, |
| 1899 | wrb_index, txcp)); |
| 1900 | tx_compl++; |
| 1901 | } |
| 1902 | if (tx_compl) { |
| 1903 | be_cq_notify(adapter, txo->cq.id, true, tx_compl); |
| 1904 | |
| 1905 | atomic_sub(num_wrbs, &txo->q.used); |
| 1906 | |
| 1907 | /* As Tx wrbs have been freed up, wake up netdev queue |
| 1908 | * if it was stopped due to lack of tx wrbs. */ |
| 1909 | if (__netif_subqueue_stopped(adapter->netdev, i) && |
| 1910 | atomic_read(&txo->q.used) < txo->q.len / 2) { |
| 1911 | netif_wake_subqueue(adapter->netdev, i); |
| 1912 | } |
| 1913 | |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1914 | u64_stats_update_begin(&tx_stats(txo)->sync_compl); |
Sathya Perla | ac124ff | 2011-07-25 19:10:14 +0000 | [diff] [blame] | 1915 | tx_stats(txo)->tx_compl += tx_compl; |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1916 | u64_stats_update_end(&tx_stats(txo)->sync_compl); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1917 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1920 | mcc_compl = be_process_mcc(adapter, &status); |
| 1921 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 1922 | if (mcc_compl) { |
| 1923 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
| 1924 | be_cq_notify(adapter, mcc_obj->cq.id, true, mcc_compl); |
| 1925 | } |
| 1926 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1927 | napi_complete(napi); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1928 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 1929 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 1930 | adapter->drv_stats.tx_events++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1931 | return 1; |
| 1932 | } |
| 1933 | |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 1934 | void be_detect_dump_ue(struct be_adapter *adapter) |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 1935 | { |
| 1936 | u32 ue_status_lo, ue_status_hi, ue_status_lo_mask, ue_status_hi_mask; |
| 1937 | u32 i; |
| 1938 | |
| 1939 | pci_read_config_dword(adapter->pdev, |
| 1940 | PCICFG_UE_STATUS_LOW, &ue_status_lo); |
| 1941 | pci_read_config_dword(adapter->pdev, |
| 1942 | PCICFG_UE_STATUS_HIGH, &ue_status_hi); |
| 1943 | pci_read_config_dword(adapter->pdev, |
| 1944 | PCICFG_UE_STATUS_LOW_MASK, &ue_status_lo_mask); |
| 1945 | pci_read_config_dword(adapter->pdev, |
| 1946 | PCICFG_UE_STATUS_HI_MASK, &ue_status_hi_mask); |
| 1947 | |
| 1948 | ue_status_lo = (ue_status_lo & (~ue_status_lo_mask)); |
| 1949 | ue_status_hi = (ue_status_hi & (~ue_status_hi_mask)); |
| 1950 | |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 1951 | if (ue_status_lo || ue_status_hi) { |
| 1952 | adapter->ue_detected = true; |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 1953 | adapter->eeh_err = true; |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 1954 | dev_err(&adapter->pdev->dev, "UE Detected!!\n"); |
| 1955 | } |
| 1956 | |
Ajit Khaparde | 7c18527 | 2010-07-29 06:16:33 +0000 | [diff] [blame] | 1957 | if (ue_status_lo) { |
| 1958 | for (i = 0; ue_status_lo; ue_status_lo >>= 1, i++) { |
| 1959 | if (ue_status_lo & 1) |
| 1960 | dev_err(&adapter->pdev->dev, |
| 1961 | "UE: %s bit set\n", ue_status_low_desc[i]); |
| 1962 | } |
| 1963 | } |
| 1964 | if (ue_status_hi) { |
| 1965 | for (i = 0; ue_status_hi; ue_status_hi >>= 1, i++) { |
| 1966 | if (ue_status_hi & 1) |
| 1967 | dev_err(&adapter->pdev->dev, |
| 1968 | "UE: %s bit set\n", ue_status_hi_desc[i]); |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | } |
| 1973 | |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1974 | static void be_worker(struct work_struct *work) |
| 1975 | { |
| 1976 | struct be_adapter *adapter = |
| 1977 | container_of(work, struct be_adapter, work.work); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1978 | struct be_rx_obj *rxo; |
| 1979 | int i; |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 1980 | |
Sathya Perla | 16da825 | 2011-03-21 20:49:27 +0000 | [diff] [blame] | 1981 | if (!adapter->ue_detected && !lancer_chip(adapter)) |
| 1982 | be_detect_dump_ue(adapter); |
| 1983 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 1984 | /* when interrupts are not yet enabled, just reap any pending |
| 1985 | * mcc completions */ |
| 1986 | if (!netif_running(adapter->netdev)) { |
| 1987 | int mcc_compl, status = 0; |
| 1988 | |
| 1989 | mcc_compl = be_process_mcc(adapter, &status); |
| 1990 | |
| 1991 | if (mcc_compl) { |
| 1992 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
| 1993 | be_cq_notify(adapter, mcc_obj->cq.id, false, mcc_compl); |
| 1994 | } |
Ajit Khaparde | 9b037f3 | 2011-02-11 13:38:29 +0000 | [diff] [blame] | 1995 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 1996 | goto reschedule; |
| 1997 | } |
| 1998 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1999 | if (!adapter->stats_cmd_sent) { |
| 2000 | if (lancer_chip(adapter)) |
| 2001 | lancer_cmd_get_pport_stats(adapter, |
| 2002 | &adapter->stats_cmd); |
| 2003 | else |
| 2004 | be_cmd_get_stats(adapter, &adapter->stats_cmd); |
| 2005 | } |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2006 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2007 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2008 | be_rx_eqd_update(adapter, rxo); |
| 2009 | |
| 2010 | if (rxo->rx_post_starved) { |
| 2011 | rxo->rx_post_starved = false; |
Eric Dumazet | 1829b08 | 2011-03-01 05:48:12 +0000 | [diff] [blame] | 2012 | be_post_rx_frags(rxo, GFP_KERNEL); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2013 | } |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 2016 | reschedule: |
Ivan Vecera | e74fbd03 | 2011-04-21 00:20:04 +0000 | [diff] [blame] | 2017 | adapter->work_counter++; |
Sathya Perla | ea1dae1 | 2009-03-19 23:56:20 -0700 | [diff] [blame] | 2018 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); |
| 2019 | } |
| 2020 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2021 | static void be_msix_disable(struct be_adapter *adapter) |
| 2022 | { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2023 | if (msix_enabled(adapter)) { |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 2024 | pci_disable_msix(adapter->pdev); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2025 | adapter->num_msix_vec = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2026 | } |
| 2027 | } |
| 2028 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2029 | static void be_msix_enable(struct be_adapter *adapter) |
| 2030 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2031 | #define BE_MIN_MSIX_VECTORS (1 + 1) /* Rx + Tx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2032 | int i, status, num_vec; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2033 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2034 | num_vec = be_num_rxqs_want(adapter) + 1; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2035 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2036 | for (i = 0; i < num_vec; i++) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2037 | adapter->msix_entries[i].entry = i; |
| 2038 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2039 | status = pci_enable_msix(adapter->pdev, adapter->msix_entries, num_vec); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2040 | if (status == 0) { |
| 2041 | goto done; |
| 2042 | } else if (status >= BE_MIN_MSIX_VECTORS) { |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2043 | num_vec = status; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2044 | if (pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2045 | num_vec) == 0) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2046 | goto done; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2047 | } |
| 2048 | return; |
| 2049 | done: |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2050 | adapter->num_msix_vec = num_vec; |
| 2051 | return; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2054 | static void be_sriov_enable(struct be_adapter *adapter) |
| 2055 | { |
Sarveshwar Bandi | 344dbf1 | 2010-07-09 01:43:55 +0000 | [diff] [blame] | 2056 | be_check_sriov_fn_type(adapter); |
Ajit Khaparde | 6dedec8 | 2010-07-29 06:15:32 +0000 | [diff] [blame] | 2057 | #ifdef CONFIG_PCI_IOV |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2058 | if (be_physfn(adapter) && num_vfs) { |
Ajit Khaparde | 81be8f0 | 2011-04-06 18:08:17 +0000 | [diff] [blame] | 2059 | int status, pos; |
| 2060 | u16 nvfs; |
| 2061 | |
| 2062 | pos = pci_find_ext_capability(adapter->pdev, |
| 2063 | PCI_EXT_CAP_ID_SRIOV); |
| 2064 | pci_read_config_word(adapter->pdev, |
| 2065 | pos + PCI_SRIOV_TOTAL_VF, &nvfs); |
| 2066 | |
| 2067 | if (num_vfs > nvfs) { |
| 2068 | dev_info(&adapter->pdev->dev, |
| 2069 | "Device supports %d VFs and not %d\n", |
| 2070 | nvfs, num_vfs); |
| 2071 | num_vfs = nvfs; |
| 2072 | } |
Ajit Khaparde | 6dedec8 | 2010-07-29 06:15:32 +0000 | [diff] [blame] | 2073 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2074 | status = pci_enable_sriov(adapter->pdev, num_vfs); |
| 2075 | adapter->sriov_enabled = status ? false : true; |
| 2076 | } |
| 2077 | #endif |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | static void be_sriov_disable(struct be_adapter *adapter) |
| 2081 | { |
| 2082 | #ifdef CONFIG_PCI_IOV |
| 2083 | if (adapter->sriov_enabled) { |
| 2084 | pci_disable_sriov(adapter->pdev); |
| 2085 | adapter->sriov_enabled = false; |
| 2086 | } |
| 2087 | #endif |
| 2088 | } |
| 2089 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2090 | static inline int be_msix_vec_get(struct be_adapter *adapter, |
| 2091 | struct be_eq_obj *eq_obj) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2092 | { |
Padmanabh Ratnakar | ecd6210 | 2011-04-03 01:54:11 +0000 | [diff] [blame] | 2093 | return adapter->msix_entries[eq_obj->eq_idx].vector; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | static int be_request_irq(struct be_adapter *adapter, |
| 2097 | struct be_eq_obj *eq_obj, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2098 | void *handler, char *desc, void *context) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2099 | { |
| 2100 | struct net_device *netdev = adapter->netdev; |
| 2101 | int vec; |
| 2102 | |
| 2103 | sprintf(eq_obj->desc, "%s-%s", netdev->name, desc); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2104 | vec = be_msix_vec_get(adapter, eq_obj); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2105 | return request_irq(vec, handler, 0, eq_obj->desc, context); |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2108 | static void be_free_irq(struct be_adapter *adapter, struct be_eq_obj *eq_obj, |
| 2109 | void *context) |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2110 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2111 | int vec = be_msix_vec_get(adapter, eq_obj); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2112 | free_irq(vec, context); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | static int be_msix_register(struct be_adapter *adapter) |
| 2116 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2117 | struct be_rx_obj *rxo; |
| 2118 | int status, i; |
| 2119 | char qname[10]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2120 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2121 | status = be_request_irq(adapter, &adapter->tx_eq, be_msix_tx_mcc, "tx", |
| 2122 | adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2123 | if (status) |
| 2124 | goto err; |
| 2125 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2126 | for_all_rx_queues(adapter, rxo, i) { |
| 2127 | sprintf(qname, "rxq%d", i); |
| 2128 | status = be_request_irq(adapter, &rxo->rx_eq, be_msix_rx, |
| 2129 | qname, rxo); |
| 2130 | if (status) |
| 2131 | goto err_msix; |
| 2132 | } |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2133 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2134 | return 0; |
Sathya Perla | b628bde | 2009-08-17 00:58:26 +0000 | [diff] [blame] | 2135 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2136 | err_msix: |
| 2137 | be_free_irq(adapter, &adapter->tx_eq, adapter); |
| 2138 | |
| 2139 | for (i--, rxo = &adapter->rx_obj[i]; i >= 0; i--, rxo--) |
| 2140 | be_free_irq(adapter, &rxo->rx_eq, rxo); |
| 2141 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2142 | err: |
| 2143 | dev_warn(&adapter->pdev->dev, |
| 2144 | "MSIX Request IRQ failed - err %d\n", status); |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2145 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2146 | return status; |
| 2147 | } |
| 2148 | |
| 2149 | static int be_irq_register(struct be_adapter *adapter) |
| 2150 | { |
| 2151 | struct net_device *netdev = adapter->netdev; |
| 2152 | int status; |
| 2153 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2154 | if (msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2155 | status = be_msix_register(adapter); |
| 2156 | if (status == 0) |
| 2157 | goto done; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2158 | /* INTx is not supported for VF */ |
| 2159 | if (!be_physfn(adapter)) |
| 2160 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /* INTx */ |
| 2164 | netdev->irq = adapter->pdev->irq; |
| 2165 | status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name, |
| 2166 | adapter); |
| 2167 | if (status) { |
| 2168 | dev_err(&adapter->pdev->dev, |
| 2169 | "INTx request IRQ failed - err %d\n", status); |
| 2170 | return status; |
| 2171 | } |
| 2172 | done: |
| 2173 | adapter->isr_registered = true; |
| 2174 | return 0; |
| 2175 | } |
| 2176 | |
| 2177 | static void be_irq_unregister(struct be_adapter *adapter) |
| 2178 | { |
| 2179 | struct net_device *netdev = adapter->netdev; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2180 | struct be_rx_obj *rxo; |
| 2181 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2182 | |
| 2183 | if (!adapter->isr_registered) |
| 2184 | return; |
| 2185 | |
| 2186 | /* INTx */ |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2187 | if (!msix_enabled(adapter)) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2188 | free_irq(netdev->irq, adapter); |
| 2189 | goto done; |
| 2190 | } |
| 2191 | |
| 2192 | /* MSIx */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2193 | be_free_irq(adapter, &adapter->tx_eq, adapter); |
| 2194 | |
| 2195 | for_all_rx_queues(adapter, rxo, i) |
| 2196 | be_free_irq(adapter, &rxo->rx_eq, rxo); |
| 2197 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2198 | done: |
| 2199 | adapter->isr_registered = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2202 | static void be_rx_queues_clear(struct be_adapter *adapter) |
| 2203 | { |
| 2204 | struct be_queue_info *q; |
| 2205 | struct be_rx_obj *rxo; |
| 2206 | int i; |
| 2207 | |
| 2208 | for_all_rx_queues(adapter, rxo, i) { |
| 2209 | q = &rxo->q; |
| 2210 | if (q->created) { |
| 2211 | be_cmd_rxq_destroy(adapter, q); |
| 2212 | /* After the rxq is invalidated, wait for a grace time |
| 2213 | * of 1ms for all dma to end and the flush compl to |
| 2214 | * arrive |
| 2215 | */ |
| 2216 | mdelay(1); |
| 2217 | be_rx_q_clean(adapter, rxo); |
| 2218 | } |
| 2219 | |
| 2220 | /* Clear any residual events */ |
| 2221 | q = &rxo->rx_eq.q; |
| 2222 | if (q->created) |
| 2223 | be_eq_clean(adapter, &rxo->rx_eq); |
| 2224 | } |
| 2225 | } |
| 2226 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2227 | static int be_close(struct net_device *netdev) |
| 2228 | { |
| 2229 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2230 | struct be_rx_obj *rxo; |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2231 | struct be_tx_obj *txo; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2232 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2233 | int vec, i; |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2234 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2235 | be_async_mcc_disable(adapter); |
| 2236 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2237 | if (!lancer_chip(adapter)) |
| 2238 | be_intr_set(adapter, false); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2239 | |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2240 | for_all_rx_queues(adapter, rxo, i) |
| 2241 | napi_disable(&rxo->rx_eq.napi); |
| 2242 | |
| 2243 | napi_disable(&tx_eq->napi); |
| 2244 | |
| 2245 | if (lancer_chip(adapter)) { |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2246 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0); |
| 2247 | for_all_rx_queues(adapter, rxo, i) |
| 2248 | be_cq_notify(adapter, rxo->cq.id, false, 0); |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2249 | for_all_tx_queues(adapter, txo, i) |
| 2250 | be_cq_notify(adapter, txo->cq.id, false, 0); |
Padmanabh Ratnakar | 63fcb27 | 2011-03-07 03:09:17 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2253 | if (msix_enabled(adapter)) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2254 | vec = be_msix_vec_get(adapter, tx_eq); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2255 | synchronize_irq(vec); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2256 | |
| 2257 | for_all_rx_queues(adapter, rxo, i) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2258 | vec = be_msix_vec_get(adapter, &rxo->rx_eq); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2259 | synchronize_irq(vec); |
| 2260 | } |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2261 | } else { |
| 2262 | synchronize_irq(netdev->irq); |
| 2263 | } |
| 2264 | be_irq_unregister(adapter); |
| 2265 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2266 | /* Wait for all pending tx completions to arrive so that |
| 2267 | * all tx skbs are freed. |
| 2268 | */ |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 2269 | for_all_tx_queues(adapter, txo, i) |
| 2270 | be_tx_compl_clean(adapter, txo); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2271 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2272 | be_rx_queues_clear(adapter); |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static int be_rx_queues_setup(struct be_adapter *adapter) |
| 2277 | { |
| 2278 | struct be_rx_obj *rxo; |
| 2279 | int rc, i; |
| 2280 | u8 rsstable[MAX_RSS_QS]; |
| 2281 | |
| 2282 | for_all_rx_queues(adapter, rxo, i) { |
| 2283 | rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, |
| 2284 | rx_frag_size, BE_MAX_JUMBO_FRAME_SIZE, |
| 2285 | adapter->if_handle, |
| 2286 | (i > 0) ? 1 : 0/* rss enable */, &rxo->rss_id); |
| 2287 | if (rc) |
| 2288 | return rc; |
| 2289 | } |
| 2290 | |
| 2291 | if (be_multi_rxq(adapter)) { |
| 2292 | for_all_rss_queues(adapter, rxo, i) |
| 2293 | rsstable[i] = rxo->rss_id; |
| 2294 | |
| 2295 | rc = be_cmd_rss_config(adapter, rsstable, |
| 2296 | adapter->num_rx_qs - 1); |
| 2297 | if (rc) |
| 2298 | return rc; |
| 2299 | } |
| 2300 | |
| 2301 | /* First time posting */ |
| 2302 | for_all_rx_queues(adapter, rxo, i) { |
| 2303 | be_post_rx_frags(rxo, GFP_KERNEL); |
| 2304 | napi_enable(&rxo->rx_eq.napi); |
| 2305 | } |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2306 | return 0; |
| 2307 | } |
| 2308 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2309 | static int be_open(struct net_device *netdev) |
| 2310 | { |
| 2311 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2312 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2313 | struct be_rx_obj *rxo; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2314 | int status, i; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2315 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 2316 | status = be_rx_queues_setup(adapter); |
| 2317 | if (status) |
| 2318 | goto err; |
| 2319 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2320 | napi_enable(&tx_eq->napi); |
| 2321 | |
| 2322 | be_irq_register(adapter); |
| 2323 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2324 | if (!lancer_chip(adapter)) |
| 2325 | be_intr_set(adapter, true); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2326 | |
| 2327 | /* The evt queues are created in unarmed state; arm them */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2328 | for_all_rx_queues(adapter, rxo, i) { |
| 2329 | be_eq_notify(adapter, rxo->rx_eq.q.id, true, false, 0); |
| 2330 | be_cq_notify(adapter, rxo->cq.id, true, 0); |
| 2331 | } |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2332 | be_eq_notify(adapter, tx_eq->q.id, true, false, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2333 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 2334 | /* Now that interrupts are on we can process async mcc */ |
| 2335 | be_async_mcc_enable(adapter); |
| 2336 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2337 | if (be_physfn(adapter)) { |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 2338 | status = be_vid_config(adapter, false, 0); |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2339 | if (status) |
| 2340 | goto err; |
| 2341 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2342 | status = be_cmd_set_flow_control(adapter, |
| 2343 | adapter->tx_fc, adapter->rx_fc); |
| 2344 | if (status) |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2345 | goto err; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2346 | } |
Ajit Khaparde | 4f2aa89 | 2009-11-06 02:07:32 +0000 | [diff] [blame] | 2347 | |
Sathya Perla | 889cd4b | 2010-05-30 23:33:45 +0000 | [diff] [blame] | 2348 | return 0; |
| 2349 | err: |
| 2350 | be_close(adapter->netdev); |
| 2351 | return -EIO; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2354 | static int be_setup_wol(struct be_adapter *adapter, bool enable) |
| 2355 | { |
| 2356 | struct be_dma_mem cmd; |
| 2357 | int status = 0; |
| 2358 | u8 mac[ETH_ALEN]; |
| 2359 | |
| 2360 | memset(mac, 0, ETH_ALEN); |
| 2361 | |
| 2362 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2363 | cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 2364 | GFP_KERNEL); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2365 | if (cmd.va == NULL) |
| 2366 | return -1; |
| 2367 | memset(cmd.va, 0, cmd.size); |
| 2368 | |
| 2369 | if (enable) { |
| 2370 | status = pci_write_config_dword(adapter->pdev, |
| 2371 | PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK); |
| 2372 | if (status) { |
| 2373 | dev_err(&adapter->pdev->dev, |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 2374 | "Could not enable Wake-on-lan\n"); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2375 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 2376 | cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2377 | return status; |
| 2378 | } |
| 2379 | status = be_cmd_enable_magic_wol(adapter, |
| 2380 | adapter->netdev->dev_addr, &cmd); |
| 2381 | pci_enable_wake(adapter->pdev, PCI_D3hot, 1); |
| 2382 | pci_enable_wake(adapter->pdev, PCI_D3cold, 1); |
| 2383 | } else { |
| 2384 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); |
| 2385 | pci_enable_wake(adapter->pdev, PCI_D3hot, 0); |
| 2386 | pci_enable_wake(adapter->pdev, PCI_D3cold, 0); |
| 2387 | } |
| 2388 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2389 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2390 | return status; |
| 2391 | } |
| 2392 | |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2393 | /* |
| 2394 | * Generate a seed MAC address from the PF MAC Address using jhash. |
| 2395 | * MAC Address for VFs are assigned incrementally starting from the seed. |
| 2396 | * These addresses are programmed in the ASIC by the PF and the VF driver |
| 2397 | * queries for the MAC address during its probe. |
| 2398 | */ |
| 2399 | static inline int be_vf_eth_addr_config(struct be_adapter *adapter) |
| 2400 | { |
| 2401 | u32 vf = 0; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2402 | int status = 0; |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2403 | u8 mac[ETH_ALEN]; |
| 2404 | |
| 2405 | be_vf_eth_addr_generate(adapter, mac); |
| 2406 | |
| 2407 | for (vf = 0; vf < num_vfs; vf++) { |
| 2408 | status = be_cmd_pmac_add(adapter, mac, |
| 2409 | adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 2410 | &adapter->vf_cfg[vf].vf_pmac_id, |
| 2411 | vf + 1); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2412 | if (status) |
| 2413 | dev_err(&adapter->pdev->dev, |
| 2414 | "Mac address add failed for VF %d\n", vf); |
| 2415 | else |
| 2416 | memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN); |
| 2417 | |
| 2418 | mac[5] += 1; |
| 2419 | } |
| 2420 | return status; |
| 2421 | } |
| 2422 | |
| 2423 | static inline void be_vf_eth_addr_rem(struct be_adapter *adapter) |
| 2424 | { |
| 2425 | u32 vf; |
| 2426 | |
| 2427 | for (vf = 0; vf < num_vfs; vf++) { |
| 2428 | if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID) |
| 2429 | be_cmd_pmac_del(adapter, |
| 2430 | adapter->vf_cfg[vf].vf_if_handle, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 2431 | adapter->vf_cfg[vf].vf_pmac_id, vf + 1); |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2435 | static int be_setup(struct be_adapter *adapter) |
| 2436 | { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2437 | struct net_device *netdev = adapter->netdev; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2438 | u32 cap_flags, en_flags, vf = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2439 | int status; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2440 | u8 mac[ETH_ALEN]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2441 | |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 2442 | be_cmd_req_native_mode(adapter); |
| 2443 | |
Padmanabh Ratnakar | f21b538 | 2011-03-07 03:09:36 +0000 | [diff] [blame] | 2444 | cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | |
| 2445 | BE_IF_FLAGS_BROADCAST | |
| 2446 | BE_IF_FLAGS_MULTICAST; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2447 | |
| 2448 | if (be_physfn(adapter)) { |
| 2449 | cap_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS | |
| 2450 | BE_IF_FLAGS_PROMISCUOUS | |
| 2451 | BE_IF_FLAGS_PASS_L3L4_ERRORS; |
| 2452 | en_flags |= BE_IF_FLAGS_PASS_L3L4_ERRORS; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2453 | |
Sathya Perla | ac6a0c4 | 2011-03-21 20:49:25 +0000 | [diff] [blame] | 2454 | if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2455 | cap_flags |= BE_IF_FLAGS_RSS; |
| 2456 | en_flags |= BE_IF_FLAGS_RSS; |
| 2457 | } |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2458 | } |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 2459 | |
| 2460 | status = be_cmd_if_create(adapter, cap_flags, en_flags, |
| 2461 | netdev->dev_addr, false/* pmac_invalid */, |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2462 | &adapter->if_handle, &adapter->pmac_id, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2463 | if (status != 0) |
| 2464 | goto do_none; |
| 2465 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2466 | if (be_physfn(adapter)) { |
Ajit Khaparde | c99ac3e | 2011-02-11 13:35:02 +0000 | [diff] [blame] | 2467 | if (adapter->sriov_enabled) { |
| 2468 | while (vf < num_vfs) { |
| 2469 | cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | |
| 2470 | BE_IF_FLAGS_BROADCAST; |
| 2471 | status = be_cmd_if_create(adapter, cap_flags, |
| 2472 | en_flags, mac, true, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 2473 | &adapter->vf_cfg[vf].vf_if_handle, |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2474 | NULL, vf+1); |
Ajit Khaparde | c99ac3e | 2011-02-11 13:35:02 +0000 | [diff] [blame] | 2475 | if (status) { |
| 2476 | dev_err(&adapter->pdev->dev, |
| 2477 | "Interface Create failed for VF %d\n", |
| 2478 | vf); |
| 2479 | goto if_destroy; |
| 2480 | } |
| 2481 | adapter->vf_cfg[vf].vf_pmac_id = |
| 2482 | BE_INVALID_PMAC_ID; |
| 2483 | vf++; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2484 | } |
Sarveshwar Bandi | 84e5b9f | 2010-05-27 16:28:15 -0700 | [diff] [blame] | 2485 | } |
Ajit Khaparde | c99ac3e | 2011-02-11 13:35:02 +0000 | [diff] [blame] | 2486 | } else { |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2487 | status = be_cmd_mac_addr_query(adapter, mac, |
| 2488 | MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle); |
| 2489 | if (!status) { |
| 2490 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 2491 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 2492 | } |
| 2493 | } |
| 2494 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2495 | status = be_tx_queues_create(adapter); |
| 2496 | if (status != 0) |
| 2497 | goto if_destroy; |
| 2498 | |
| 2499 | status = be_rx_queues_create(adapter); |
| 2500 | if (status != 0) |
| 2501 | goto tx_qs_destroy; |
| 2502 | |
Sathya Perla | 2903dd6 | 2011-06-26 20:41:53 +0000 | [diff] [blame] | 2503 | /* Allow all priorities by default. A GRP5 evt may modify this */ |
| 2504 | adapter->vlan_prio_bmap = 0xff; |
| 2505 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2506 | status = be_mcc_queues_create(adapter); |
| 2507 | if (status != 0) |
| 2508 | goto rx_qs_destroy; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2509 | |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 2510 | adapter->link_speed = -1; |
| 2511 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2512 | return 0; |
| 2513 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2514 | rx_qs_destroy: |
| 2515 | be_rx_queues_destroy(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2516 | tx_qs_destroy: |
| 2517 | be_tx_queues_destroy(adapter); |
| 2518 | if_destroy: |
Ajit Khaparde | c99ac3e | 2011-02-11 13:35:02 +0000 | [diff] [blame] | 2519 | if (be_physfn(adapter) && adapter->sriov_enabled) |
| 2520 | for (vf = 0; vf < num_vfs; vf++) |
| 2521 | if (adapter->vf_cfg[vf].vf_if_handle) |
| 2522 | be_cmd_if_destroy(adapter, |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 2523 | adapter->vf_cfg[vf].vf_if_handle, |
| 2524 | vf + 1); |
| 2525 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2526 | do_none: |
| 2527 | return status; |
| 2528 | } |
| 2529 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2530 | static int be_clear(struct be_adapter *adapter) |
| 2531 | { |
Ajit Khaparde | 7ab8b0b | 2011-02-11 13:35:56 +0000 | [diff] [blame] | 2532 | int vf; |
| 2533 | |
Ajit Khaparde | c99ac3e | 2011-02-11 13:35:02 +0000 | [diff] [blame] | 2534 | if (be_physfn(adapter) && adapter->sriov_enabled) |
Ajit Khaparde | 6d87f5c | 2010-08-25 00:32:33 +0000 | [diff] [blame] | 2535 | be_vf_eth_addr_rem(adapter); |
| 2536 | |
Sathya Perla | 1a8887d | 2009-08-17 00:58:41 +0000 | [diff] [blame] | 2537 | be_mcc_queues_destroy(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2538 | be_rx_queues_destroy(adapter); |
| 2539 | be_tx_queues_destroy(adapter); |
Padmanabh Ratnakar | 1f5db83 | 2011-04-03 01:54:39 +0000 | [diff] [blame] | 2540 | adapter->eq_next_idx = 0; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2541 | |
Ajit Khaparde | 7ab8b0b | 2011-02-11 13:35:56 +0000 | [diff] [blame] | 2542 | if (be_physfn(adapter) && adapter->sriov_enabled) |
| 2543 | for (vf = 0; vf < num_vfs; vf++) |
| 2544 | if (adapter->vf_cfg[vf].vf_if_handle) |
| 2545 | be_cmd_if_destroy(adapter, |
| 2546 | adapter->vf_cfg[vf].vf_if_handle, |
| 2547 | vf + 1); |
| 2548 | |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 2549 | be_cmd_if_destroy(adapter, adapter->if_handle, 0); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2550 | |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 2551 | adapter->be3_native = 0; |
| 2552 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 2553 | /* tell fw we're done with firing cmds */ |
| 2554 | be_cmd_fw_clean(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2555 | return 0; |
| 2556 | } |
| 2557 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2558 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2559 | #define FW_FILE_HDR_SIGN "ServerEngines Corp. " |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2560 | static bool be_flash_redboot(struct be_adapter *adapter, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2561 | const u8 *p, u32 img_start, int image_size, |
| 2562 | int hdr_size) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2563 | { |
| 2564 | u32 crc_offset; |
| 2565 | u8 flashed_crc[4]; |
| 2566 | int status; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2567 | |
| 2568 | crc_offset = hdr_size + img_start + image_size - 4; |
| 2569 | |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2570 | p += crc_offset; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2571 | |
| 2572 | status = be_cmd_get_flash_crc(adapter, flashed_crc, |
Ajit Khaparde | f510fc6 | 2010-03-31 01:47:45 +0000 | [diff] [blame] | 2573 | (image_size - 4)); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2574 | if (status) { |
| 2575 | dev_err(&adapter->pdev->dev, |
| 2576 | "could not get crc from flash, not flashing redboot\n"); |
| 2577 | return false; |
| 2578 | } |
| 2579 | |
| 2580 | /*update redboot only if crc does not match*/ |
| 2581 | if (!memcmp(flashed_crc, p, 4)) |
| 2582 | return false; |
| 2583 | else |
| 2584 | return true; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2587 | static bool phy_flashing_required(struct be_adapter *adapter) |
| 2588 | { |
| 2589 | int status = 0; |
| 2590 | struct be_phy_info phy_info; |
| 2591 | |
| 2592 | status = be_cmd_get_phy_info(adapter, &phy_info); |
| 2593 | if (status) |
| 2594 | return false; |
| 2595 | if ((phy_info.phy_type == TN_8022) && |
| 2596 | (phy_info.interface_type == PHY_TYPE_BASET_10GB)) { |
| 2597 | return true; |
| 2598 | } |
| 2599 | return false; |
| 2600 | } |
| 2601 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2602 | static int be_flash_data(struct be_adapter *adapter, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2603 | const struct firmware *fw, |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2604 | struct be_dma_mem *flash_cmd, int num_of_images) |
| 2605 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2606 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2607 | int status = 0, i, filehdr_size = 0; |
| 2608 | u32 total_bytes = 0, flash_op; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2609 | int num_bytes; |
| 2610 | const u8 *p = fw->data; |
| 2611 | struct be_cmd_write_flashrom *req = flash_cmd->va; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2612 | const struct flash_comp *pflashcomp; |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2613 | int num_comp; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2614 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2615 | static const struct flash_comp gen3_flash_types[10] = { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2616 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, IMG_TYPE_ISCSI_ACTIVE, |
| 2617 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2618 | { FLASH_REDBOOT_START_g3, IMG_TYPE_REDBOOT, |
| 2619 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g3}, |
| 2620 | { FLASH_iSCSI_BIOS_START_g3, IMG_TYPE_BIOS, |
| 2621 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2622 | { FLASH_PXE_BIOS_START_g3, IMG_TYPE_PXE_BIOS, |
| 2623 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2624 | { FLASH_FCoE_BIOS_START_g3, IMG_TYPE_FCOE_BIOS, |
| 2625 | FLASH_BIOS_IMAGE_MAX_SIZE_g3}, |
| 2626 | { FLASH_iSCSI_BACKUP_IMAGE_START_g3, IMG_TYPE_ISCSI_BACKUP, |
| 2627 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2628 | { FLASH_FCoE_PRIMARY_IMAGE_START_g3, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2629 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2630 | { FLASH_FCoE_BACKUP_IMAGE_START_g3, IMG_TYPE_FCOE_FW_BACKUP, |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2631 | FLASH_IMAGE_MAX_SIZE_g3}, |
| 2632 | { FLASH_NCSI_START_g3, IMG_TYPE_NCSI_FW, |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2633 | FLASH_NCSI_IMAGE_MAX_SIZE_g3}, |
| 2634 | { FLASH_PHY_FW_START_g3, IMG_TYPE_PHY_FW, |
| 2635 | FLASH_PHY_FW_IMAGE_MAX_SIZE_g3} |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2636 | }; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2637 | static const struct flash_comp gen2_flash_types[8] = { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2638 | { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, IMG_TYPE_ISCSI_ACTIVE, |
| 2639 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2640 | { FLASH_REDBOOT_START_g2, IMG_TYPE_REDBOOT, |
| 2641 | FLASH_REDBOOT_IMAGE_MAX_SIZE_g2}, |
| 2642 | { FLASH_iSCSI_BIOS_START_g2, IMG_TYPE_BIOS, |
| 2643 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2644 | { FLASH_PXE_BIOS_START_g2, IMG_TYPE_PXE_BIOS, |
| 2645 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2646 | { FLASH_FCoE_BIOS_START_g2, IMG_TYPE_FCOE_BIOS, |
| 2647 | FLASH_BIOS_IMAGE_MAX_SIZE_g2}, |
| 2648 | { FLASH_iSCSI_BACKUP_IMAGE_START_g2, IMG_TYPE_ISCSI_BACKUP, |
| 2649 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2650 | { FLASH_FCoE_PRIMARY_IMAGE_START_g2, IMG_TYPE_FCOE_FW_ACTIVE, |
| 2651 | FLASH_IMAGE_MAX_SIZE_g2}, |
| 2652 | { FLASH_FCoE_BACKUP_IMAGE_START_g2, IMG_TYPE_FCOE_FW_BACKUP, |
| 2653 | FLASH_IMAGE_MAX_SIZE_g2} |
| 2654 | }; |
| 2655 | |
| 2656 | if (adapter->generation == BE_GEN3) { |
| 2657 | pflashcomp = gen3_flash_types; |
| 2658 | filehdr_size = sizeof(struct flash_file_hdr_g3); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2659 | num_comp = ARRAY_SIZE(gen3_flash_types); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2660 | } else { |
| 2661 | pflashcomp = gen2_flash_types; |
| 2662 | filehdr_size = sizeof(struct flash_file_hdr_g2); |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 2663 | num_comp = ARRAY_SIZE(gen2_flash_types); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2664 | } |
Sarveshwar Bandi | 9fe9693 | 2010-03-02 22:37:28 +0000 | [diff] [blame] | 2665 | for (i = 0; i < num_comp; i++) { |
| 2666 | if ((pflashcomp[i].optype == IMG_TYPE_NCSI_FW) && |
| 2667 | memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0) |
| 2668 | continue; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2669 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) { |
| 2670 | if (!phy_flashing_required(adapter)) |
| 2671 | continue; |
| 2672 | } |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2673 | if ((pflashcomp[i].optype == IMG_TYPE_REDBOOT) && |
| 2674 | (!be_flash_redboot(adapter, fw->data, |
Ajit Khaparde | fae21a4 | 2011-02-11 13:37:42 +0000 | [diff] [blame] | 2675 | pflashcomp[i].offset, pflashcomp[i].size, filehdr_size + |
| 2676 | (num_of_images * sizeof(struct image_hdr))))) |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2677 | continue; |
| 2678 | p = fw->data; |
| 2679 | p += filehdr_size + pflashcomp[i].offset |
| 2680 | + (num_of_images * sizeof(struct image_hdr)); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2681 | if (p + pflashcomp[i].size > fw->data + fw->size) |
| 2682 | return -1; |
| 2683 | total_bytes = pflashcomp[i].size; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2684 | while (total_bytes) { |
| 2685 | if (total_bytes > 32*1024) |
| 2686 | num_bytes = 32*1024; |
| 2687 | else |
| 2688 | num_bytes = total_bytes; |
| 2689 | total_bytes -= num_bytes; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2690 | if (!total_bytes) { |
| 2691 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) |
| 2692 | flash_op = FLASHROM_OPER_PHY_FLASH; |
| 2693 | else |
| 2694 | flash_op = FLASHROM_OPER_FLASH; |
| 2695 | } else { |
| 2696 | if (pflashcomp[i].optype == IMG_TYPE_PHY_FW) |
| 2697 | flash_op = FLASHROM_OPER_PHY_SAVE; |
| 2698 | else |
| 2699 | flash_op = FLASHROM_OPER_SAVE; |
| 2700 | } |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2701 | memcpy(req->params.data_buf, p, num_bytes); |
| 2702 | p += num_bytes; |
| 2703 | status = be_cmd_write_flashrom(adapter, flash_cmd, |
| 2704 | pflashcomp[i].optype, flash_op, num_bytes); |
| 2705 | if (status) { |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2706 | if ((status == ILLEGAL_IOCTL_REQ) && |
| 2707 | (pflashcomp[i].optype == |
| 2708 | IMG_TYPE_PHY_FW)) |
| 2709 | break; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2710 | dev_err(&adapter->pdev->dev, |
| 2711 | "cmd to write to flash rom failed.\n"); |
| 2712 | return -1; |
| 2713 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2714 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2715 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2716 | return 0; |
| 2717 | } |
| 2718 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2719 | static int get_ufigen_type(struct flash_file_hdr_g2 *fhdr) |
| 2720 | { |
| 2721 | if (fhdr == NULL) |
| 2722 | return 0; |
| 2723 | if (fhdr->build[0] == '3') |
| 2724 | return BE_GEN3; |
| 2725 | else if (fhdr->build[0] == '2') |
| 2726 | return BE_GEN2; |
| 2727 | else |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2731 | static int lancer_fw_download(struct be_adapter *adapter, |
| 2732 | const struct firmware *fw) |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2733 | { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2734 | #define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024) |
| 2735 | #define LANCER_FW_DOWNLOAD_LOCATION "/prg" |
| 2736 | struct be_dma_mem flash_cmd; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2737 | const u8 *data_ptr = NULL; |
| 2738 | u8 *dest_image_ptr = NULL; |
| 2739 | size_t image_size = 0; |
| 2740 | u32 chunk_size = 0; |
| 2741 | u32 data_written = 0; |
| 2742 | u32 offset = 0; |
| 2743 | int status = 0; |
| 2744 | u8 add_status = 0; |
| 2745 | |
| 2746 | if (!IS_ALIGNED(fw->size, sizeof(u32))) { |
| 2747 | dev_err(&adapter->pdev->dev, |
| 2748 | "FW Image not properly aligned. " |
| 2749 | "Length must be 4 byte aligned.\n"); |
| 2750 | status = -EINVAL; |
| 2751 | goto lancer_fw_exit; |
| 2752 | } |
| 2753 | |
| 2754 | flash_cmd.size = sizeof(struct lancer_cmd_req_write_object) |
| 2755 | + LANCER_FW_DOWNLOAD_CHUNK; |
| 2756 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
| 2757 | &flash_cmd.dma, GFP_KERNEL); |
| 2758 | if (!flash_cmd.va) { |
| 2759 | status = -ENOMEM; |
| 2760 | dev_err(&adapter->pdev->dev, |
| 2761 | "Memory allocation failure while flashing\n"); |
| 2762 | goto lancer_fw_exit; |
| 2763 | } |
| 2764 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2765 | dest_image_ptr = flash_cmd.va + |
| 2766 | sizeof(struct lancer_cmd_req_write_object); |
| 2767 | image_size = fw->size; |
| 2768 | data_ptr = fw->data; |
| 2769 | |
| 2770 | while (image_size) { |
| 2771 | chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK); |
| 2772 | |
| 2773 | /* Copy the image chunk content. */ |
| 2774 | memcpy(dest_image_ptr, data_ptr, chunk_size); |
| 2775 | |
| 2776 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
| 2777 | chunk_size, offset, LANCER_FW_DOWNLOAD_LOCATION, |
| 2778 | &data_written, &add_status); |
| 2779 | |
| 2780 | if (status) |
| 2781 | break; |
| 2782 | |
| 2783 | offset += data_written; |
| 2784 | data_ptr += data_written; |
| 2785 | image_size -= data_written; |
| 2786 | } |
| 2787 | |
| 2788 | if (!status) { |
| 2789 | /* Commit the FW written */ |
| 2790 | status = lancer_cmd_write_object(adapter, &flash_cmd, |
| 2791 | 0, offset, LANCER_FW_DOWNLOAD_LOCATION, |
| 2792 | &data_written, &add_status); |
| 2793 | } |
| 2794 | |
| 2795 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 2796 | flash_cmd.dma); |
| 2797 | if (status) { |
| 2798 | dev_err(&adapter->pdev->dev, |
| 2799 | "Firmware load error. " |
| 2800 | "Status code: 0x%x Additional Status: 0x%x\n", |
| 2801 | status, add_status); |
| 2802 | goto lancer_fw_exit; |
| 2803 | } |
| 2804 | |
| 2805 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
| 2806 | lancer_fw_exit: |
| 2807 | return status; |
| 2808 | } |
| 2809 | |
| 2810 | static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw) |
| 2811 | { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2812 | struct flash_file_hdr_g2 *fhdr; |
| 2813 | struct flash_file_hdr_g3 *fhdr3; |
| 2814 | struct image_hdr *img_hdr_ptr = NULL; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2815 | struct be_dma_mem flash_cmd; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2816 | const u8 *p; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2817 | int status = 0, i = 0, num_imgs = 0; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2818 | |
| 2819 | p = fw->data; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2820 | fhdr = (struct flash_file_hdr_g2 *) p; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2821 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2822 | flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2823 | flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size, |
| 2824 | &flash_cmd.dma, GFP_KERNEL); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2825 | if (!flash_cmd.va) { |
| 2826 | status = -ENOMEM; |
| 2827 | dev_err(&adapter->pdev->dev, |
| 2828 | "Memory allocation failure while flashing\n"); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2829 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2832 | if ((adapter->generation == BE_GEN3) && |
| 2833 | (get_ufigen_type(fhdr) == BE_GEN3)) { |
| 2834 | fhdr3 = (struct flash_file_hdr_g3 *) fw->data; |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2835 | num_imgs = le32_to_cpu(fhdr3->num_imgs); |
| 2836 | for (i = 0; i < num_imgs; i++) { |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2837 | img_hdr_ptr = (struct image_hdr *) (fw->data + |
| 2838 | (sizeof(struct flash_file_hdr_g3) + |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2839 | i * sizeof(struct image_hdr))); |
| 2840 | if (le32_to_cpu(img_hdr_ptr->imageid) == 1) |
| 2841 | status = be_flash_data(adapter, fw, &flash_cmd, |
| 2842 | num_imgs); |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2843 | } |
| 2844 | } else if ((adapter->generation == BE_GEN2) && |
| 2845 | (get_ufigen_type(fhdr) == BE_GEN2)) { |
| 2846 | status = be_flash_data(adapter, fw, &flash_cmd, 0); |
| 2847 | } else { |
| 2848 | dev_err(&adapter->pdev->dev, |
| 2849 | "UFI and Interface are not compatible for flashing\n"); |
| 2850 | status = -1; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 2853 | dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va, |
| 2854 | flash_cmd.dma); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2855 | if (status) { |
| 2856 | dev_err(&adapter->pdev->dev, "Firmware load error\n"); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2857 | goto be_fw_exit; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2860 | dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n"); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2861 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2862 | be_fw_exit: |
| 2863 | return status; |
| 2864 | } |
| 2865 | |
| 2866 | int be_load_fw(struct be_adapter *adapter, u8 *fw_file) |
| 2867 | { |
| 2868 | const struct firmware *fw; |
| 2869 | int status; |
| 2870 | |
| 2871 | if (!netif_running(adapter->netdev)) { |
| 2872 | dev_err(&adapter->pdev->dev, |
| 2873 | "Firmware load not allowed (interface is down)\n"); |
| 2874 | return -1; |
| 2875 | } |
| 2876 | |
| 2877 | status = request_firmware(&fw, fw_file, &adapter->pdev->dev); |
| 2878 | if (status) |
| 2879 | goto fw_exit; |
| 2880 | |
| 2881 | dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file); |
| 2882 | |
| 2883 | if (lancer_chip(adapter)) |
| 2884 | status = lancer_fw_download(adapter, fw); |
| 2885 | else |
| 2886 | status = be_fw_download(adapter, fw); |
| 2887 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2888 | fw_exit: |
| 2889 | release_firmware(fw); |
| 2890 | return status; |
| 2891 | } |
| 2892 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2893 | static struct net_device_ops be_netdev_ops = { |
| 2894 | .ndo_open = be_open, |
| 2895 | .ndo_stop = be_close, |
| 2896 | .ndo_start_xmit = be_xmit, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2897 | .ndo_set_rx_mode = be_set_multicast_list, |
| 2898 | .ndo_set_mac_address = be_mac_addr_set, |
| 2899 | .ndo_change_mtu = be_change_mtu, |
Sathya Perla | ab1594e | 2011-07-25 19:10:15 +0000 | [diff] [blame] | 2900 | .ndo_get_stats64 = be_get_stats64, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2901 | .ndo_validate_addr = eth_validate_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2902 | .ndo_vlan_rx_add_vid = be_vlan_add_vid, |
| 2903 | .ndo_vlan_rx_kill_vid = be_vlan_rem_vid, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 2904 | .ndo_set_vf_mac = be_set_vf_mac, |
Ajit Khaparde | 1da87b7 | 2010-07-23 01:51:22 +0000 | [diff] [blame] | 2905 | .ndo_set_vf_vlan = be_set_vf_vlan, |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2906 | .ndo_set_vf_tx_rate = be_set_vf_tx_rate, |
Ajit Khaparde | 64600ea | 2010-07-23 01:50:34 +0000 | [diff] [blame] | 2907 | .ndo_get_vf_config = be_get_vf_config |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2908 | }; |
| 2909 | |
| 2910 | static void be_netdev_init(struct net_device *netdev) |
| 2911 | { |
| 2912 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2913 | struct be_rx_obj *rxo; |
| 2914 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2915 | |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2916 | netdev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 2917 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | |
| 2918 | NETIF_F_HW_VLAN_TX; |
| 2919 | if (be_multi_rxq(adapter)) |
| 2920 | netdev->hw_features |= NETIF_F_RXHASH; |
Michał Mirosław | 6332c8d | 2011-04-07 02:43:48 +0000 | [diff] [blame] | 2921 | |
| 2922 | netdev->features |= netdev->hw_features | |
Michał Mirosław | 8b8ddc6 | 2011-04-08 02:38:47 +0000 | [diff] [blame] | 2923 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; |
Ajit Khaparde | 4b97291 | 2011-04-06 18:07:43 +0000 | [diff] [blame] | 2924 | |
Padmanabh Ratnakar | eb8a50d | 2011-06-11 15:58:46 -0700 | [diff] [blame] | 2925 | netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | |
Michał Mirosław | 7903264 | 2010-11-30 06:38:00 +0000 | [diff] [blame] | 2926 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
Ajit Khaparde | 51c5987 | 2009-11-29 17:54:54 +0000 | [diff] [blame] | 2927 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2928 | netdev->flags |= IFF_MULTICAST; |
| 2929 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 2930 | /* Default settings for Rx and Tx flow control */ |
| 2931 | adapter->rx_fc = true; |
| 2932 | adapter->tx_fc = true; |
| 2933 | |
Ajit Khaparde | c190e3c | 2009-09-04 03:12:29 +0000 | [diff] [blame] | 2934 | netif_set_gso_max_size(netdev, 65535); |
| 2935 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2936 | BE_SET_NETDEV_OPS(netdev, &be_netdev_ops); |
| 2937 | |
| 2938 | SET_ETHTOOL_OPS(netdev, &be_ethtool_ops); |
| 2939 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2940 | for_all_rx_queues(adapter, rxo, i) |
| 2941 | netif_napi_add(netdev, &rxo->rx_eq.napi, be_poll_rx, |
| 2942 | BE_NAPI_WEIGHT); |
| 2943 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 2944 | netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2945 | BE_NAPI_WEIGHT); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | static void be_unmap_pci_bars(struct be_adapter *adapter) |
| 2949 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2950 | if (adapter->csr) |
| 2951 | iounmap(adapter->csr); |
| 2952 | if (adapter->db) |
| 2953 | iounmap(adapter->db); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2954 | if (adapter->pcicfg && be_physfn(adapter)) |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2955 | iounmap(adapter->pcicfg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | static int be_map_pci_bars(struct be_adapter *adapter) |
| 2959 | { |
| 2960 | u8 __iomem *addr; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2961 | int pcicfg_reg, db_reg; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2962 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 2963 | if (lancer_chip(adapter)) { |
| 2964 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 0), |
| 2965 | pci_resource_len(adapter->pdev, 0)); |
| 2966 | if (addr == NULL) |
| 2967 | return -ENOMEM; |
| 2968 | adapter->db = addr; |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2972 | if (be_physfn(adapter)) { |
| 2973 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2), |
| 2974 | pci_resource_len(adapter->pdev, 2)); |
| 2975 | if (addr == NULL) |
| 2976 | return -ENOMEM; |
| 2977 | adapter->csr = addr; |
| 2978 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2979 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2980 | if (adapter->generation == BE_GEN2) { |
| 2981 | pcicfg_reg = 1; |
| 2982 | db_reg = 4; |
| 2983 | } else { |
| 2984 | pcicfg_reg = 0; |
| 2985 | if (be_physfn(adapter)) |
| 2986 | db_reg = 4; |
| 2987 | else |
| 2988 | db_reg = 0; |
| 2989 | } |
| 2990 | addr = ioremap_nocache(pci_resource_start(adapter->pdev, db_reg), |
| 2991 | pci_resource_len(adapter->pdev, db_reg)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2992 | if (addr == NULL) |
| 2993 | goto pci_map_err; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2994 | adapter->db = addr; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2995 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 2996 | if (be_physfn(adapter)) { |
| 2997 | addr = ioremap_nocache( |
| 2998 | pci_resource_start(adapter->pdev, pcicfg_reg), |
| 2999 | pci_resource_len(adapter->pdev, pcicfg_reg)); |
| 3000 | if (addr == NULL) |
| 3001 | goto pci_map_err; |
| 3002 | adapter->pcicfg = addr; |
| 3003 | } else |
| 3004 | adapter->pcicfg = adapter->db + SRIOV_VF_PCICFG_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3005 | |
| 3006 | return 0; |
| 3007 | pci_map_err: |
| 3008 | be_unmap_pci_bars(adapter); |
| 3009 | return -ENOMEM; |
| 3010 | } |
| 3011 | |
| 3012 | |
| 3013 | static void be_ctrl_cleanup(struct be_adapter *adapter) |
| 3014 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3015 | struct be_dma_mem *mem = &adapter->mbox_mem_alloced; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3016 | |
| 3017 | be_unmap_pci_bars(adapter); |
| 3018 | |
| 3019 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3020 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 3021 | mem->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3022 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3023 | mem = &adapter->rx_filter; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3024 | if (mem->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3025 | dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va, |
| 3026 | mem->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3029 | static int be_ctrl_init(struct be_adapter *adapter) |
| 3030 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3031 | struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced; |
| 3032 | struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3033 | struct be_dma_mem *rx_filter = &adapter->rx_filter; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3034 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3035 | |
| 3036 | status = be_map_pci_bars(adapter); |
| 3037 | if (status) |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3038 | goto done; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3039 | |
| 3040 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3041 | mbox_mem_alloc->va = dma_alloc_coherent(&adapter->pdev->dev, |
| 3042 | mbox_mem_alloc->size, |
| 3043 | &mbox_mem_alloc->dma, |
| 3044 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3045 | if (!mbox_mem_alloc->va) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3046 | status = -ENOMEM; |
| 3047 | goto unmap_pci_bars; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3048 | } |
| 3049 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 3050 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 3051 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 3052 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3053 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3054 | rx_filter->size = sizeof(struct be_cmd_req_rx_filter); |
| 3055 | rx_filter->va = dma_alloc_coherent(&adapter->pdev->dev, rx_filter->size, |
| 3056 | &rx_filter->dma, GFP_KERNEL); |
| 3057 | if (rx_filter->va == NULL) { |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3058 | status = -ENOMEM; |
| 3059 | goto free_mbox; |
| 3060 | } |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 3061 | memset(rx_filter->va, 0, rx_filter->size); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3062 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 3063 | mutex_init(&adapter->mbox_lock); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3064 | spin_lock_init(&adapter->mcc_lock); |
| 3065 | spin_lock_init(&adapter->mcc_cq_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3066 | |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 3067 | init_completion(&adapter->flash_compl); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3068 | pci_save_state(adapter->pdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3069 | return 0; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3070 | |
| 3071 | free_mbox: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3072 | dma_free_coherent(&adapter->pdev->dev, mbox_mem_alloc->size, |
| 3073 | mbox_mem_alloc->va, mbox_mem_alloc->dma); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 3074 | |
| 3075 | unmap_pci_bars: |
| 3076 | be_unmap_pci_bars(adapter); |
| 3077 | |
| 3078 | done: |
| 3079 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | static void be_stats_cleanup(struct be_adapter *adapter) |
| 3083 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3084 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3085 | |
| 3086 | if (cmd->va) |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3087 | dma_free_coherent(&adapter->pdev->dev, cmd->size, |
| 3088 | cmd->va, cmd->dma); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | static int be_stats_init(struct be_adapter *adapter) |
| 3092 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3093 | struct be_dma_mem *cmd = &adapter->stats_cmd; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3094 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 3095 | if (adapter->generation == BE_GEN2) { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 3096 | cmd->size = sizeof(struct be_cmd_req_get_stats_v0); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 3097 | } else { |
| 3098 | if (lancer_chip(adapter)) |
| 3099 | cmd->size = sizeof(struct lancer_cmd_req_pport_stats); |
| 3100 | else |
| 3101 | cmd->size = sizeof(struct be_cmd_req_get_stats_v1); |
| 3102 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3103 | cmd->va = dma_alloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma, |
| 3104 | GFP_KERNEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3105 | if (cmd->va == NULL) |
| 3106 | return -1; |
David S. Miller | d291b9a | 2010-01-28 21:36:21 -0800 | [diff] [blame] | 3107 | memset(cmd->va, 0, cmd->size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3108 | return 0; |
| 3109 | } |
| 3110 | |
| 3111 | static void __devexit be_remove(struct pci_dev *pdev) |
| 3112 | { |
| 3113 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3114 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3115 | if (!adapter) |
| 3116 | return; |
| 3117 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 3118 | cancel_delayed_work_sync(&adapter->work); |
| 3119 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3120 | unregister_netdev(adapter->netdev); |
| 3121 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3122 | be_clear(adapter); |
| 3123 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3124 | be_stats_cleanup(adapter); |
| 3125 | |
| 3126 | be_ctrl_cleanup(adapter); |
| 3127 | |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3128 | kfree(adapter->vf_cfg); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3129 | be_sriov_disable(adapter); |
| 3130 | |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3131 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3132 | |
| 3133 | pci_set_drvdata(pdev, NULL); |
| 3134 | pci_release_regions(pdev); |
| 3135 | pci_disable_device(pdev); |
| 3136 | |
| 3137 | free_netdev(adapter->netdev); |
| 3138 | } |
| 3139 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3140 | static int be_get_config(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3141 | { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3142 | int status; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3143 | u8 mac[ETH_ALEN]; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 3144 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 3145 | status = be_cmd_get_fw_ver(adapter, adapter->fw_ver); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3146 | if (status) |
| 3147 | return status; |
| 3148 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3149 | status = be_cmd_query_fw_cfg(adapter, &adapter->port_num, |
| 3150 | &adapter->function_mode, &adapter->function_caps); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3151 | if (status) |
| 3152 | return status; |
| 3153 | |
| 3154 | memset(mac, 0, ETH_ALEN); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3155 | |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 3156 | /* A default permanent address is given to each VF for Lancer*/ |
| 3157 | if (be_physfn(adapter) || lancer_chip(adapter)) { |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3158 | status = be_cmd_mac_addr_query(adapter, mac, |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3159 | MAC_ADDRESS_TYPE_NETWORK, true /*permanent */, 0); |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 3160 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3161 | if (status) |
| 3162 | return status; |
Ajit Khaparde | ca9e498 | 2009-11-29 17:56:26 +0000 | [diff] [blame] | 3163 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3164 | if (!is_valid_ether_addr(mac)) |
| 3165 | return -EADDRNOTAVAIL; |
| 3166 | |
| 3167 | memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN); |
| 3168 | memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN); |
| 3169 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3170 | |
Ajit Khaparde | 3486be2 | 2010-07-23 02:04:54 +0000 | [diff] [blame] | 3171 | if (adapter->function_mode & 0x400) |
Ajit Khaparde | 82903e4 | 2010-02-09 01:34:57 +0000 | [diff] [blame] | 3172 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/4; |
| 3173 | else |
| 3174 | adapter->max_vlans = BE_NUM_VLANS_SUPPORTED; |
| 3175 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3176 | status = be_cmd_get_cntl_attributes(adapter); |
| 3177 | if (status) |
| 3178 | return status; |
| 3179 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3180 | if ((num_vfs && adapter->sriov_enabled) || |
| 3181 | (adapter->function_mode & 0x400) || |
| 3182 | lancer_chip(adapter) || !be_physfn(adapter)) { |
| 3183 | adapter->num_tx_qs = 1; |
| 3184 | netif_set_real_num_tx_queues(adapter->netdev, |
| 3185 | adapter->num_tx_qs); |
| 3186 | } else { |
| 3187 | adapter->num_tx_qs = MAX_TX_QS; |
| 3188 | } |
| 3189 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3190 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3193 | static int be_dev_family_check(struct be_adapter *adapter) |
| 3194 | { |
| 3195 | struct pci_dev *pdev = adapter->pdev; |
| 3196 | u32 sli_intf = 0, if_type; |
| 3197 | |
| 3198 | switch (pdev->device) { |
| 3199 | case BE_DEVICE_ID1: |
| 3200 | case OC_DEVICE_ID1: |
| 3201 | adapter->generation = BE_GEN2; |
| 3202 | break; |
| 3203 | case BE_DEVICE_ID2: |
| 3204 | case OC_DEVICE_ID2: |
| 3205 | adapter->generation = BE_GEN3; |
| 3206 | break; |
| 3207 | case OC_DEVICE_ID3: |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 3208 | case OC_DEVICE_ID4: |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3209 | pci_read_config_dword(pdev, SLI_INTF_REG_OFFSET, &sli_intf); |
| 3210 | if_type = (sli_intf & SLI_INTF_IF_TYPE_MASK) >> |
| 3211 | SLI_INTF_IF_TYPE_SHIFT; |
| 3212 | |
| 3213 | if (((sli_intf & SLI_INTF_VALID_MASK) != SLI_INTF_VALID) || |
| 3214 | if_type != 0x02) { |
| 3215 | dev_err(&pdev->dev, "SLI_INTF reg val is not valid\n"); |
| 3216 | return -EINVAL; |
| 3217 | } |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3218 | adapter->sli_family = ((sli_intf & SLI_INTF_FAMILY_MASK) >> |
| 3219 | SLI_INTF_FAMILY_SHIFT); |
| 3220 | adapter->generation = BE_GEN3; |
| 3221 | break; |
| 3222 | default: |
| 3223 | adapter->generation = 0; |
| 3224 | } |
| 3225 | return 0; |
| 3226 | } |
| 3227 | |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3228 | static int lancer_wait_ready(struct be_adapter *adapter) |
| 3229 | { |
| 3230 | #define SLIPORT_READY_TIMEOUT 500 |
| 3231 | u32 sliport_status; |
| 3232 | int status = 0, i; |
| 3233 | |
| 3234 | for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) { |
| 3235 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3236 | if (sliport_status & SLIPORT_STATUS_RDY_MASK) |
| 3237 | break; |
| 3238 | |
| 3239 | msleep(20); |
| 3240 | } |
| 3241 | |
| 3242 | if (i == SLIPORT_READY_TIMEOUT) |
| 3243 | status = -1; |
| 3244 | |
| 3245 | return status; |
| 3246 | } |
| 3247 | |
| 3248 | static int lancer_test_and_set_rdy_state(struct be_adapter *adapter) |
| 3249 | { |
| 3250 | int status; |
| 3251 | u32 sliport_status, err, reset_needed; |
| 3252 | status = lancer_wait_ready(adapter); |
| 3253 | if (!status) { |
| 3254 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3255 | err = sliport_status & SLIPORT_STATUS_ERR_MASK; |
| 3256 | reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK; |
| 3257 | if (err && reset_needed) { |
| 3258 | iowrite32(SLI_PORT_CONTROL_IP_MASK, |
| 3259 | adapter->db + SLIPORT_CONTROL_OFFSET); |
| 3260 | |
| 3261 | /* check adapter has corrected the error */ |
| 3262 | status = lancer_wait_ready(adapter); |
| 3263 | sliport_status = ioread32(adapter->db + |
| 3264 | SLIPORT_STATUS_OFFSET); |
| 3265 | sliport_status &= (SLIPORT_STATUS_ERR_MASK | |
| 3266 | SLIPORT_STATUS_RN_MASK); |
| 3267 | if (status || sliport_status) |
| 3268 | status = -1; |
| 3269 | } else if (err || reset_needed) { |
| 3270 | status = -1; |
| 3271 | } |
| 3272 | } |
| 3273 | return status; |
| 3274 | } |
| 3275 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3276 | static int __devinit be_probe(struct pci_dev *pdev, |
| 3277 | const struct pci_device_id *pdev_id) |
| 3278 | { |
| 3279 | int status = 0; |
| 3280 | struct be_adapter *adapter; |
| 3281 | struct net_device *netdev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3282 | |
| 3283 | status = pci_enable_device(pdev); |
| 3284 | if (status) |
| 3285 | goto do_none; |
| 3286 | |
| 3287 | status = pci_request_regions(pdev, DRV_NAME); |
| 3288 | if (status) |
| 3289 | goto disable_dev; |
| 3290 | pci_set_master(pdev); |
| 3291 | |
Sathya Perla | 3c8def9 | 2011-06-12 20:01:58 +0000 | [diff] [blame] | 3292 | netdev = alloc_etherdev_mq(sizeof(struct be_adapter), MAX_TX_QS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3293 | if (netdev == NULL) { |
| 3294 | status = -ENOMEM; |
| 3295 | goto rel_reg; |
| 3296 | } |
| 3297 | adapter = netdev_priv(netdev); |
| 3298 | adapter->pdev = pdev; |
| 3299 | pci_set_drvdata(pdev, adapter); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3300 | |
| 3301 | status = be_dev_family_check(adapter); |
Sathya Perla | 63657b9 | 2010-12-01 01:02:28 +0000 | [diff] [blame] | 3302 | if (status) |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3303 | goto free_netdev; |
| 3304 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3305 | adapter->netdev = netdev; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3306 | SET_NETDEV_DEV(netdev, &pdev->dev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3307 | |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3308 | status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3309 | if (!status) { |
| 3310 | netdev->features |= NETIF_F_HIGHDMA; |
| 3311 | } else { |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 3312 | status = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3313 | if (status) { |
| 3314 | dev_err(&pdev->dev, "Could not set PCI DMA Mask\n"); |
| 3315 | goto free_netdev; |
| 3316 | } |
| 3317 | } |
| 3318 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3319 | be_sriov_enable(adapter); |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3320 | if (adapter->sriov_enabled) { |
| 3321 | adapter->vf_cfg = kcalloc(num_vfs, |
| 3322 | sizeof(struct be_vf_cfg), GFP_KERNEL); |
| 3323 | |
| 3324 | if (!adapter->vf_cfg) |
| 3325 | goto free_netdev; |
| 3326 | } |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3327 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3328 | status = be_ctrl_init(adapter); |
| 3329 | if (status) |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3330 | goto free_vf_cfg; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3331 | |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3332 | if (lancer_chip(adapter)) { |
| 3333 | status = lancer_test_and_set_rdy_state(adapter); |
| 3334 | if (status) { |
| 3335 | dev_err(&pdev->dev, "Adapter in non recoverable error\n"); |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3336 | goto ctrl_clean; |
Padmanabh Ratnakar | 37eed1c | 2011-03-07 03:08:36 +0000 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3340 | /* sync up with fw's ready state */ |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3341 | if (be_physfn(adapter)) { |
| 3342 | status = be_cmd_POST(adapter); |
| 3343 | if (status) |
| 3344 | goto ctrl_clean; |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3345 | } |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3346 | |
| 3347 | /* tell fw we're ready to fire cmds */ |
| 3348 | status = be_cmd_fw_init(adapter); |
| 3349 | if (status) |
| 3350 | goto ctrl_clean; |
| 3351 | |
Ajit Khaparde | a4b4dfa | 2011-02-11 13:36:57 +0000 | [diff] [blame] | 3352 | status = be_cmd_reset_function(adapter); |
| 3353 | if (status) |
| 3354 | goto ctrl_clean; |
Sarveshwar Bandi | 556ae19 | 2010-05-24 18:38:25 -0700 | [diff] [blame] | 3355 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3356 | status = be_stats_init(adapter); |
| 3357 | if (status) |
| 3358 | goto ctrl_clean; |
| 3359 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3360 | status = be_get_config(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3361 | if (status) |
| 3362 | goto stats_clean; |
| 3363 | |
Sathya Perla | b9ab82c | 2011-06-29 23:33:37 +0000 | [diff] [blame] | 3364 | /* The INTR bit may be set in the card when probed by a kdump kernel |
| 3365 | * after a crash. |
| 3366 | */ |
| 3367 | if (!lancer_chip(adapter)) |
| 3368 | be_intr_set(adapter, false); |
| 3369 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3370 | be_msix_enable(adapter); |
| 3371 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3372 | INIT_DELAYED_WORK(&adapter->work, be_worker); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3373 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3374 | status = be_setup(adapter); |
| 3375 | if (status) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3376 | goto msix_disable; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3377 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3378 | be_netdev_init(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3379 | status = register_netdev(netdev); |
| 3380 | if (status != 0) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3381 | goto unsetup; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3382 | |
Ajit Khaparde | e631936 | 2011-02-11 13:35:41 +0000 | [diff] [blame] | 3383 | if (be_physfn(adapter) && adapter->sriov_enabled) { |
Ajit Khaparde | d0381c4 | 2011-04-19 12:11:55 +0000 | [diff] [blame] | 3384 | u8 mac_speed; |
Ajit Khaparde | d0381c4 | 2011-04-19 12:11:55 +0000 | [diff] [blame] | 3385 | u16 vf, lnk_speed; |
| 3386 | |
Mammatha Edhala | 12f4d0a | 2011-05-18 03:26:22 +0000 | [diff] [blame] | 3387 | if (!lancer_chip(adapter)) { |
| 3388 | status = be_vf_eth_addr_config(adapter); |
| 3389 | if (status) |
| 3390 | goto unreg_netdev; |
| 3391 | } |
Ajit Khaparde | d0381c4 | 2011-04-19 12:11:55 +0000 | [diff] [blame] | 3392 | |
| 3393 | for (vf = 0; vf < num_vfs; vf++) { |
Sathya Perla | ea172a0 | 2011-08-02 19:57:42 +0000 | [diff] [blame] | 3394 | status = be_cmd_link_status_query(adapter, &mac_speed, |
| 3395 | &lnk_speed, vf + 1); |
Ajit Khaparde | d0381c4 | 2011-04-19 12:11:55 +0000 | [diff] [blame] | 3396 | if (!status) |
| 3397 | adapter->vf_cfg[vf].vf_tx_rate = lnk_speed * 10; |
| 3398 | else |
| 3399 | goto unreg_netdev; |
| 3400 | } |
Ajit Khaparde | e631936 | 2011-02-11 13:35:41 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 3403 | dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 3404 | |
Somnath Kotur | f203af7 | 2010-10-25 23:01:03 +0000 | [diff] [blame] | 3405 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3406 | return 0; |
| 3407 | |
Ajit Khaparde | e631936 | 2011-02-11 13:35:41 +0000 | [diff] [blame] | 3408 | unreg_netdev: |
| 3409 | unregister_netdev(netdev); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 3410 | unsetup: |
| 3411 | be_clear(adapter); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 3412 | msix_disable: |
| 3413 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3414 | stats_clean: |
| 3415 | be_stats_cleanup(adapter); |
| 3416 | ctrl_clean: |
| 3417 | be_ctrl_cleanup(adapter); |
Ajit Khaparde | 48f5a19 | 2011-04-06 18:08:30 +0000 | [diff] [blame] | 3418 | free_vf_cfg: |
| 3419 | kfree(adapter->vf_cfg); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3420 | free_netdev: |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 3421 | be_sriov_disable(adapter); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 3422 | free_netdev(netdev); |
Sathya Perla | 8d56ff1 | 2009-11-22 22:02:26 +0000 | [diff] [blame] | 3423 | pci_set_drvdata(pdev, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3424 | rel_reg: |
| 3425 | pci_release_regions(pdev); |
| 3426 | disable_dev: |
| 3427 | pci_disable_device(pdev); |
| 3428 | do_none: |
Ajit Khaparde | c4ca237 | 2009-05-18 15:38:55 -0700 | [diff] [blame] | 3429 | dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3430 | return status; |
| 3431 | } |
| 3432 | |
| 3433 | static int be_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3434 | { |
| 3435 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3436 | struct net_device *netdev = adapter->netdev; |
| 3437 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3438 | cancel_delayed_work_sync(&adapter->work); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3439 | if (adapter->wol) |
| 3440 | be_setup_wol(adapter, true); |
| 3441 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3442 | netif_device_detach(netdev); |
| 3443 | if (netif_running(netdev)) { |
| 3444 | rtnl_lock(); |
| 3445 | be_close(netdev); |
| 3446 | rtnl_unlock(); |
| 3447 | } |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 3448 | be_cmd_get_flow_control(adapter, &adapter->tx_fc, &adapter->rx_fc); |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 3449 | be_clear(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3450 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3451 | be_msix_disable(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3452 | pci_save_state(pdev); |
| 3453 | pci_disable_device(pdev); |
| 3454 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3455 | return 0; |
| 3456 | } |
| 3457 | |
| 3458 | static int be_resume(struct pci_dev *pdev) |
| 3459 | { |
| 3460 | int status = 0; |
| 3461 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3462 | struct net_device *netdev = adapter->netdev; |
| 3463 | |
| 3464 | netif_device_detach(netdev); |
| 3465 | |
| 3466 | status = pci_enable_device(pdev); |
| 3467 | if (status) |
| 3468 | return status; |
| 3469 | |
| 3470 | pci_set_power_state(pdev, 0); |
| 3471 | pci_restore_state(pdev); |
| 3472 | |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3473 | be_msix_enable(adapter); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 3474 | /* tell fw we're ready to fire cmds */ |
| 3475 | status = be_cmd_fw_init(adapter); |
| 3476 | if (status) |
| 3477 | return status; |
| 3478 | |
Sarveshwar Bandi | 9b0365f | 2009-08-12 21:01:29 +0000 | [diff] [blame] | 3479 | be_setup(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3480 | if (netif_running(netdev)) { |
| 3481 | rtnl_lock(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3482 | be_open(netdev); |
| 3483 | rtnl_unlock(); |
| 3484 | } |
| 3485 | netif_device_attach(netdev); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3486 | |
| 3487 | if (adapter->wol) |
| 3488 | be_setup_wol(adapter, false); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3489 | |
| 3490 | schedule_delayed_work(&adapter->work, msecs_to_jiffies(100)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3491 | return 0; |
| 3492 | } |
| 3493 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3494 | /* |
| 3495 | * An FLR will stop BE from DMAing any data. |
| 3496 | */ |
| 3497 | static void be_shutdown(struct pci_dev *pdev) |
| 3498 | { |
| 3499 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3500 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 3501 | if (!adapter) |
| 3502 | return; |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3503 | |
Sathya Perla | 0f4a682 | 2011-03-21 20:49:28 +0000 | [diff] [blame] | 3504 | cancel_delayed_work_sync(&adapter->work); |
Ajit Khaparde | a4ca055 | 2011-02-11 13:38:03 +0000 | [diff] [blame] | 3505 | |
Ajit Khaparde | 2d5d415 | 2011-04-06 05:53:13 +0000 | [diff] [blame] | 3506 | netif_device_detach(adapter->netdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3507 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3508 | if (adapter->wol) |
| 3509 | be_setup_wol(adapter, true); |
| 3510 | |
Ajit Khaparde | 5784186 | 2011-04-06 18:08:43 +0000 | [diff] [blame] | 3511 | be_cmd_reset_function(adapter); |
| 3512 | |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3513 | pci_disable_device(pdev); |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3516 | static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev, |
| 3517 | pci_channel_state_t state) |
| 3518 | { |
| 3519 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3520 | struct net_device *netdev = adapter->netdev; |
| 3521 | |
| 3522 | dev_err(&adapter->pdev->dev, "EEH error detected\n"); |
| 3523 | |
| 3524 | adapter->eeh_err = true; |
| 3525 | |
| 3526 | netif_device_detach(netdev); |
| 3527 | |
| 3528 | if (netif_running(netdev)) { |
| 3529 | rtnl_lock(); |
| 3530 | be_close(netdev); |
| 3531 | rtnl_unlock(); |
| 3532 | } |
| 3533 | be_clear(adapter); |
| 3534 | |
| 3535 | if (state == pci_channel_io_perm_failure) |
| 3536 | return PCI_ERS_RESULT_DISCONNECT; |
| 3537 | |
| 3538 | pci_disable_device(pdev); |
| 3539 | |
| 3540 | return PCI_ERS_RESULT_NEED_RESET; |
| 3541 | } |
| 3542 | |
| 3543 | static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev) |
| 3544 | { |
| 3545 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3546 | int status; |
| 3547 | |
| 3548 | dev_info(&adapter->pdev->dev, "EEH reset\n"); |
| 3549 | adapter->eeh_err = false; |
| 3550 | |
| 3551 | status = pci_enable_device(pdev); |
| 3552 | if (status) |
| 3553 | return PCI_ERS_RESULT_DISCONNECT; |
| 3554 | |
| 3555 | pci_set_master(pdev); |
| 3556 | pci_set_power_state(pdev, 0); |
| 3557 | pci_restore_state(pdev); |
| 3558 | |
| 3559 | /* Check if card is ok and fw is ready */ |
| 3560 | status = be_cmd_POST(adapter); |
| 3561 | if (status) |
| 3562 | return PCI_ERS_RESULT_DISCONNECT; |
| 3563 | |
| 3564 | return PCI_ERS_RESULT_RECOVERED; |
| 3565 | } |
| 3566 | |
| 3567 | static void be_eeh_resume(struct pci_dev *pdev) |
| 3568 | { |
| 3569 | int status = 0; |
| 3570 | struct be_adapter *adapter = pci_get_drvdata(pdev); |
| 3571 | struct net_device *netdev = adapter->netdev; |
| 3572 | |
| 3573 | dev_info(&adapter->pdev->dev, "EEH resume\n"); |
| 3574 | |
| 3575 | pci_save_state(pdev); |
| 3576 | |
| 3577 | /* tell fw we're ready to fire cmds */ |
| 3578 | status = be_cmd_fw_init(adapter); |
| 3579 | if (status) |
| 3580 | goto err; |
| 3581 | |
| 3582 | status = be_setup(adapter); |
| 3583 | if (status) |
| 3584 | goto err; |
| 3585 | |
| 3586 | if (netif_running(netdev)) { |
| 3587 | status = be_open(netdev); |
| 3588 | if (status) |
| 3589 | goto err; |
| 3590 | } |
| 3591 | netif_device_attach(netdev); |
| 3592 | return; |
| 3593 | err: |
| 3594 | dev_err(&adapter->pdev->dev, "EEH resume failed\n"); |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static struct pci_error_handlers be_eeh_handlers = { |
| 3598 | .error_detected = be_eeh_err_detected, |
| 3599 | .slot_reset = be_eeh_reset, |
| 3600 | .resume = be_eeh_resume, |
| 3601 | }; |
| 3602 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3603 | static struct pci_driver be_driver = { |
| 3604 | .name = DRV_NAME, |
| 3605 | .id_table = be_dev_ids, |
| 3606 | .probe = be_probe, |
| 3607 | .remove = be_remove, |
| 3608 | .suspend = be_suspend, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3609 | .resume = be_resume, |
Sathya Perla | 82456b0 | 2010-02-17 01:35:37 +0000 | [diff] [blame] | 3610 | .shutdown = be_shutdown, |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 3611 | .err_handler = &be_eeh_handlers |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3612 | }; |
| 3613 | |
| 3614 | static int __init be_init_module(void) |
| 3615 | { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 3616 | if (rx_frag_size != 8192 && rx_frag_size != 4096 && |
| 3617 | rx_frag_size != 2048) { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3618 | printk(KERN_WARNING DRV_NAME |
| 3619 | " : Module param rx_frag_size must be 2048/4096/8192." |
| 3620 | " Using 2048\n"); |
| 3621 | rx_frag_size = 2048; |
| 3622 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3623 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3624 | return pci_register_driver(&be_driver); |
| 3625 | } |
| 3626 | module_init(be_init_module); |
| 3627 | |
| 3628 | static void __exit be_exit_module(void) |
| 3629 | { |
| 3630 | pci_unregister_driver(&be_driver); |
| 3631 | } |
| 3632 | module_exit(be_exit_module); |