Jitendra Kalsaria | 577ae39 | 2013-02-04 12:33:07 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * QLogic qlcnic NIC Driver |
| 3 | * Copyright (c) 2009-2013 QLogic Corporation |
| 4 | * |
| 5 | * See LICENSE.qlcnic for copyright and licensing details. |
| 6 | */ |
| 7 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 8 | #include <linux/netdevice.h> |
| 9 | #include <linux/if_vlan.h> |
| 10 | #include <net/ip.h> |
| 11 | #include <linux/ipv6.h> |
| 12 | |
| 13 | #include "qlcnic.h" |
| 14 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 15 | #define TX_ETHER_PKT 0x01 |
| 16 | #define TX_TCP_PKT 0x02 |
| 17 | #define TX_UDP_PKT 0x03 |
| 18 | #define TX_IP_PKT 0x04 |
| 19 | #define TX_TCP_LSO 0x05 |
| 20 | #define TX_TCP_LSO6 0x06 |
| 21 | #define TX_TCPV6_PKT 0x0b |
| 22 | #define TX_UDPV6_PKT 0x0c |
| 23 | #define FLAGS_VLAN_TAGGED 0x10 |
| 24 | #define FLAGS_VLAN_OOB 0x40 |
| 25 | |
| 26 | #define qlcnic_set_tx_vlan_tci(cmd_desc, v) \ |
| 27 | (cmd_desc)->vlan_TCI = cpu_to_le16(v); |
| 28 | #define qlcnic_set_cmd_desc_port(cmd_desc, var) \ |
| 29 | ((cmd_desc)->port_ctxid |= ((var) & 0x0F)) |
| 30 | #define qlcnic_set_cmd_desc_ctxid(cmd_desc, var) \ |
| 31 | ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0)) |
| 32 | |
| 33 | #define qlcnic_set_tx_port(_desc, _port) \ |
| 34 | ((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0)) |
| 35 | |
| 36 | #define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \ |
| 37 | ((_desc)->flags_opcode |= \ |
| 38 | cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7))) |
| 39 | |
| 40 | #define qlcnic_set_tx_frags_len(_desc, _frags, _len) \ |
| 41 | ((_desc)->nfrags__length = \ |
| 42 | cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8))) |
| 43 | |
| 44 | /* owner bits of status_desc */ |
| 45 | #define STATUS_OWNER_HOST (0x1ULL << 56) |
| 46 | #define STATUS_OWNER_PHANTOM (0x2ULL << 56) |
| 47 | |
| 48 | /* Status descriptor: |
| 49 | 0-3 port, 4-7 status, 8-11 type, 12-27 total_length |
| 50 | 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset |
| 51 | 53-55 desc_cnt, 56-57 owner, 58-63 opcode |
| 52 | */ |
| 53 | #define qlcnic_get_sts_port(sts_data) \ |
| 54 | ((sts_data) & 0x0F) |
| 55 | #define qlcnic_get_sts_status(sts_data) \ |
| 56 | (((sts_data) >> 4) & 0x0F) |
| 57 | #define qlcnic_get_sts_type(sts_data) \ |
| 58 | (((sts_data) >> 8) & 0x0F) |
| 59 | #define qlcnic_get_sts_totallength(sts_data) \ |
| 60 | (((sts_data) >> 12) & 0xFFFF) |
| 61 | #define qlcnic_get_sts_refhandle(sts_data) \ |
| 62 | (((sts_data) >> 28) & 0xFFFF) |
| 63 | #define qlcnic_get_sts_prot(sts_data) \ |
| 64 | (((sts_data) >> 44) & 0x0F) |
| 65 | #define qlcnic_get_sts_pkt_offset(sts_data) \ |
| 66 | (((sts_data) >> 48) & 0x1F) |
| 67 | #define qlcnic_get_sts_desc_cnt(sts_data) \ |
| 68 | (((sts_data) >> 53) & 0x7) |
| 69 | #define qlcnic_get_sts_opcode(sts_data) \ |
| 70 | (((sts_data) >> 58) & 0x03F) |
| 71 | |
| 72 | #define qlcnic_get_lro_sts_refhandle(sts_data) \ |
Sony Chacko | 5796bd0 | 2012-12-04 03:33:57 +0000 | [diff] [blame] | 73 | ((sts_data) & 0x07FFF) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 74 | #define qlcnic_get_lro_sts_length(sts_data) \ |
| 75 | (((sts_data) >> 16) & 0x0FFFF) |
| 76 | #define qlcnic_get_lro_sts_l2_hdr_offset(sts_data) \ |
| 77 | (((sts_data) >> 32) & 0x0FF) |
| 78 | #define qlcnic_get_lro_sts_l4_hdr_offset(sts_data) \ |
| 79 | (((sts_data) >> 40) & 0x0FF) |
| 80 | #define qlcnic_get_lro_sts_timestamp(sts_data) \ |
| 81 | (((sts_data) >> 48) & 0x1) |
| 82 | #define qlcnic_get_lro_sts_type(sts_data) \ |
| 83 | (((sts_data) >> 49) & 0x7) |
| 84 | #define qlcnic_get_lro_sts_push_flag(sts_data) \ |
| 85 | (((sts_data) >> 52) & 0x1) |
| 86 | #define qlcnic_get_lro_sts_seq_number(sts_data) \ |
| 87 | ((sts_data) & 0x0FFFFFFFF) |
| 88 | #define qlcnic_get_lro_sts_mss(sts_data1) \ |
| 89 | ((sts_data1 >> 32) & 0x0FFFF) |
| 90 | |
| 91 | /* opcode field in status_desc */ |
| 92 | #define QLCNIC_SYN_OFFLOAD 0x03 |
| 93 | #define QLCNIC_RXPKT_DESC 0x04 |
| 94 | #define QLCNIC_OLD_RXPKT_DESC 0x3f |
| 95 | #define QLCNIC_RESPONSE_DESC 0x05 |
| 96 | #define QLCNIC_LRO_DESC 0x12 |
| 97 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 98 | #define QLCNIC_TX_POLL_BUDGET 128 |
| 99 | #define QLCNIC_TCP_HDR_SIZE 20 |
| 100 | #define QLCNIC_TCP_TS_OPTION_SIZE 12 |
| 101 | #define QLCNIC_FETCH_RING_ID(handle) ((handle) >> 63) |
| 102 | #define QLCNIC_DESC_OWNER_FW cpu_to_le64(STATUS_OWNER_PHANTOM) |
| 103 | |
| 104 | #define QLCNIC_TCP_TS_HDR_SIZE (QLCNIC_TCP_HDR_SIZE + QLCNIC_TCP_TS_OPTION_SIZE) |
| 105 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 106 | /* for status field in status_desc */ |
| 107 | #define STATUS_CKSUM_LOOP 0 |
| 108 | #define STATUS_CKSUM_OK 2 |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 109 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 110 | #define qlcnic_83xx_pktln(sts) ((sts >> 32) & 0x3FFF) |
| 111 | #define qlcnic_83xx_hndl(sts) ((sts >> 48) & 0x7FFF) |
| 112 | #define qlcnic_83xx_csum_status(sts) ((sts >> 39) & 7) |
| 113 | #define qlcnic_83xx_opcode(sts) ((sts >> 42) & 0xF) |
| 114 | #define qlcnic_83xx_vlan_tag(sts) (((sts) >> 48) & 0xFFFF) |
| 115 | #define qlcnic_83xx_lro_pktln(sts) (((sts) >> 32) & 0x3FFF) |
| 116 | #define qlcnic_83xx_l2_hdr_off(sts) (((sts) >> 16) & 0xFF) |
| 117 | #define qlcnic_83xx_l4_hdr_off(sts) (((sts) >> 24) & 0xFF) |
| 118 | #define qlcnic_83xx_pkt_cnt(sts) (((sts) >> 16) & 0x7) |
| 119 | #define qlcnic_83xx_is_tstamp(sts) (((sts) >> 40) & 1) |
| 120 | #define qlcnic_83xx_is_psh_bit(sts) (((sts) >> 41) & 1) |
| 121 | #define qlcnic_83xx_is_ip_align(sts) (((sts) >> 46) & 1) |
| 122 | #define qlcnic_83xx_has_vlan_tag(sts) (((sts) >> 47) & 1) |
| 123 | |
| 124 | struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *, |
| 125 | struct qlcnic_host_rds_ring *, u16, u16); |
| 126 | |
| 127 | inline void qlcnic_83xx_enable_tx_intr(struct qlcnic_adapter *adapter, |
| 128 | struct qlcnic_host_tx_ring *tx_ring) |
| 129 | { |
| 130 | writel(0, tx_ring->crb_intr_mask); |
| 131 | } |
| 132 | |
| 133 | inline void qlcnic_83xx_disable_tx_intr(struct qlcnic_adapter *adapter, |
| 134 | struct qlcnic_host_tx_ring *tx_ring) |
| 135 | { |
| 136 | writel(1, tx_ring->crb_intr_mask); |
| 137 | } |
| 138 | |
| 139 | static inline u8 qlcnic_mac_hash(u64 mac) |
| 140 | { |
| 141 | return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff)); |
| 142 | } |
| 143 | |
| 144 | static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter, |
| 145 | u16 handle, u8 ring_id) |
| 146 | { |
| 147 | if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) |
| 148 | return handle | (ring_id << 15); |
| 149 | else |
| 150 | return handle; |
| 151 | } |
| 152 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 153 | void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr, |
| 154 | __le16 vlan_id) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 155 | { |
| 156 | struct cmd_desc_type0 *hwdesc; |
| 157 | struct qlcnic_nic_req *req; |
| 158 | struct qlcnic_mac_req *mac_req; |
| 159 | struct qlcnic_vlan_req *vlan_req; |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 160 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 161 | u32 producer; |
| 162 | u64 word; |
| 163 | |
| 164 | producer = tx_ring->producer; |
| 165 | hwdesc = &tx_ring->desc_head[tx_ring->producer]; |
| 166 | |
| 167 | req = (struct qlcnic_nic_req *)hwdesc; |
| 168 | memset(req, 0, sizeof(struct qlcnic_nic_req)); |
| 169 | req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23); |
| 170 | |
| 171 | word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16); |
| 172 | req->req_hdr = cpu_to_le64(word); |
| 173 | |
| 174 | mac_req = (struct qlcnic_mac_req *)&(req->words[0]); |
| 175 | mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD; |
| 176 | memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN); |
| 177 | |
| 178 | vlan_req = (struct qlcnic_vlan_req *)&req->words[1]; |
| 179 | vlan_req->vlan_id = vlan_id; |
| 180 | |
| 181 | tx_ring->producer = get_next_index(producer, tx_ring->num_desc); |
| 182 | smp_mb(); |
| 183 | } |
| 184 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 185 | static void qlcnic_send_filter(struct qlcnic_adapter *adapter, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 186 | struct cmd_desc_type0 *first_desc, |
| 187 | struct sk_buff *skb) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 188 | { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 189 | struct qlcnic_filter *fil, *tmp_fil; |
| 190 | struct hlist_node *tmp_hnode, *n; |
| 191 | struct hlist_head *head; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 192 | struct net_device *netdev = adapter->netdev; |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 193 | struct ethhdr *phdr = (struct ethhdr *)(skb->data); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 194 | u64 src_addr = 0; |
| 195 | __le16 vlan_id = 0; |
| 196 | u8 hindex; |
| 197 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 198 | if (ether_addr_equal(phdr->h_source, adapter->mac_addr)) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 199 | return; |
| 200 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 201 | if (adapter->fhash.fnum >= adapter->fhash.fmax) { |
| 202 | adapter->stats.mac_filter_limit_overrun++; |
| 203 | netdev_info(netdev, "Can not add more than %d mac addresses\n", |
| 204 | adapter->fhash.fmax); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 205 | return; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 206 | } |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 207 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 208 | /* Only NPAR capable devices support vlan based learning */ |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 209 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) |
| 210 | vlan_id = first_desc->vlan_TCI; |
| 211 | memcpy(&src_addr, phdr->h_source, ETH_ALEN); |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 212 | hindex = qlcnic_mac_hash(src_addr) & (adapter->fhash.fbucket_size - 1); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 213 | head = &(adapter->fhash.fhead[hindex]); |
| 214 | |
| 215 | hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { |
| 216 | if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 217 | tmp_fil->vlan_id == vlan_id) { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 218 | if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime)) |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 219 | qlcnic_change_filter(adapter, &src_addr, |
| 220 | vlan_id); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 221 | tmp_fil->ftime = jiffies; |
| 222 | return; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC); |
| 227 | if (!fil) |
| 228 | return; |
| 229 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 230 | qlcnic_change_filter(adapter, &src_addr, vlan_id); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 231 | fil->ftime = jiffies; |
| 232 | fil->vlan_id = vlan_id; |
| 233 | memcpy(fil->faddr, &src_addr, ETH_ALEN); |
| 234 | spin_lock(&adapter->mac_learn_lock); |
| 235 | hlist_add_head(&(fil->fnode), head); |
| 236 | adapter->fhash.fnum++; |
| 237 | spin_unlock(&adapter->mac_learn_lock); |
| 238 | } |
| 239 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 240 | static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter, |
| 241 | struct cmd_desc_type0 *first_desc, struct sk_buff *skb) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 242 | { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 243 | u8 l4proto, opcode = 0, hdr_len = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 244 | u16 flags = 0, vlan_tci = 0; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 245 | int copied, offset, copy_len, size; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 246 | struct cmd_desc_type0 *hwdesc; |
| 247 | struct vlan_ethhdr *vh; |
| 248 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 249 | u16 protocol = ntohs(skb->protocol); |
| 250 | u32 producer = tx_ring->producer; |
| 251 | |
| 252 | if (protocol == ETH_P_8021Q) { |
| 253 | vh = (struct vlan_ethhdr *)skb->data; |
| 254 | flags = FLAGS_VLAN_TAGGED; |
| 255 | vlan_tci = ntohs(vh->h_vlan_TCI); |
| 256 | protocol = ntohs(vh->h_vlan_encapsulated_proto); |
| 257 | } else if (vlan_tx_tag_present(skb)) { |
| 258 | flags = FLAGS_VLAN_OOB; |
| 259 | vlan_tci = vlan_tx_tag_get(skb); |
| 260 | } |
| 261 | if (unlikely(adapter->pvid)) { |
| 262 | if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED)) |
| 263 | return -EIO; |
| 264 | if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED)) |
| 265 | goto set_flags; |
| 266 | |
| 267 | flags = FLAGS_VLAN_OOB; |
| 268 | vlan_tci = adapter->pvid; |
| 269 | } |
| 270 | set_flags: |
| 271 | qlcnic_set_tx_vlan_tci(first_desc, vlan_tci); |
| 272 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); |
| 273 | |
| 274 | if (*(skb->data) & BIT_0) { |
| 275 | flags |= BIT_0; |
| 276 | memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); |
| 277 | } |
| 278 | opcode = TX_ETHER_PKT; |
| 279 | if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 280 | skb_shinfo(skb)->gso_size > 0) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 281 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 282 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 283 | first_desc->total_hdr_length = hdr_len; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 284 | opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO; |
| 285 | |
| 286 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 287 | * the descriptor ring */ |
| 288 | copied = 0; |
| 289 | offset = 2; |
| 290 | |
| 291 | if (flags & FLAGS_VLAN_OOB) { |
| 292 | first_desc->total_hdr_length += VLAN_HLEN; |
| 293 | first_desc->tcp_hdr_offset = VLAN_HLEN; |
| 294 | first_desc->ip_hdr_offset = VLAN_HLEN; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 295 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 296 | /* Only in case of TSO on vlan device */ |
| 297 | flags |= FLAGS_VLAN_TAGGED; |
| 298 | |
| 299 | /* Create a TSO vlan header template for firmware */ |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 300 | hwdesc = &tx_ring->desc_head[producer]; |
| 301 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 302 | |
| 303 | copy_len = min((int)sizeof(struct cmd_desc_type0) - |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 304 | offset, hdr_len + VLAN_HLEN); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 305 | |
| 306 | vh = (struct vlan_ethhdr *)((char *) hwdesc + 2); |
| 307 | skb_copy_from_linear_data(skb, vh, 12); |
| 308 | vh->h_vlan_proto = htons(ETH_P_8021Q); |
| 309 | vh->h_vlan_TCI = htons(vlan_tci); |
| 310 | |
| 311 | skb_copy_from_linear_data_offset(skb, 12, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 312 | (char *)vh + 16, |
| 313 | copy_len - 16); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 314 | copied = copy_len - VLAN_HLEN; |
| 315 | offset = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 316 | producer = get_next_index(producer, tx_ring->num_desc); |
| 317 | } |
| 318 | |
| 319 | while (copied < hdr_len) { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 320 | size = (int)sizeof(struct cmd_desc_type0) - offset; |
| 321 | copy_len = min(size, (hdr_len - copied)); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 322 | hwdesc = &tx_ring->desc_head[producer]; |
| 323 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 324 | skb_copy_from_linear_data_offset(skb, copied, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 325 | (char *)hwdesc + |
| 326 | offset, copy_len); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 327 | copied += copy_len; |
| 328 | offset = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 329 | producer = get_next_index(producer, tx_ring->num_desc); |
| 330 | } |
| 331 | |
| 332 | tx_ring->producer = producer; |
| 333 | smp_mb(); |
| 334 | adapter->stats.lso_frames++; |
| 335 | |
| 336 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 337 | if (protocol == ETH_P_IP) { |
| 338 | l4proto = ip_hdr(skb)->protocol; |
| 339 | |
| 340 | if (l4proto == IPPROTO_TCP) |
| 341 | opcode = TX_TCP_PKT; |
| 342 | else if (l4proto == IPPROTO_UDP) |
| 343 | opcode = TX_UDP_PKT; |
| 344 | } else if (protocol == ETH_P_IPV6) { |
| 345 | l4proto = ipv6_hdr(skb)->nexthdr; |
| 346 | |
| 347 | if (l4proto == IPPROTO_TCP) |
| 348 | opcode = TX_TCPV6_PKT; |
| 349 | else if (l4proto == IPPROTO_UDP) |
| 350 | opcode = TX_UDPV6_PKT; |
| 351 | } |
| 352 | } |
| 353 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
| 354 | first_desc->ip_hdr_offset += skb_network_offset(skb); |
| 355 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 360 | static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb, |
| 361 | struct qlcnic_cmd_buffer *pbuf) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 362 | { |
| 363 | struct qlcnic_skb_frag *nf; |
| 364 | struct skb_frag_struct *frag; |
| 365 | int i, nr_frags; |
| 366 | dma_addr_t map; |
| 367 | |
| 368 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 369 | nf = &pbuf->frag_array[0]; |
| 370 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 371 | map = pci_map_single(pdev, skb->data, skb_headlen(skb), |
| 372 | PCI_DMA_TODEVICE); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 373 | if (pci_dma_mapping_error(pdev, map)) |
| 374 | goto out_err; |
| 375 | |
| 376 | nf->dma = map; |
| 377 | nf->length = skb_headlen(skb); |
| 378 | |
| 379 | for (i = 0; i < nr_frags; i++) { |
| 380 | frag = &skb_shinfo(skb)->frags[i]; |
| 381 | nf = &pbuf->frag_array[i+1]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 382 | map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag), |
| 383 | DMA_TO_DEVICE); |
| 384 | if (dma_mapping_error(&pdev->dev, map)) |
| 385 | goto unwind; |
| 386 | |
| 387 | nf->dma = map; |
| 388 | nf->length = skb_frag_size(frag); |
| 389 | } |
| 390 | |
| 391 | return 0; |
| 392 | |
| 393 | unwind: |
| 394 | while (--i >= 0) { |
| 395 | nf = &pbuf->frag_array[i+1]; |
| 396 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); |
| 397 | } |
| 398 | |
| 399 | nf = &pbuf->frag_array[0]; |
| 400 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); |
| 401 | |
| 402 | out_err: |
| 403 | return -ENOMEM; |
| 404 | } |
| 405 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 406 | static void qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb, |
| 407 | struct qlcnic_cmd_buffer *pbuf) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 408 | { |
| 409 | struct qlcnic_skb_frag *nf = &pbuf->frag_array[0]; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 410 | int i, nr_frags = skb_shinfo(skb)->nr_frags; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 411 | |
| 412 | for (i = 0; i < nr_frags; i++) { |
| 413 | nf = &pbuf->frag_array[i+1]; |
| 414 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); |
| 415 | } |
| 416 | |
| 417 | nf = &pbuf->frag_array[0]; |
| 418 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); |
| 419 | pbuf->skb = NULL; |
| 420 | } |
| 421 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 422 | static inline void qlcnic_clear_cmddesc(u64 *desc) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 423 | { |
| 424 | desc[0] = 0ULL; |
| 425 | desc[2] = 0ULL; |
| 426 | desc[7] = 0ULL; |
| 427 | } |
| 428 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 429 | netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 430 | { |
| 431 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 432 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 433 | struct qlcnic_cmd_buffer *pbuf; |
| 434 | struct qlcnic_skb_frag *buffrag; |
| 435 | struct cmd_desc_type0 *hwdesc, *first_desc; |
| 436 | struct pci_dev *pdev; |
| 437 | struct ethhdr *phdr; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 438 | int i, k, frag_count, delta = 0; |
| 439 | u32 producer, num_txd; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 440 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 441 | num_txd = tx_ring->num_desc; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 442 | |
| 443 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
| 444 | netif_stop_queue(netdev); |
| 445 | return NETDEV_TX_BUSY; |
| 446 | } |
| 447 | |
| 448 | if (adapter->flags & QLCNIC_MACSPOOF) { |
| 449 | phdr = (struct ethhdr *)skb->data; |
| 450 | if (!ether_addr_equal(phdr->h_source, adapter->mac_addr)) |
| 451 | goto drop_packet; |
| 452 | } |
| 453 | |
| 454 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 455 | /* 14 frags supported for normal packet and |
| 456 | * 32 frags supported for TSO packet |
| 457 | */ |
| 458 | if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 459 | for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++) |
| 460 | delta += skb_frag_size(&skb_shinfo(skb)->frags[i]); |
| 461 | |
| 462 | if (!__pskb_pull_tail(skb, delta)) |
| 463 | goto drop_packet; |
| 464 | |
| 465 | frag_count = 1 + skb_shinfo(skb)->nr_frags; |
| 466 | } |
| 467 | |
| 468 | if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { |
| 469 | netif_stop_queue(netdev); |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 470 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 471 | netif_start_queue(netdev); |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 472 | } else { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 473 | adapter->stats.xmit_off++; |
| 474 | return NETDEV_TX_BUSY; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | producer = tx_ring->producer; |
| 479 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 480 | pdev = adapter->pdev; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 481 | first_desc = &tx_ring->desc_head[producer]; |
| 482 | hwdesc = &tx_ring->desc_head[producer]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 483 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 484 | |
| 485 | if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { |
| 486 | adapter->stats.tx_dma_map_error++; |
| 487 | goto drop_packet; |
| 488 | } |
| 489 | |
| 490 | pbuf->skb = skb; |
| 491 | pbuf->frag_count = frag_count; |
| 492 | |
| 493 | qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); |
| 494 | qlcnic_set_tx_port(first_desc, adapter->portnum); |
| 495 | |
| 496 | for (i = 0; i < frag_count; i++) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 497 | k = i % 4; |
| 498 | |
| 499 | if ((k == 0) && (i > 0)) { |
| 500 | /* move to next desc.*/ |
| 501 | producer = get_next_index(producer, num_txd); |
| 502 | hwdesc = &tx_ring->desc_head[producer]; |
| 503 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 504 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 505 | } |
| 506 | |
| 507 | buffrag = &pbuf->frag_array[i]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 508 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); |
| 509 | switch (k) { |
| 510 | case 0: |
| 511 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 512 | break; |
| 513 | case 1: |
| 514 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); |
| 515 | break; |
| 516 | case 2: |
| 517 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); |
| 518 | break; |
| 519 | case 3: |
| 520 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | tx_ring->producer = get_next_index(producer, num_txd); |
| 526 | smp_mb(); |
| 527 | |
| 528 | if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb))) |
| 529 | goto unwind_buff; |
| 530 | |
Jitendra Kalsaria | fe1adc6 | 2013-01-25 10:20:40 +0000 | [diff] [blame] | 531 | if (adapter->drv_mac_learn) |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 532 | qlcnic_send_filter(adapter, first_desc, skb); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 533 | |
| 534 | adapter->stats.txbytes += skb->len; |
| 535 | adapter->stats.xmitcalled++; |
| 536 | |
| 537 | qlcnic_update_cmd_producer(tx_ring); |
| 538 | |
| 539 | return NETDEV_TX_OK; |
| 540 | |
| 541 | unwind_buff: |
| 542 | qlcnic_unmap_buffers(pdev, skb, pbuf); |
| 543 | drop_packet: |
| 544 | adapter->stats.txdropped++; |
| 545 | dev_kfree_skb_any(skb); |
| 546 | return NETDEV_TX_OK; |
| 547 | } |
| 548 | |
Sony Chacko | 7f966452 | 2013-01-01 03:20:19 +0000 | [diff] [blame] | 549 | void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 550 | { |
| 551 | struct net_device *netdev = adapter->netdev; |
| 552 | |
| 553 | if (adapter->ahw->linkup && !linkup) { |
| 554 | netdev_info(netdev, "NIC Link is down\n"); |
| 555 | adapter->ahw->linkup = 0; |
| 556 | if (netif_running(netdev)) { |
| 557 | netif_carrier_off(netdev); |
| 558 | netif_stop_queue(netdev); |
| 559 | } |
| 560 | } else if (!adapter->ahw->linkup && linkup) { |
| 561 | netdev_info(netdev, "NIC Link is up\n"); |
| 562 | adapter->ahw->linkup = 1; |
| 563 | if (netif_running(netdev)) { |
| 564 | netif_carrier_on(netdev); |
| 565 | netif_wake_queue(netdev); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 570 | static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter, |
| 571 | struct qlcnic_host_rds_ring *rds_ring, |
| 572 | struct qlcnic_rx_buffer *buffer) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 573 | { |
| 574 | struct sk_buff *skb; |
| 575 | dma_addr_t dma; |
| 576 | struct pci_dev *pdev = adapter->pdev; |
| 577 | |
| 578 | skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size); |
| 579 | if (!skb) { |
| 580 | adapter->stats.skb_alloc_failure++; |
| 581 | return -ENOMEM; |
| 582 | } |
| 583 | |
| 584 | skb_reserve(skb, NET_IP_ALIGN); |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 585 | dma = pci_map_single(pdev, skb->data, |
| 586 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 587 | |
| 588 | if (pci_dma_mapping_error(pdev, dma)) { |
| 589 | adapter->stats.rx_dma_map_error++; |
| 590 | dev_kfree_skb_any(skb); |
| 591 | return -ENOMEM; |
| 592 | } |
| 593 | |
| 594 | buffer->skb = skb; |
| 595 | buffer->dma = dma; |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter, |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 601 | struct qlcnic_host_rds_ring *rds_ring, |
| 602 | u8 ring_id) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 603 | { |
| 604 | struct rcv_desc *pdesc; |
| 605 | struct qlcnic_rx_buffer *buffer; |
| 606 | int count = 0; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 607 | uint32_t producer, handle; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 608 | struct list_head *head; |
| 609 | |
| 610 | if (!spin_trylock(&rds_ring->lock)) |
| 611 | return; |
| 612 | |
| 613 | producer = rds_ring->producer; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 614 | head = &rds_ring->free_list; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 615 | while (!list_empty(head)) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 616 | buffer = list_entry(head->next, struct qlcnic_rx_buffer, list); |
| 617 | |
| 618 | if (!buffer->skb) { |
| 619 | if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 620 | break; |
| 621 | } |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 622 | count++; |
| 623 | list_del(&buffer->list); |
| 624 | |
| 625 | /* make a rcv descriptor */ |
| 626 | pdesc = &rds_ring->desc_head[producer]; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 627 | handle = qlcnic_get_ref_handle(adapter, |
| 628 | buffer->ref_handle, ring_id); |
| 629 | pdesc->reference_handle = cpu_to_le16(handle); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 630 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
| 631 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 632 | producer = get_next_index(producer, rds_ring->num_desc); |
| 633 | } |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 634 | if (count) { |
| 635 | rds_ring->producer = producer; |
| 636 | writel((producer - 1) & (rds_ring->num_desc - 1), |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 637 | rds_ring->crb_rcv_producer); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 638 | } |
| 639 | spin_unlock(&rds_ring->lock); |
| 640 | } |
| 641 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 642 | static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter, |
| 643 | struct qlcnic_host_tx_ring *tx_ring, |
| 644 | int budget) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 645 | { |
| 646 | u32 sw_consumer, hw_consumer; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 647 | int i, done, count = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 648 | struct qlcnic_cmd_buffer *buffer; |
| 649 | struct pci_dev *pdev = adapter->pdev; |
| 650 | struct net_device *netdev = adapter->netdev; |
| 651 | struct qlcnic_skb_frag *frag; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 652 | |
| 653 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 654 | return 1; |
| 655 | |
| 656 | sw_consumer = tx_ring->sw_consumer; |
| 657 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 658 | |
| 659 | while (sw_consumer != hw_consumer) { |
| 660 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
| 661 | if (buffer->skb) { |
| 662 | frag = &buffer->frag_array[0]; |
| 663 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 664 | PCI_DMA_TODEVICE); |
| 665 | frag->dma = 0ULL; |
| 666 | for (i = 1; i < buffer->frag_count; i++) { |
| 667 | frag++; |
| 668 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 669 | PCI_DMA_TODEVICE); |
| 670 | frag->dma = 0ULL; |
| 671 | } |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 672 | adapter->stats.xmitfinished++; |
| 673 | dev_kfree_skb_any(buffer->skb); |
| 674 | buffer->skb = NULL; |
| 675 | } |
| 676 | |
| 677 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 678 | if (++count >= budget) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 679 | break; |
| 680 | } |
| 681 | |
| 682 | if (count && netif_running(netdev)) { |
| 683 | tx_ring->sw_consumer = sw_consumer; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 684 | smp_mb(); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 685 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
| 686 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { |
| 687 | netif_wake_queue(netdev); |
| 688 | adapter->stats.xmit_on++; |
| 689 | } |
| 690 | } |
| 691 | adapter->tx_timeo_cnt = 0; |
| 692 | } |
| 693 | /* |
| 694 | * If everything is freed up to consumer then check if the ring is full |
| 695 | * If the ring is full then check if more needs to be freed and |
| 696 | * schedule the call back again. |
| 697 | * |
| 698 | * This happens when there are 2 CPUs. One could be freeing and the |
| 699 | * other filling it. If the ring is full when we get out of here and |
| 700 | * the card has already interrupted the host then the host can miss the |
| 701 | * interrupt. |
| 702 | * |
| 703 | * There is still a possible race condition and the host could miss an |
| 704 | * interrupt. The card has to take care of this. |
| 705 | */ |
| 706 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 707 | done = (sw_consumer == hw_consumer); |
| 708 | spin_unlock(&adapter->tx_clean_lock); |
| 709 | |
| 710 | return done; |
| 711 | } |
| 712 | |
| 713 | static int qlcnic_poll(struct napi_struct *napi, int budget) |
| 714 | { |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 715 | int tx_complete, work_done; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 716 | struct qlcnic_host_sds_ring *sds_ring; |
| 717 | struct qlcnic_adapter *adapter; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 718 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 719 | sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 720 | adapter = sds_ring->adapter; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 721 | tx_complete = qlcnic_process_cmd_ring(adapter, adapter->tx_ring, |
| 722 | budget); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 723 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 724 | if ((work_done < budget) && tx_complete) { |
| 725 | napi_complete(&sds_ring->napi); |
| 726 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 727 | qlcnic_enable_int(sds_ring); |
| 728 | } |
| 729 | |
| 730 | return work_done; |
| 731 | } |
| 732 | |
| 733 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget) |
| 734 | { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 735 | struct qlcnic_host_sds_ring *sds_ring; |
| 736 | struct qlcnic_adapter *adapter; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 737 | int work_done; |
| 738 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 739 | sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 740 | adapter = sds_ring->adapter; |
| 741 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 742 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
| 743 | |
| 744 | if (work_done < budget) { |
| 745 | napi_complete(&sds_ring->napi); |
| 746 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 747 | qlcnic_enable_int(sds_ring); |
| 748 | } |
| 749 | |
| 750 | return work_done; |
| 751 | } |
| 752 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 753 | static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter, |
| 754 | struct qlcnic_fw_msg *msg) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 755 | { |
| 756 | u32 cable_OUI; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 757 | u16 cable_len, link_speed; |
| 758 | u8 link_status, module, duplex, autoneg, lb_status = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 759 | struct net_device *netdev = adapter->netdev; |
| 760 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 761 | adapter->ahw->has_link_events = 1; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 762 | |
| 763 | cable_OUI = msg->body[1] & 0xffffffff; |
| 764 | cable_len = (msg->body[1] >> 32) & 0xffff; |
| 765 | link_speed = (msg->body[1] >> 48) & 0xffff; |
| 766 | |
| 767 | link_status = msg->body[2] & 0xff; |
| 768 | duplex = (msg->body[2] >> 16) & 0xff; |
| 769 | autoneg = (msg->body[2] >> 24) & 0xff; |
| 770 | lb_status = (msg->body[2] >> 32) & 0x3; |
| 771 | |
| 772 | module = (msg->body[2] >> 8) & 0xff; |
| 773 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 774 | dev_info(&netdev->dev, |
| 775 | "unsupported cable: OUI 0x%x, length %d\n", |
| 776 | cable_OUI, cable_len); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 777 | else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) |
| 778 | dev_info(&netdev->dev, "unsupported cable length %d\n", |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 779 | cable_len); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 780 | |
| 781 | if (!link_status && (lb_status == QLCNIC_ILB_MODE || |
| 782 | lb_status == QLCNIC_ELB_MODE)) |
| 783 | adapter->ahw->loopback_state |= QLCNIC_LINKEVENT; |
| 784 | |
| 785 | qlcnic_advert_link_change(adapter, link_status); |
| 786 | |
| 787 | if (duplex == LINKEVENT_FULL_DUPLEX) |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 788 | adapter->ahw->link_duplex = DUPLEX_FULL; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 789 | else |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 790 | adapter->ahw->link_duplex = DUPLEX_HALF; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 791 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 792 | adapter->ahw->module_type = module; |
| 793 | adapter->ahw->link_autoneg = autoneg; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 794 | |
| 795 | if (link_status) { |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 796 | adapter->ahw->link_speed = link_speed; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 797 | } else { |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 798 | adapter->ahw->link_speed = SPEED_UNKNOWN; |
| 799 | adapter->ahw->link_duplex = DUPLEX_UNKNOWN; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 803 | static void qlcnic_handle_fw_message(int desc_cnt, int index, |
| 804 | struct qlcnic_host_sds_ring *sds_ring) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 805 | { |
| 806 | struct qlcnic_fw_msg msg; |
| 807 | struct status_desc *desc; |
| 808 | struct qlcnic_adapter *adapter; |
| 809 | struct device *dev; |
| 810 | int i = 0, opcode, ret; |
| 811 | |
| 812 | while (desc_cnt > 0 && i < 8) { |
| 813 | desc = &sds_ring->desc_head[index]; |
| 814 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); |
| 815 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); |
| 816 | |
| 817 | index = get_next_index(index, sds_ring->num_desc); |
| 818 | desc_cnt--; |
| 819 | } |
| 820 | |
| 821 | adapter = sds_ring->adapter; |
| 822 | dev = &adapter->pdev->dev; |
| 823 | opcode = qlcnic_get_nic_msg_opcode(msg.body[0]); |
| 824 | |
| 825 | switch (opcode) { |
| 826 | case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: |
| 827 | qlcnic_handle_linkevent(adapter, &msg); |
| 828 | break; |
| 829 | case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK: |
| 830 | ret = (u32)(msg.body[1]); |
| 831 | switch (ret) { |
| 832 | case 0: |
| 833 | adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE; |
| 834 | break; |
| 835 | case 1: |
| 836 | dev_info(dev, "loopback already in progress\n"); |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 837 | adapter->ahw->diag_cnt = -QLCNIC_TEST_IN_PROGRESS; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 838 | break; |
| 839 | case 2: |
| 840 | dev_info(dev, "loopback cable is not connected\n"); |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 841 | adapter->ahw->diag_cnt = -QLCNIC_LB_CABLE_NOT_CONN; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 842 | break; |
| 843 | default: |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 844 | dev_info(dev, |
| 845 | "loopback configure request failed, err %x\n", |
| 846 | ret); |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 847 | adapter->ahw->diag_cnt = -QLCNIC_UNDEFINED_ERROR; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 848 | break; |
| 849 | } |
| 850 | break; |
| 851 | default: |
| 852 | break; |
| 853 | } |
| 854 | } |
| 855 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 856 | struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter, |
| 857 | struct qlcnic_host_rds_ring *ring, |
| 858 | u16 index, u16 cksum) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 859 | { |
| 860 | struct qlcnic_rx_buffer *buffer; |
| 861 | struct sk_buff *skb; |
| 862 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 863 | buffer = &ring->rx_buf_arr[index]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 864 | if (unlikely(buffer->skb == NULL)) { |
| 865 | WARN_ON(1); |
| 866 | return NULL; |
| 867 | } |
| 868 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 869 | pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 870 | PCI_DMA_FROMDEVICE); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 871 | |
| 872 | skb = buffer->skb; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 873 | if (likely((adapter->netdev->features & NETIF_F_RXCSUM) && |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 874 | (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) { |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 875 | adapter->stats.csummed++; |
| 876 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 877 | } else { |
| 878 | skb_checksum_none_assert(skb); |
| 879 | } |
| 880 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 881 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 882 | buffer->skb = NULL; |
| 883 | |
| 884 | return skb; |
| 885 | } |
| 886 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 887 | static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter, |
| 888 | struct sk_buff *skb, u16 *vlan_tag) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 889 | { |
| 890 | struct ethhdr *eth_hdr; |
| 891 | |
| 892 | if (!__vlan_get_tag(skb, vlan_tag)) { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 893 | eth_hdr = (struct ethhdr *)skb->data; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 894 | memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2); |
| 895 | skb_pull(skb, VLAN_HLEN); |
| 896 | } |
| 897 | if (!adapter->pvid) |
| 898 | return 0; |
| 899 | |
| 900 | if (*vlan_tag == adapter->pvid) { |
| 901 | /* Outer vlan tag. Packet should follow non-vlan path */ |
| 902 | *vlan_tag = 0xffff; |
| 903 | return 0; |
| 904 | } |
| 905 | if (adapter->flags & QLCNIC_TAGGING_ENABLED) |
| 906 | return 0; |
| 907 | |
| 908 | return -EINVAL; |
| 909 | } |
| 910 | |
| 911 | static struct qlcnic_rx_buffer * |
| 912 | qlcnic_process_rcv(struct qlcnic_adapter *adapter, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 913 | struct qlcnic_host_sds_ring *sds_ring, int ring, |
| 914 | u64 sts_data0) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 915 | { |
| 916 | struct net_device *netdev = adapter->netdev; |
| 917 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 918 | struct qlcnic_rx_buffer *buffer; |
| 919 | struct sk_buff *skb; |
| 920 | struct qlcnic_host_rds_ring *rds_ring; |
| 921 | int index, length, cksum, pkt_offset; |
| 922 | u16 vid = 0xffff; |
| 923 | |
| 924 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 925 | return NULL; |
| 926 | |
| 927 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 928 | |
| 929 | index = qlcnic_get_sts_refhandle(sts_data0); |
| 930 | if (unlikely(index >= rds_ring->num_desc)) |
| 931 | return NULL; |
| 932 | |
| 933 | buffer = &rds_ring->rx_buf_arr[index]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 934 | length = qlcnic_get_sts_totallength(sts_data0); |
| 935 | cksum = qlcnic_get_sts_status(sts_data0); |
| 936 | pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0); |
| 937 | |
| 938 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum); |
| 939 | if (!skb) |
| 940 | return buffer; |
| 941 | |
| 942 | if (length > rds_ring->skb_size) |
| 943 | skb_put(skb, rds_ring->skb_size); |
| 944 | else |
| 945 | skb_put(skb, length); |
| 946 | |
| 947 | if (pkt_offset) |
| 948 | skb_pull(skb, pkt_offset); |
| 949 | |
| 950 | if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) { |
| 951 | adapter->stats.rxdropped++; |
| 952 | dev_kfree_skb(skb); |
| 953 | return buffer; |
| 954 | } |
| 955 | |
| 956 | skb->protocol = eth_type_trans(skb, netdev); |
| 957 | |
| 958 | if (vid != 0xffff) |
| 959 | __vlan_hwaccel_put_tag(skb, vid); |
| 960 | |
| 961 | napi_gro_receive(&sds_ring->napi, skb); |
| 962 | |
| 963 | adapter->stats.rx_pkts++; |
| 964 | adapter->stats.rxbytes += length; |
| 965 | |
| 966 | return buffer; |
| 967 | } |
| 968 | |
| 969 | #define QLC_TCP_HDR_SIZE 20 |
| 970 | #define QLC_TCP_TS_OPTION_SIZE 12 |
| 971 | #define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE) |
| 972 | |
| 973 | static struct qlcnic_rx_buffer * |
| 974 | qlcnic_process_lro(struct qlcnic_adapter *adapter, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 975 | int ring, u64 sts_data0, u64 sts_data1) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 976 | { |
| 977 | struct net_device *netdev = adapter->netdev; |
| 978 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 979 | struct qlcnic_rx_buffer *buffer; |
| 980 | struct sk_buff *skb; |
| 981 | struct qlcnic_host_rds_ring *rds_ring; |
| 982 | struct iphdr *iph; |
Shahed Shaikh | 776e7bd | 2013-01-25 10:20:35 +0000 | [diff] [blame] | 983 | struct ipv6hdr *ipv6h; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 984 | struct tcphdr *th; |
| 985 | bool push, timestamp; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 986 | int index, l2_hdr_offset, l4_hdr_offset; |
| 987 | u16 lro_length, length, data_offset, vid = 0xffff; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 988 | u32 seq_number; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 989 | |
| 990 | if (unlikely(ring > adapter->max_rds_rings)) |
| 991 | return NULL; |
| 992 | |
| 993 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 994 | |
| 995 | index = qlcnic_get_lro_sts_refhandle(sts_data0); |
| 996 | if (unlikely(index > rds_ring->num_desc)) |
| 997 | return NULL; |
| 998 | |
| 999 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1000 | |
| 1001 | timestamp = qlcnic_get_lro_sts_timestamp(sts_data0); |
| 1002 | lro_length = qlcnic_get_lro_sts_length(sts_data0); |
| 1003 | l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0); |
| 1004 | l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0); |
| 1005 | push = qlcnic_get_lro_sts_push_flag(sts_data0); |
| 1006 | seq_number = qlcnic_get_lro_sts_seq_number(sts_data1); |
| 1007 | |
| 1008 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1009 | if (!skb) |
| 1010 | return buffer; |
| 1011 | |
| 1012 | if (timestamp) |
| 1013 | data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE; |
| 1014 | else |
| 1015 | data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE; |
| 1016 | |
| 1017 | skb_put(skb, lro_length + data_offset); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1018 | skb_pull(skb, l2_hdr_offset); |
| 1019 | |
| 1020 | if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) { |
| 1021 | adapter->stats.rxdropped++; |
| 1022 | dev_kfree_skb(skb); |
| 1023 | return buffer; |
| 1024 | } |
| 1025 | |
| 1026 | skb->protocol = eth_type_trans(skb, netdev); |
Shahed Shaikh | 776e7bd | 2013-01-25 10:20:35 +0000 | [diff] [blame] | 1027 | |
Shahed Shaikh | 069048f | 2013-01-30 12:47:12 +0000 | [diff] [blame] | 1028 | if (ntohs(skb->protocol) == ETH_P_IPV6) { |
Shahed Shaikh | 776e7bd | 2013-01-25 10:20:35 +0000 | [diff] [blame] | 1029 | ipv6h = (struct ipv6hdr *)skb->data; |
| 1030 | th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr)); |
| 1031 | length = (th->doff << 2) + lro_length; |
| 1032 | ipv6h->payload_len = htons(length); |
| 1033 | } else { |
| 1034 | iph = (struct iphdr *)skb->data; |
| 1035 | th = (struct tcphdr *)(skb->data + (iph->ihl << 2)); |
| 1036 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; |
| 1037 | iph->tot_len = htons(length); |
| 1038 | iph->check = 0; |
| 1039 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 1040 | } |
| 1041 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1042 | th->psh = push; |
| 1043 | th->seq = htonl(seq_number); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1044 | length = skb->len; |
| 1045 | |
| 1046 | if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) |
| 1047 | skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1); |
| 1048 | |
| 1049 | if (vid != 0xffff) |
| 1050 | __vlan_hwaccel_put_tag(skb, vid); |
| 1051 | netif_receive_skb(skb); |
| 1052 | |
| 1053 | adapter->stats.lro_pkts++; |
| 1054 | adapter->stats.lrobytes += length; |
| 1055 | |
| 1056 | return buffer; |
| 1057 | } |
| 1058 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1059 | int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1060 | { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1061 | struct qlcnic_host_rds_ring *rds_ring; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1062 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1063 | struct list_head *cur; |
| 1064 | struct status_desc *desc; |
| 1065 | struct qlcnic_rx_buffer *rxbuf; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1066 | int opcode, desc_cnt, count = 0; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1067 | u64 sts_data0, sts_data1; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1068 | u8 ring; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1069 | u32 consumer = sds_ring->consumer; |
| 1070 | |
| 1071 | while (count < max) { |
| 1072 | desc = &sds_ring->desc_head[consumer]; |
| 1073 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
| 1074 | |
| 1075 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
| 1076 | break; |
| 1077 | |
| 1078 | desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0); |
| 1079 | opcode = qlcnic_get_sts_opcode(sts_data0); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1080 | switch (opcode) { |
| 1081 | case QLCNIC_RXPKT_DESC: |
| 1082 | case QLCNIC_OLD_RXPKT_DESC: |
| 1083 | case QLCNIC_SYN_OFFLOAD: |
| 1084 | ring = qlcnic_get_sts_type(sts_data0); |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1085 | rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring, |
| 1086 | sts_data0); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1087 | break; |
| 1088 | case QLCNIC_LRO_DESC: |
| 1089 | ring = qlcnic_get_lro_sts_type(sts_data0); |
| 1090 | sts_data1 = le64_to_cpu(desc->status_desc_data[1]); |
| 1091 | rxbuf = qlcnic_process_lro(adapter, ring, sts_data0, |
| 1092 | sts_data1); |
| 1093 | break; |
| 1094 | case QLCNIC_RESPONSE_DESC: |
| 1095 | qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1096 | default: |
| 1097 | goto skip; |
| 1098 | } |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1099 | WARN_ON(desc_cnt > 1); |
| 1100 | |
| 1101 | if (likely(rxbuf)) |
| 1102 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
| 1103 | else |
| 1104 | adapter->stats.null_rxbuf++; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1105 | skip: |
| 1106 | for (; desc_cnt > 0; desc_cnt--) { |
| 1107 | desc = &sds_ring->desc_head[consumer]; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1108 | desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1109 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1110 | } |
| 1111 | count++; |
| 1112 | } |
| 1113 | |
| 1114 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1115 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1116 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1117 | list_for_each(cur, &sds_ring->free_list[ring]) { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1118 | rxbuf = list_entry(cur, struct qlcnic_rx_buffer, |
| 1119 | list); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1120 | qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1121 | } |
| 1122 | spin_lock(&rds_ring->lock); |
| 1123 | list_splice_tail_init(&sds_ring->free_list[ring], |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1124 | &rds_ring->free_list); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1125 | spin_unlock(&rds_ring->lock); |
| 1126 | } |
| 1127 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1128 | qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | if (count) { |
| 1132 | sds_ring->consumer = consumer; |
| 1133 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1134 | } |
| 1135 | |
| 1136 | return count; |
| 1137 | } |
| 1138 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1139 | void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1140 | struct qlcnic_host_rds_ring *rds_ring, u8 ring_id) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1141 | { |
| 1142 | struct rcv_desc *pdesc; |
| 1143 | struct qlcnic_rx_buffer *buffer; |
| 1144 | int count = 0; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1145 | u32 producer, handle; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1146 | struct list_head *head; |
| 1147 | |
| 1148 | producer = rds_ring->producer; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1149 | head = &rds_ring->free_list; |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1150 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1151 | while (!list_empty(head)) { |
| 1152 | |
| 1153 | buffer = list_entry(head->next, struct qlcnic_rx_buffer, list); |
| 1154 | |
| 1155 | if (!buffer->skb) { |
| 1156 | if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1157 | break; |
| 1158 | } |
| 1159 | |
| 1160 | count++; |
| 1161 | list_del(&buffer->list); |
| 1162 | |
| 1163 | /* make a rcv descriptor */ |
| 1164 | pdesc = &rds_ring->desc_head[producer]; |
| 1165 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1166 | handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle, |
| 1167 | ring_id); |
| 1168 | pdesc->reference_handle = cpu_to_le16(handle); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1169 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1170 | producer = get_next_index(producer, rds_ring->num_desc); |
| 1171 | } |
| 1172 | |
| 1173 | if (count) { |
| 1174 | rds_ring->producer = producer; |
| 1175 | writel((producer-1) & (rds_ring->num_desc-1), |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1176 | rds_ring->crb_rcv_producer); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter) |
| 1181 | { |
| 1182 | int i; |
| 1183 | unsigned char *data = skb->data; |
| 1184 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1185 | pr_info(KERN_INFO "\n"); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1186 | for (i = 0; i < skb->len; i++) { |
| 1187 | QLCDB(adapter, DRV, "%02x ", data[i]); |
| 1188 | if ((i & 0x0f) == 8) |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1189 | pr_info(KERN_INFO "\n"); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring, |
| 1194 | u64 sts_data0) |
| 1195 | { |
| 1196 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1197 | struct sk_buff *skb; |
| 1198 | struct qlcnic_host_rds_ring *rds_ring; |
| 1199 | int index, length, cksum, pkt_offset; |
| 1200 | |
| 1201 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1202 | return; |
| 1203 | |
| 1204 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1205 | |
| 1206 | index = qlcnic_get_sts_refhandle(sts_data0); |
| 1207 | length = qlcnic_get_sts_totallength(sts_data0); |
| 1208 | if (unlikely(index >= rds_ring->num_desc)) |
| 1209 | return; |
| 1210 | |
| 1211 | cksum = qlcnic_get_sts_status(sts_data0); |
| 1212 | pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0); |
| 1213 | |
| 1214 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1215 | if (!skb) |
| 1216 | return; |
| 1217 | |
| 1218 | if (length > rds_ring->skb_size) |
| 1219 | skb_put(skb, rds_ring->skb_size); |
| 1220 | else |
| 1221 | skb_put(skb, length); |
| 1222 | |
| 1223 | if (pkt_offset) |
| 1224 | skb_pull(skb, pkt_offset); |
| 1225 | |
| 1226 | if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr)) |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1227 | adapter->ahw->diag_cnt++; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1228 | else |
| 1229 | dump_skb(skb, adapter); |
| 1230 | |
| 1231 | dev_kfree_skb_any(skb); |
| 1232 | adapter->stats.rx_pkts++; |
| 1233 | adapter->stats.rxbytes += length; |
| 1234 | |
| 1235 | return; |
| 1236 | } |
| 1237 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 1238 | void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1239 | { |
| 1240 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1241 | struct status_desc *desc; |
| 1242 | u64 sts_data0; |
| 1243 | int ring, opcode, desc_cnt; |
| 1244 | |
| 1245 | u32 consumer = sds_ring->consumer; |
| 1246 | |
| 1247 | desc = &sds_ring->desc_head[consumer]; |
| 1248 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
| 1249 | |
| 1250 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
| 1251 | return; |
| 1252 | |
| 1253 | desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0); |
| 1254 | opcode = qlcnic_get_sts_opcode(sts_data0); |
| 1255 | switch (opcode) { |
| 1256 | case QLCNIC_RESPONSE_DESC: |
| 1257 | qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1258 | break; |
| 1259 | default: |
| 1260 | ring = qlcnic_get_sts_type(sts_data0); |
| 1261 | qlcnic_process_rcv_diag(adapter, ring, sts_data0); |
| 1262 | break; |
| 1263 | } |
| 1264 | |
| 1265 | for (; desc_cnt > 0; desc_cnt--) { |
| 1266 | desc = &sds_ring->desc_head[consumer]; |
| 1267 | desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1268 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1269 | } |
| 1270 | |
| 1271 | sds_ring->consumer = consumer; |
| 1272 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1273 | } |
| 1274 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 1275 | int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter, |
| 1276 | struct net_device *netdev) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1277 | { |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1278 | int ring, max_sds_rings; |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1279 | struct qlcnic_host_sds_ring *sds_ring; |
| 1280 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1281 | |
| 1282 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
| 1283 | return -ENOMEM; |
| 1284 | |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1285 | max_sds_rings = adapter->max_sds_rings; |
| 1286 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1287 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1288 | sds_ring = &recv_ctx->sds_rings[ring]; |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1289 | if (ring == adapter->max_sds_rings - 1) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1290 | netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll, |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1291 | QLCNIC_NETDEV_WEIGHT / max_sds_rings); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1292 | else |
Sony Chacko | d17dd0d | 2012-11-28 04:34:27 +0000 | [diff] [blame] | 1293 | netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll, |
| 1294 | QLCNIC_NETDEV_WEIGHT*2); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1297 | if (qlcnic_alloc_tx_rings(adapter, netdev)) { |
| 1298 | qlcnic_free_sds_rings(recv_ctx); |
| 1299 | return -ENOMEM; |
| 1300 | } |
| 1301 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1305 | void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1306 | { |
| 1307 | int ring; |
| 1308 | struct qlcnic_host_sds_ring *sds_ring; |
| 1309 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1310 | |
| 1311 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1312 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1313 | netif_napi_del(&sds_ring->napi); |
| 1314 | } |
| 1315 | |
| 1316 | qlcnic_free_sds_rings(adapter->recv_ctx); |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1317 | qlcnic_free_tx_rings(adapter); |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 1320 | void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1321 | { |
| 1322 | int ring; |
| 1323 | struct qlcnic_host_sds_ring *sds_ring; |
| 1324 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1325 | |
| 1326 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1327 | return; |
| 1328 | |
| 1329 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1330 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1331 | napi_enable(&sds_ring->napi); |
| 1332 | qlcnic_enable_int(sds_ring); |
| 1333 | } |
| 1334 | } |
| 1335 | |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 1336 | void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter) |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 1337 | { |
| 1338 | int ring; |
| 1339 | struct qlcnic_host_sds_ring *sds_ring; |
| 1340 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1341 | |
| 1342 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1343 | return; |
| 1344 | |
| 1345 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1346 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1347 | qlcnic_disable_int(sds_ring); |
| 1348 | napi_synchronize(&sds_ring->napi); |
| 1349 | napi_disable(&sds_ring->napi); |
| 1350 | } |
| 1351 | } |
Sony Chacko | 4be41e9 | 2013-01-01 03:20:20 +0000 | [diff] [blame] | 1352 | |
| 1353 | static struct qlcnic_rx_buffer * |
| 1354 | qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter, |
| 1355 | struct qlcnic_host_sds_ring *sds_ring, |
| 1356 | u8 ring, u64 sts_data[]) |
| 1357 | { |
| 1358 | struct net_device *netdev = adapter->netdev; |
| 1359 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1360 | struct qlcnic_rx_buffer *buffer; |
| 1361 | struct sk_buff *skb; |
| 1362 | struct qlcnic_host_rds_ring *rds_ring; |
| 1363 | int index, length, cksum; |
| 1364 | u16 vid = 0xffff; |
| 1365 | |
| 1366 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1367 | return NULL; |
| 1368 | |
| 1369 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1370 | |
| 1371 | index = qlcnic_83xx_hndl(sts_data[0]); |
| 1372 | if (unlikely(index >= rds_ring->num_desc)) |
| 1373 | return NULL; |
| 1374 | |
| 1375 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1376 | length = qlcnic_83xx_pktln(sts_data[0]); |
| 1377 | cksum = qlcnic_83xx_csum_status(sts_data[1]); |
| 1378 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1379 | if (!skb) |
| 1380 | return buffer; |
| 1381 | |
| 1382 | if (length > rds_ring->skb_size) |
| 1383 | skb_put(skb, rds_ring->skb_size); |
| 1384 | else |
| 1385 | skb_put(skb, length); |
| 1386 | |
| 1387 | if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) { |
| 1388 | adapter->stats.rxdropped++; |
| 1389 | dev_kfree_skb(skb); |
| 1390 | return buffer; |
| 1391 | } |
| 1392 | |
| 1393 | skb->protocol = eth_type_trans(skb, netdev); |
| 1394 | |
| 1395 | if (vid != 0xffff) |
| 1396 | __vlan_hwaccel_put_tag(skb, vid); |
| 1397 | |
| 1398 | napi_gro_receive(&sds_ring->napi, skb); |
| 1399 | |
| 1400 | adapter->stats.rx_pkts++; |
| 1401 | adapter->stats.rxbytes += length; |
| 1402 | |
| 1403 | return buffer; |
| 1404 | } |
| 1405 | |
| 1406 | static struct qlcnic_rx_buffer * |
| 1407 | qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter, |
| 1408 | u8 ring, u64 sts_data[]) |
| 1409 | { |
| 1410 | struct net_device *netdev = adapter->netdev; |
| 1411 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1412 | struct qlcnic_rx_buffer *buffer; |
| 1413 | struct sk_buff *skb; |
| 1414 | struct qlcnic_host_rds_ring *rds_ring; |
| 1415 | struct iphdr *iph; |
| 1416 | struct ipv6hdr *ipv6h; |
| 1417 | struct tcphdr *th; |
| 1418 | bool push; |
| 1419 | int l2_hdr_offset, l4_hdr_offset; |
| 1420 | int index; |
| 1421 | u16 lro_length, length, data_offset; |
| 1422 | u16 vid = 0xffff; |
| 1423 | |
| 1424 | if (unlikely(ring > adapter->max_rds_rings)) |
| 1425 | return NULL; |
| 1426 | |
| 1427 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1428 | |
| 1429 | index = qlcnic_83xx_hndl(sts_data[0]); |
| 1430 | if (unlikely(index > rds_ring->num_desc)) |
| 1431 | return NULL; |
| 1432 | |
| 1433 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1434 | |
| 1435 | lro_length = qlcnic_83xx_lro_pktln(sts_data[0]); |
| 1436 | l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]); |
| 1437 | l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]); |
| 1438 | push = qlcnic_83xx_is_psh_bit(sts_data[1]); |
| 1439 | |
| 1440 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1441 | if (!skb) |
| 1442 | return buffer; |
| 1443 | if (qlcnic_83xx_is_tstamp(sts_data[1])) |
| 1444 | data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE; |
| 1445 | else |
| 1446 | data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE; |
| 1447 | |
| 1448 | skb_put(skb, lro_length + data_offset); |
| 1449 | skb_pull(skb, l2_hdr_offset); |
| 1450 | |
| 1451 | if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) { |
| 1452 | adapter->stats.rxdropped++; |
| 1453 | dev_kfree_skb(skb); |
| 1454 | return buffer; |
| 1455 | } |
| 1456 | |
| 1457 | skb->protocol = eth_type_trans(skb, netdev); |
| 1458 | if (ntohs(skb->protocol) == ETH_P_IPV6) { |
| 1459 | ipv6h = (struct ipv6hdr *)skb->data; |
| 1460 | th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr)); |
| 1461 | |
| 1462 | length = (th->doff << 2) + lro_length; |
| 1463 | ipv6h->payload_len = htons(length); |
| 1464 | } else { |
| 1465 | iph = (struct iphdr *)skb->data; |
| 1466 | th = (struct tcphdr *)(skb->data + (iph->ihl << 2)); |
| 1467 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; |
| 1468 | iph->tot_len = htons(length); |
| 1469 | iph->check = 0; |
| 1470 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 1471 | } |
| 1472 | |
| 1473 | th->psh = push; |
| 1474 | length = skb->len; |
| 1475 | |
| 1476 | if (vid != 0xffff) |
| 1477 | __vlan_hwaccel_put_tag(skb, vid); |
| 1478 | |
| 1479 | netif_receive_skb(skb); |
| 1480 | |
| 1481 | adapter->stats.lro_pkts++; |
| 1482 | adapter->stats.lrobytes += length; |
| 1483 | return buffer; |
| 1484 | } |
| 1485 | |
| 1486 | static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, |
| 1487 | int max) |
| 1488 | { |
| 1489 | struct qlcnic_host_rds_ring *rds_ring; |
| 1490 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1491 | struct list_head *cur; |
| 1492 | struct status_desc *desc; |
| 1493 | struct qlcnic_rx_buffer *rxbuf = NULL; |
| 1494 | u8 ring; |
| 1495 | u64 sts_data[2]; |
| 1496 | int count = 0, opcode; |
| 1497 | u32 consumer = sds_ring->consumer; |
| 1498 | |
| 1499 | while (count < max) { |
| 1500 | desc = &sds_ring->desc_head[consumer]; |
| 1501 | sts_data[1] = le64_to_cpu(desc->status_desc_data[1]); |
| 1502 | opcode = qlcnic_83xx_opcode(sts_data[1]); |
| 1503 | if (!opcode) |
| 1504 | break; |
| 1505 | sts_data[0] = le64_to_cpu(desc->status_desc_data[0]); |
| 1506 | ring = QLCNIC_FETCH_RING_ID(sts_data[0]); |
| 1507 | |
| 1508 | switch (opcode) { |
| 1509 | case QLC_83XX_REG_DESC: |
| 1510 | rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring, |
| 1511 | ring, sts_data); |
| 1512 | break; |
| 1513 | case QLC_83XX_LRO_DESC: |
| 1514 | rxbuf = qlcnic_83xx_process_lro(adapter, ring, |
| 1515 | sts_data); |
| 1516 | break; |
| 1517 | default: |
| 1518 | dev_info(&adapter->pdev->dev, |
| 1519 | "Unkonwn opcode: 0x%x\n", opcode); |
| 1520 | goto skip; |
| 1521 | } |
| 1522 | |
| 1523 | if (likely(rxbuf)) |
| 1524 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
| 1525 | else |
| 1526 | adapter->stats.null_rxbuf++; |
| 1527 | skip: |
| 1528 | desc = &sds_ring->desc_head[consumer]; |
| 1529 | /* Reset the descriptor */ |
| 1530 | desc->status_desc_data[1] = 0; |
| 1531 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1532 | count++; |
| 1533 | } |
| 1534 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1535 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
| 1536 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1537 | list_for_each(cur, &sds_ring->free_list[ring]) { |
| 1538 | rxbuf = list_entry(cur, struct qlcnic_rx_buffer, |
| 1539 | list); |
| 1540 | qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1541 | } |
| 1542 | spin_lock(&rds_ring->lock); |
| 1543 | list_splice_tail_init(&sds_ring->free_list[ring], |
| 1544 | &rds_ring->free_list); |
| 1545 | spin_unlock(&rds_ring->lock); |
| 1546 | } |
| 1547 | qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring); |
| 1548 | } |
| 1549 | if (count) { |
| 1550 | sds_ring->consumer = consumer; |
| 1551 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1552 | } |
| 1553 | return count; |
| 1554 | } |
| 1555 | |
| 1556 | static int qlcnic_83xx_poll(struct napi_struct *napi, int budget) |
| 1557 | { |
| 1558 | int tx_complete; |
| 1559 | int work_done; |
| 1560 | struct qlcnic_host_sds_ring *sds_ring; |
| 1561 | struct qlcnic_adapter *adapter; |
| 1562 | struct qlcnic_host_tx_ring *tx_ring; |
| 1563 | |
| 1564 | sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 1565 | adapter = sds_ring->adapter; |
| 1566 | /* tx ring count = 1 */ |
| 1567 | tx_ring = adapter->tx_ring; |
| 1568 | |
| 1569 | if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) |
| 1570 | qlcnic_83xx_process_aen(adapter); |
| 1571 | |
| 1572 | tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget); |
| 1573 | work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget); |
| 1574 | if ((work_done < budget) && tx_complete) { |
| 1575 | napi_complete(&sds_ring->napi); |
| 1576 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1577 | qlcnic_83xx_enable_intr(adapter, sds_ring); |
| 1578 | } |
| 1579 | |
| 1580 | return work_done; |
| 1581 | } |
| 1582 | |
| 1583 | static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget) |
| 1584 | { |
| 1585 | int work_done; |
| 1586 | struct qlcnic_host_tx_ring *tx_ring; |
| 1587 | struct qlcnic_adapter *adapter; |
| 1588 | |
| 1589 | budget = QLCNIC_TX_POLL_BUDGET; |
| 1590 | tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi); |
| 1591 | adapter = tx_ring->adapter; |
| 1592 | work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget); |
| 1593 | if (work_done) { |
| 1594 | napi_complete(&tx_ring->napi); |
| 1595 | if (test_bit(__QLCNIC_DEV_UP , &adapter->state)) |
| 1596 | qlcnic_83xx_enable_tx_intr(adapter, tx_ring); |
| 1597 | } |
| 1598 | |
| 1599 | return work_done; |
| 1600 | } |
| 1601 | |
| 1602 | static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget) |
| 1603 | { |
| 1604 | int work_done; |
| 1605 | struct qlcnic_host_sds_ring *sds_ring; |
| 1606 | struct qlcnic_adapter *adapter; |
| 1607 | |
| 1608 | sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 1609 | adapter = sds_ring->adapter; |
| 1610 | work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget); |
| 1611 | if (work_done < budget) { |
| 1612 | napi_complete(&sds_ring->napi); |
| 1613 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1614 | qlcnic_83xx_enable_intr(adapter, sds_ring); |
| 1615 | } |
| 1616 | |
| 1617 | return work_done; |
| 1618 | } |
| 1619 | |
| 1620 | void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter) |
| 1621 | { |
| 1622 | int ring; |
| 1623 | struct qlcnic_host_sds_ring *sds_ring; |
| 1624 | struct qlcnic_host_tx_ring *tx_ring; |
| 1625 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1626 | |
| 1627 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1628 | return; |
| 1629 | |
| 1630 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1631 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1632 | napi_enable(&sds_ring->napi); |
| 1633 | qlcnic_83xx_enable_intr(adapter, sds_ring); |
| 1634 | } |
| 1635 | |
| 1636 | if (adapter->flags & QLCNIC_MSIX_ENABLED) { |
| 1637 | for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { |
| 1638 | tx_ring = &adapter->tx_ring[ring]; |
| 1639 | napi_enable(&tx_ring->napi); |
| 1640 | qlcnic_83xx_enable_tx_intr(adapter, tx_ring); |
| 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter) |
| 1646 | { |
| 1647 | int ring; |
| 1648 | struct qlcnic_host_sds_ring *sds_ring; |
| 1649 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1650 | struct qlcnic_host_tx_ring *tx_ring; |
| 1651 | |
| 1652 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1653 | return; |
| 1654 | |
| 1655 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1656 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1657 | writel(1, sds_ring->crb_intr_mask); |
| 1658 | napi_synchronize(&sds_ring->napi); |
| 1659 | napi_disable(&sds_ring->napi); |
| 1660 | } |
| 1661 | |
| 1662 | if (adapter->flags & QLCNIC_MSIX_ENABLED) { |
| 1663 | for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { |
| 1664 | tx_ring = &adapter->tx_ring[ring]; |
| 1665 | qlcnic_83xx_disable_tx_intr(adapter, tx_ring); |
| 1666 | napi_synchronize(&tx_ring->napi); |
| 1667 | napi_disable(&tx_ring->napi); |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter, |
| 1673 | struct net_device *netdev) |
| 1674 | { |
| 1675 | int ring, max_sds_rings; |
| 1676 | struct qlcnic_host_sds_ring *sds_ring; |
| 1677 | struct qlcnic_host_tx_ring *tx_ring; |
| 1678 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1679 | |
| 1680 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
| 1681 | return -ENOMEM; |
| 1682 | |
| 1683 | max_sds_rings = adapter->max_sds_rings; |
| 1684 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1685 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1686 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 1687 | netif_napi_add(netdev, &sds_ring->napi, |
| 1688 | qlcnic_83xx_rx_poll, |
| 1689 | QLCNIC_NETDEV_WEIGHT * 2); |
| 1690 | else |
| 1691 | netif_napi_add(netdev, &sds_ring->napi, |
| 1692 | qlcnic_83xx_poll, |
| 1693 | QLCNIC_NETDEV_WEIGHT / max_sds_rings); |
| 1694 | } |
| 1695 | |
| 1696 | if (qlcnic_alloc_tx_rings(adapter, netdev)) { |
| 1697 | qlcnic_free_sds_rings(recv_ctx); |
| 1698 | return -ENOMEM; |
| 1699 | } |
| 1700 | |
| 1701 | if (adapter->flags & QLCNIC_MSIX_ENABLED) { |
| 1702 | for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { |
| 1703 | tx_ring = &adapter->tx_ring[ring]; |
| 1704 | netif_napi_add(netdev, &tx_ring->napi, |
| 1705 | qlcnic_83xx_msix_tx_poll, |
| 1706 | QLCNIC_NETDEV_WEIGHT); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
| 1713 | void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter) |
| 1714 | { |
| 1715 | int ring; |
| 1716 | struct qlcnic_host_sds_ring *sds_ring; |
| 1717 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1718 | struct qlcnic_host_tx_ring *tx_ring; |
| 1719 | |
| 1720 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1721 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1722 | netif_napi_del(&sds_ring->napi); |
| 1723 | } |
| 1724 | |
| 1725 | qlcnic_free_sds_rings(adapter->recv_ctx); |
| 1726 | |
| 1727 | if ((adapter->flags & QLCNIC_MSIX_ENABLED)) { |
| 1728 | for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { |
| 1729 | tx_ring = &adapter->tx_ring[ring]; |
| 1730 | netif_napi_del(&tx_ring->napi); |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | qlcnic_free_tx_rings(adapter); |
| 1735 | } |
| 1736 | |
| 1737 | void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter, |
| 1738 | int ring, u64 sts_data[]) |
| 1739 | { |
| 1740 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
| 1741 | struct sk_buff *skb; |
| 1742 | struct qlcnic_host_rds_ring *rds_ring; |
| 1743 | int index, length; |
| 1744 | |
| 1745 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1746 | return; |
| 1747 | |
| 1748 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1749 | index = qlcnic_83xx_hndl(sts_data[0]); |
| 1750 | if (unlikely(index >= rds_ring->num_desc)) |
| 1751 | return; |
| 1752 | |
| 1753 | length = qlcnic_83xx_pktln(sts_data[0]); |
| 1754 | |
| 1755 | skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1756 | if (!skb) |
| 1757 | return; |
| 1758 | |
| 1759 | if (length > rds_ring->skb_size) |
| 1760 | skb_put(skb, rds_ring->skb_size); |
| 1761 | else |
| 1762 | skb_put(skb, length); |
| 1763 | |
| 1764 | if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr)) |
| 1765 | adapter->ahw->diag_cnt++; |
| 1766 | else |
| 1767 | dump_skb(skb, adapter); |
| 1768 | |
| 1769 | dev_kfree_skb_any(skb); |
| 1770 | return; |
| 1771 | } |
| 1772 | |
| 1773 | void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring) |
| 1774 | { |
| 1775 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1776 | struct status_desc *desc; |
| 1777 | u64 sts_data[2]; |
| 1778 | int ring, opcode; |
| 1779 | u32 consumer = sds_ring->consumer; |
| 1780 | |
| 1781 | desc = &sds_ring->desc_head[consumer]; |
| 1782 | sts_data[0] = le64_to_cpu(desc->status_desc_data[0]); |
| 1783 | sts_data[1] = le64_to_cpu(desc->status_desc_data[1]); |
| 1784 | opcode = qlcnic_83xx_opcode(sts_data[1]); |
| 1785 | if (!opcode) |
| 1786 | return; |
| 1787 | |
| 1788 | ring = QLCNIC_FETCH_RING_ID(qlcnic_83xx_hndl(sts_data[0])); |
| 1789 | qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data); |
| 1790 | desc = &sds_ring->desc_head[consumer]; |
| 1791 | desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1792 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1793 | sds_ring->consumer = consumer; |
| 1794 | writel(consumer, sds_ring->crb_sts_consumer); |
| 1795 | } |