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