Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'sfc-tso-v2'

Edward Cree says:

====================
sfc: Firmware-Assisted TSO version 2

The firmware on 8000 series SFC NICs supports a new TSO API ("FATSOv2"), and
7000 series NICs will also support this in an imminent release. This series
adds driver support for this TSO implementation.
The series also removes SWTSO, as it's now equivalent to GSO. This does not
actually remove very much code, because SWTSO was grotesquely intertwingled
with FATSOv1, which will also be removed once 7000 series supports FATSOv2.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+1562 -830
+1 -1
drivers/net/ethernet/sfc/Makefile
··· 1 1 sfc-y += efx.o nic.o farch.o falcon.o siena.o ef10.o tx.o \ 2 2 rx.o selftest.o ethtool.o qt202x_phy.o mdio_10g.o \ 3 3 tenxpress.o txc43128_phy.o falcon_boards.o \ 4 - mcdi.o mcdi_port.o mcdi_mon.o ptp.o 4 + mcdi.o mcdi_port.o mcdi_mon.o ptp.o tx_tso.o 5 5 sfc-$(CONFIG_SFC_MTD) += mtd.o 6 6 sfc-$(CONFIG_SFC_SRIOV) += sriov.o siena_sriov.o ef10_sriov.o 7 7
+149 -9
drivers/net/ethernet/sfc/ef10.c
··· 2086 2086 ER_DZ_TX_DESC_UPD, tx_queue->queue); 2087 2087 } 2088 2088 2089 + /* Add Firmware-Assisted TSO v2 option descriptors to a queue. 2090 + */ 2091 + static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue, 2092 + struct sk_buff *skb, 2093 + bool *data_mapped) 2094 + { 2095 + struct efx_tx_buffer *buffer; 2096 + struct tcphdr *tcp; 2097 + struct iphdr *ip; 2098 + 2099 + u16 ipv4_id; 2100 + u32 seqnum; 2101 + u32 mss; 2102 + 2103 + EFX_BUG_ON_PARANOID(tx_queue->tso_version != 2); 2104 + 2105 + mss = skb_shinfo(skb)->gso_size; 2106 + 2107 + if (unlikely(mss < 4)) { 2108 + WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss); 2109 + return -EINVAL; 2110 + } 2111 + 2112 + ip = ip_hdr(skb); 2113 + if (ip->version == 4) { 2114 + /* Modify IPv4 header if needed. */ 2115 + ip->tot_len = 0; 2116 + ip->check = 0; 2117 + ipv4_id = ip->id; 2118 + } else { 2119 + /* Modify IPv6 header if needed. */ 2120 + struct ipv6hdr *ipv6 = ipv6_hdr(skb); 2121 + 2122 + ipv6->payload_len = 0; 2123 + ipv4_id = 0; 2124 + } 2125 + 2126 + tcp = tcp_hdr(skb); 2127 + seqnum = ntohl(tcp->seq); 2128 + 2129 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 2130 + 2131 + buffer->flags = EFX_TX_BUF_OPTION; 2132 + buffer->len = 0; 2133 + buffer->unmap_len = 0; 2134 + EFX_POPULATE_QWORD_5(buffer->option, 2135 + ESF_DZ_TX_DESC_IS_OPT, 1, 2136 + ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO, 2137 + ESF_DZ_TX_TSO_OPTION_TYPE, 2138 + ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A, 2139 + ESF_DZ_TX_TSO_IP_ID, ipv4_id, 2140 + ESF_DZ_TX_TSO_TCP_SEQNO, seqnum 2141 + ); 2142 + ++tx_queue->insert_count; 2143 + 2144 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 2145 + 2146 + buffer->flags = EFX_TX_BUF_OPTION; 2147 + buffer->len = 0; 2148 + buffer->unmap_len = 0; 2149 + EFX_POPULATE_QWORD_4(buffer->option, 2150 + ESF_DZ_TX_DESC_IS_OPT, 1, 2151 + ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO, 2152 + ESF_DZ_TX_TSO_OPTION_TYPE, 2153 + ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B, 2154 + ESF_DZ_TX_TSO_TCP_MSS, mss 2155 + ); 2156 + ++tx_queue->insert_count; 2157 + 2158 + return 0; 2159 + } 2160 + 2161 + static u32 efx_ef10_tso_versions(struct efx_nic *efx) 2162 + { 2163 + struct efx_ef10_nic_data *nic_data = efx->nic_data; 2164 + u32 tso_versions = 0; 2165 + 2166 + if (nic_data->datapath_caps & 2167 + (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) 2168 + tso_versions |= BIT(1); 2169 + if (nic_data->datapath_caps2 & 2170 + (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) 2171 + tso_versions |= BIT(2); 2172 + return tso_versions; 2173 + } 2174 + 2089 2175 static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) 2090 2176 { 2091 2177 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / ··· 2181 2095 struct efx_channel *channel = tx_queue->channel; 2182 2096 struct efx_nic *efx = tx_queue->efx; 2183 2097 struct efx_ef10_nic_data *nic_data = efx->nic_data; 2098 + bool tso_v2 = false; 2184 2099 size_t inlen; 2185 2100 dma_addr_t dma_addr; 2186 2101 efx_qword_t *txd; ··· 2189 2102 int i; 2190 2103 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0); 2191 2104 2105 + /* TSOv2 is a limited resource that can only be configured on a limited 2106 + * number of queues. TSO without checksum offload is not really a thing, 2107 + * so we only enable it for those queues. 2108 + */ 2109 + if (csum_offload && (nic_data->datapath_caps2 & 2110 + (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) { 2111 + tso_v2 = true; 2112 + netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n", 2113 + channel->channel); 2114 + } 2115 + 2192 2116 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); 2193 2117 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); 2194 2118 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); 2195 2119 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); 2196 - MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, 2197 - INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, 2198 - INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); 2199 2120 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); 2200 2121 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id); 2201 2122 ··· 2219 2124 2220 2125 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); 2221 2126 2222 - rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, 2223 - NULL, 0, NULL); 2224 - if (rc) 2225 - goto fail; 2127 + do { 2128 + MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS, 2129 + /* This flag was removed from mcdi_pcol.h for 2130 + * the non-_EXT version of INIT_TXQ. However, 2131 + * firmware still honours it. 2132 + */ 2133 + INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2, 2134 + INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, 2135 + INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); 2136 + 2137 + rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen, 2138 + NULL, 0, NULL); 2139 + if (rc == -ENOSPC && tso_v2) { 2140 + /* Retry without TSOv2 if we're short on contexts. */ 2141 + tso_v2 = false; 2142 + netif_warn(efx, probe, efx->net_dev, 2143 + "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n"); 2144 + } else if (rc) { 2145 + efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ, 2146 + MC_CMD_INIT_TXQ_EXT_IN_LEN, 2147 + NULL, 0, rc); 2148 + goto fail; 2149 + } 2150 + } while (rc); 2226 2151 2227 2152 /* A previous user of this TX queue might have set us up the 2228 2153 * bomb by writing a descriptor to the TX push collector but ··· 2261 2146 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); 2262 2147 tx_queue->write_count = 1; 2263 2148 2264 - if (nic_data->datapath_caps & 2265 - (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) { 2149 + if (tso_v2) { 2150 + tx_queue->handle_tso = efx_ef10_tx_tso_desc; 2151 + tx_queue->tso_version = 2; 2152 + } else if (nic_data->datapath_caps & 2153 + (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) { 2266 2154 tx_queue->tso_version = 1; 2267 2155 } 2268 2156 ··· 2318 2200 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); 2319 2201 efx_writed_page(tx_queue->efx, &reg, 2320 2202 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); 2203 + } 2204 + 2205 + #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff 2206 + 2207 + static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue, 2208 + dma_addr_t dma_addr, unsigned int len) 2209 + { 2210 + if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) { 2211 + /* If we need to break across multiple descriptors we should 2212 + * stop at a page boundary. This assumes the length limit is 2213 + * greater than the page size. 2214 + */ 2215 + dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN; 2216 + 2217 + BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE); 2218 + len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr; 2219 + } 2220 + 2221 + return len; 2321 2222 } 2322 2223 2323 2224 static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) ··· 5606 5469 .tx_init = efx_ef10_tx_init, 5607 5470 .tx_remove = efx_ef10_tx_remove, 5608 5471 .tx_write = efx_ef10_tx_write, 5472 + .tx_limit_len = efx_ef10_tx_limit_len, 5609 5473 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config, 5610 5474 .rx_probe = efx_ef10_rx_probe, 5611 5475 .rx_init = efx_ef10_rx_init, ··· 5713 5575 .tx_init = efx_ef10_tx_init, 5714 5576 .tx_remove = efx_ef10_tx_remove, 5715 5577 .tx_write = efx_ef10_tx_write, 5578 + .tx_limit_len = efx_ef10_tx_limit_len, 5716 5579 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config, 5717 5580 .rx_probe = efx_ef10_rx_probe, 5718 5581 .rx_init = efx_ef10_rx_init, ··· 5773 5634 #endif 5774 5635 .get_mac_address = efx_ef10_get_mac_address_pf, 5775 5636 .set_mac_address = efx_ef10_set_mac_address, 5637 + .tso_versions = efx_ef10_tso_versions, 5776 5638 5777 5639 .revision = EFX_REV_HUNT_A0, 5778 5640 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
+88 -15
drivers/net/ethernet/sfc/ef10_regs.h
··· 1 1 /**************************************************************************** 2 2 * Driver for Solarflare network controllers and boards 3 - * Copyright 2012-2013 Solarflare Communications Inc. 3 + * Copyright 2012-2015 Solarflare Communications Inc. 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify it 6 6 * under the terms of the GNU General Public License version 2 as published ··· 147 147 #define ESF_DZ_RX_OVERRIDE_HOLDOFF_WIDTH 1 148 148 #define ESF_DZ_RX_DROP_EVENT_LBN 58 149 149 #define ESF_DZ_RX_DROP_EVENT_WIDTH 1 150 - #define ESF_DZ_RX_EV_RSVD2_LBN 54 151 - #define ESF_DZ_RX_EV_RSVD2_WIDTH 4 150 + #define ESF_DD_RX_EV_RSVD2_LBN 54 151 + #define ESF_DD_RX_EV_RSVD2_WIDTH 4 152 + #define ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR_LBN 57 153 + #define ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR_WIDTH 1 154 + #define ESF_EZ_RX_IP_INNER_CHKSUM_ERR_LBN 56 155 + #define ESF_EZ_RX_IP_INNER_CHKSUM_ERR_WIDTH 1 156 + #define ESF_EZ_RX_EV_RSVD2_LBN 54 157 + #define ESF_EZ_RX_EV_RSVD2_WIDTH 2 152 158 #define ESF_DZ_RX_EV_SOFT2_LBN 52 153 159 #define ESF_DZ_RX_EV_SOFT2_WIDTH 2 154 160 #define ESF_DZ_RX_DSC_PTR_LBITS_LBN 48 ··· 198 192 #define ESF_DZ_RX_MAC_CLASS_WIDTH 1 199 193 #define ESE_DZ_MAC_CLASS_MCAST 1 200 194 #define ESE_DZ_MAC_CLASS_UCAST 0 201 - #define ESF_DZ_RX_EV_SOFT1_LBN 32 202 - #define ESF_DZ_RX_EV_SOFT1_WIDTH 3 203 - #define ESF_DZ_RX_EV_RSVD1_LBN 31 204 - #define ESF_DZ_RX_EV_RSVD1_WIDTH 1 205 - #define ESF_DZ_RX_ABORT_LBN 30 206 - #define ESF_DZ_RX_ABORT_WIDTH 1 195 + #define ESF_DD_RX_EV_SOFT1_LBN 32 196 + #define ESF_DD_RX_EV_SOFT1_WIDTH 3 197 + #define ESF_EZ_RX_EV_SOFT1_LBN 34 198 + #define ESF_EZ_RX_EV_SOFT1_WIDTH 1 199 + #define ESF_EZ_RX_ENCAP_HDR_LBN 32 200 + #define ESF_EZ_RX_ENCAP_HDR_WIDTH 2 201 + #define ESE_EZ_ENCAP_HDR_GRE 2 202 + #define ESE_EZ_ENCAP_HDR_VXLAN 1 203 + #define ESE_EZ_ENCAP_HDR_NONE 0 204 + #define ESF_DD_RX_EV_RSVD1_LBN 30 205 + #define ESF_DD_RX_EV_RSVD1_WIDTH 2 206 + #define ESF_EZ_RX_EV_RSVD1_LBN 31 207 + #define ESF_EZ_RX_EV_RSVD1_WIDTH 1 208 + #define ESF_EZ_RX_ABORT_LBN 30 209 + #define ESF_EZ_RX_ABORT_WIDTH 1 207 210 #define ESF_DZ_RX_ECC_ERR_LBN 29 208 211 #define ESF_DZ_RX_ECC_ERR_WIDTH 1 209 212 #define ESF_DZ_RX_CRC1_ERR_LBN 28 ··· 250 235 #define ESE_DZ_TX_OPTION_DESC_TSO 7 251 236 #define ESE_DZ_TX_OPTION_DESC_VLAN 6 252 237 #define ESE_DZ_TX_OPTION_DESC_CRC_CSUM 0 238 + #define ESF_DZ_TX_OPTION_TS_AT_TXDP_LBN 8 239 + #define ESF_DZ_TX_OPTION_TS_AT_TXDP_WIDTH 1 240 + #define ESF_DZ_TX_OPTION_INNER_UDP_TCP_CSUM_LBN 7 241 + #define ESF_DZ_TX_OPTION_INNER_UDP_TCP_CSUM_WIDTH 1 242 + #define ESF_DZ_TX_OPTION_INNER_IP_CSUM_LBN 6 243 + #define ESF_DZ_TX_OPTION_INNER_IP_CSUM_WIDTH 1 253 244 #define ESF_DZ_TX_TIMESTAMP_LBN 5 254 245 #define ESF_DZ_TX_TIMESTAMP_WIDTH 1 255 246 #define ESF_DZ_TX_OPTION_CRC_MODE_LBN 2 ··· 278 257 #define ESF_DZ_TX_OVERRIDE_HOLDOFF_WIDTH 1 279 258 #define ESF_DZ_TX_DROP_EVENT_LBN 58 280 259 #define ESF_DZ_TX_DROP_EVENT_WIDTH 1 281 - #define ESF_DZ_TX_EV_RSVD_LBN 48 282 - #define ESF_DZ_TX_EV_RSVD_WIDTH 10 260 + #define ESF_DD_TX_EV_RSVD_LBN 48 261 + #define ESF_DD_TX_EV_RSVD_WIDTH 10 262 + #define ESF_EZ_TCP_UDP_INNER_CHKSUM_ERR_LBN 57 263 + #define ESF_EZ_TCP_UDP_INNER_CHKSUM_ERR_WIDTH 1 264 + #define ESF_EZ_IP_INNER_CHKSUM_ERR_LBN 56 265 + #define ESF_EZ_IP_INNER_CHKSUM_ERR_WIDTH 1 266 + #define ESF_EZ_TX_EV_RSVD_LBN 48 267 + #define ESF_EZ_TX_EV_RSVD_WIDTH 8 283 268 #define ESF_DZ_TX_SOFT2_LBN 32 284 269 #define ESF_DZ_TX_SOFT2_WIDTH 16 285 - #define ESF_DZ_TX_CAN_MERGE_LBN 31 286 - #define ESF_DZ_TX_CAN_MERGE_WIDTH 1 287 - #define ESF_DZ_TX_SOFT1_LBN 24 288 - #define ESF_DZ_TX_SOFT1_WIDTH 7 270 + #define ESF_DD_TX_SOFT1_LBN 24 271 + #define ESF_DD_TX_SOFT1_WIDTH 8 272 + #define ESF_EZ_TX_CAN_MERGE_LBN 31 273 + #define ESF_EZ_TX_CAN_MERGE_WIDTH 1 274 + #define ESF_EZ_TX_SOFT1_LBN 24 275 + #define ESF_EZ_TX_SOFT1_WIDTH 7 289 276 #define ESF_DZ_TX_QLABEL_LBN 16 290 277 #define ESF_DZ_TX_QLABEL_WIDTH 5 291 278 #define ESF_DZ_TX_DESCR_INDX_LBN 0 ··· 330 301 #define ESE_DZ_TX_OPTION_DESC_TSO 7 331 302 #define ESE_DZ_TX_OPTION_DESC_VLAN 6 332 303 #define ESE_DZ_TX_OPTION_DESC_CRC_CSUM 0 304 + #define ESF_DZ_TX_TSO_OPTION_TYPE_LBN 56 305 + #define ESF_DZ_TX_TSO_OPTION_TYPE_WIDTH 4 306 + #define ESE_DZ_TX_TSO_OPTION_DESC_ENCAP 1 307 + #define ESE_DZ_TX_TSO_OPTION_DESC_NORMAL 0 333 308 #define ESF_DZ_TX_TSO_TCP_FLAGS_LBN 48 334 309 #define ESF_DZ_TX_TSO_TCP_FLAGS_WIDTH 8 335 310 #define ESF_DZ_TX_TSO_IP_ID_LBN 32 336 311 #define ESF_DZ_TX_TSO_IP_ID_WIDTH 16 337 312 #define ESF_DZ_TX_TSO_TCP_SEQNO_LBN 0 338 313 #define ESF_DZ_TX_TSO_TCP_SEQNO_WIDTH 32 314 + 315 + /* TX_TSO_FATSO2A_DESC */ 316 + #define ESF_DZ_TX_DESC_IS_OPT_LBN 63 317 + #define ESF_DZ_TX_DESC_IS_OPT_WIDTH 1 318 + #define ESF_DZ_TX_OPTION_TYPE_LBN 60 319 + #define ESF_DZ_TX_OPTION_TYPE_WIDTH 3 320 + #define ESE_DZ_TX_OPTION_DESC_TSO 7 321 + #define ESE_DZ_TX_OPTION_DESC_VLAN 6 322 + #define ESE_DZ_TX_OPTION_DESC_CRC_CSUM 0 323 + #define ESF_DZ_TX_TSO_OPTION_TYPE_LBN 56 324 + #define ESF_DZ_TX_TSO_OPTION_TYPE_WIDTH 4 325 + #define ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B 3 326 + #define ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A 2 327 + #define ESE_DZ_TX_TSO_OPTION_DESC_ENCAP 1 328 + #define ESE_DZ_TX_TSO_OPTION_DESC_NORMAL 0 329 + #define ESF_DZ_TX_TSO_IP_ID_LBN 32 330 + #define ESF_DZ_TX_TSO_IP_ID_WIDTH 16 331 + #define ESF_DZ_TX_TSO_TCP_SEQNO_LBN 0 332 + #define ESF_DZ_TX_TSO_TCP_SEQNO_WIDTH 32 333 + 334 + 335 + /* TX_TSO_FATSO2B_DESC */ 336 + #define ESF_DZ_TX_DESC_IS_OPT_LBN 63 337 + #define ESF_DZ_TX_DESC_IS_OPT_WIDTH 1 338 + #define ESF_DZ_TX_OPTION_TYPE_LBN 60 339 + #define ESF_DZ_TX_OPTION_TYPE_WIDTH 3 340 + #define ESE_DZ_TX_OPTION_DESC_TSO 7 341 + #define ESE_DZ_TX_OPTION_DESC_VLAN 6 342 + #define ESE_DZ_TX_OPTION_DESC_CRC_CSUM 0 343 + #define ESF_DZ_TX_TSO_OPTION_TYPE_LBN 56 344 + #define ESF_DZ_TX_TSO_OPTION_TYPE_WIDTH 4 345 + #define ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B 3 346 + #define ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A 2 347 + #define ESE_DZ_TX_TSO_OPTION_DESC_ENCAP 1 348 + #define ESE_DZ_TX_TSO_OPTION_DESC_NORMAL 0 349 + #define ESF_DZ_TX_TSO_OUTER_IP_ID_LBN 0 350 + #define ESF_DZ_TX_TSO_OUTER_IP_ID_WIDTH 16 351 + #define ESF_DZ_TX_TSO_TCP_MSS_LBN 32 352 + #define ESF_DZ_TX_TSO_TCP_MSS_WIDTH 16 353 + 339 354 340 355 /*************************************************************************/ 341 356
+21 -17
drivers/net/ethernet/sfc/efx.c
··· 3200 3200 efx = netdev_priv(net_dev); 3201 3201 efx->type = (const struct efx_nic_type *) entry->driver_data; 3202 3202 efx->fixed_features |= NETIF_F_HIGHDMA; 3203 - net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 3204 - NETIF_F_TSO | NETIF_F_RXCSUM); 3205 - if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) 3206 - net_dev->features |= NETIF_F_TSO6; 3207 - /* Mask for features that also apply to VLAN devices */ 3208 - net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 3209 - NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 3210 - NETIF_F_RXCSUM); 3211 - 3212 - net_dev->hw_features = net_dev->features & ~efx->fixed_features; 3213 - 3214 - /* Disable VLAN filtering by default. It may be enforced if 3215 - * the feature is fixed (i.e. VLAN filters are required to 3216 - * receive VLAN tagged packets due to vPort restrictions). 3217 - */ 3218 - net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 3219 - net_dev->features |= efx->fixed_features; 3220 3203 3221 3204 pci_set_drvdata(pci_dev, efx); 3222 3205 SET_NETDEV_DEV(net_dev, &pci_dev->dev); ··· 3221 3238 rc = efx_pci_probe_main(efx); 3222 3239 if (rc) 3223 3240 goto fail3; 3241 + 3242 + net_dev->features |= (efx->type->offload_features | NETIF_F_SG | 3243 + NETIF_F_TSO | NETIF_F_RXCSUM); 3244 + if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) 3245 + net_dev->features |= NETIF_F_TSO6; 3246 + /* Check whether device supports TSO */ 3247 + if (!efx->type->tso_versions || !efx->type->tso_versions(efx)) 3248 + net_dev->features &= ~NETIF_F_ALL_TSO; 3249 + /* Mask for features that also apply to VLAN devices */ 3250 + net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | 3251 + NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | 3252 + NETIF_F_RXCSUM); 3253 + 3254 + net_dev->hw_features = net_dev->features & ~efx->fixed_features; 3255 + 3256 + /* Disable VLAN filtering by default. It may be enforced if 3257 + * the feature is fixed (i.e. VLAN filters are required to 3258 + * receive VLAN tagged packets due to vPort restrictions). 3259 + */ 3260 + net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 3261 + net_dev->features |= efx->fixed_features; 3224 3262 3225 3263 rc = efx_register_netdev(efx); 3226 3264 if (rc)
+2
drivers/net/ethernet/sfc/ethtool.c
··· 69 69 EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), 70 70 EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), 71 71 EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), 72 + EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks), 72 73 EFX_ETHTOOL_UINT_TXQ_STAT(pushes), 73 74 EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), 75 + EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), 74 76 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), 75 77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), 76 78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
+2
drivers/net/ethernet/sfc/falcon.c
··· 2750 2750 .tx_init = efx_farch_tx_init, 2751 2751 .tx_remove = efx_farch_tx_remove, 2752 2752 .tx_write = efx_farch_tx_write, 2753 + .tx_limit_len = efx_farch_tx_limit_len, 2753 2754 .rx_push_rss_config = dummy_rx_push_rss_config, 2754 2755 .rx_probe = efx_farch_rx_probe, 2755 2756 .rx_init = efx_farch_rx_init, ··· 2850 2849 .tx_init = efx_farch_tx_init, 2851 2850 .tx_remove = efx_farch_tx_remove, 2852 2851 .tx_write = efx_farch_tx_write, 2852 + .tx_limit_len = efx_farch_tx_limit_len, 2853 2853 .rx_push_rss_config = falcon_b0_rx_push_rss_config, 2854 2854 .rx_probe = efx_farch_rx_probe, 2855 2855 .rx_init = efx_farch_rx_init,
+15
drivers/net/ethernet/sfc/farch.c
··· 356 356 } 357 357 } 358 358 359 + unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue, 360 + dma_addr_t dma_addr, unsigned int len) 361 + { 362 + /* Don't cross 4K boundaries with descriptors. */ 363 + unsigned int limit = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1; 364 + 365 + len = min(limit, len); 366 + 367 + if (EFX_WORKAROUND_5391(tx_queue->efx) && (dma_addr & 0xf)) 368 + len = min_t(unsigned int, len, 512 - (dma_addr & 0xf)); 369 + 370 + return len; 371 + } 372 + 373 + 359 374 /* Allocate hardware resources for a TX queue */ 360 375 int efx_farch_tx_probe(struct efx_tx_queue *tx_queue) 361 376 {
+462 -21
drivers/net/ethernet/sfc/mcdi_pcol.h
··· 276 276 /* The clock whose frequency you've attempted to set set 277 277 * doesn't exist on this NIC */ 278 278 #define MC_CMD_ERR_NO_CLOCK 0x1015 279 + /* Returned by MC_CMD_TESTASSERT if the action that should 280 + * have caused an assertion failed to do so. */ 281 + #define MC_CMD_ERR_UNREACHABLE 0x1016 279 282 280 283 #define MC_CMD_ERR_CODE_OFST 0 281 284 ··· 936 933 #define MC_CMD_COPYCODE_IN_BOOT_MAGIC_SKIP_BOOT_ICORE_SYNC_WIDTH 1 937 934 #define MC_CMD_COPYCODE_IN_BOOT_MAGIC_FORCE_STANDALONE_LBN 5 938 935 #define MC_CMD_COPYCODE_IN_BOOT_MAGIC_FORCE_STANDALONE_WIDTH 1 936 + #define MC_CMD_COPYCODE_IN_BOOT_MAGIC_DISABLE_XIP_LBN 6 937 + #define MC_CMD_COPYCODE_IN_BOOT_MAGIC_DISABLE_XIP_WIDTH 1 939 938 /* Destination address */ 940 939 #define MC_CMD_COPYCODE_IN_DEST_ADDR_OFST 4 941 940 #define MC_CMD_COPYCODE_IN_NUMWORDS_OFST 8 ··· 1664 1659 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_CAPABILITIES_OFST 8 1665 1660 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_REPORT_SYNC_STATUS_LBN 0 1666 1661 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_REPORT_SYNC_STATUS_WIDTH 1 1662 + #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_RX_TSTAMP_OOB_LBN 1 1663 + #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_RX_TSTAMP_OOB_WIDTH 1 1667 1664 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_RESERVED0_OFST 12 1668 1665 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_RESERVED1_OFST 16 1669 1666 #define MC_CMD_PTP_OUT_GET_ATTRIBUTES_RESERVED2_OFST 20 ··· 2218 2211 #define MC_CMD_FW_HIGH_TX_RATE 0x3 2219 2212 /* enum: Reserved value */ 2220 2213 #define MC_CMD_FW_PACKED_STREAM_HASH_MODE_1 0x4 2214 + /* enum: Prefer to use firmware with additional "rules engine" filtering 2215 + * support 2216 + */ 2217 + #define MC_CMD_FW_RULES_ENGINE 0x5 2221 2218 /* enum: Only this option is allowed for non-admin functions */ 2222 2219 #define MC_CMD_FW_DONT_CARE 0xffffffff 2223 2220 ··· 3665 3654 3666 3655 #define MC_CMD_0x38_PRIVILEGE_CTG SRIOV_CTG_ADMIN 3667 3656 3668 - /* MC_CMD_NVRAM_UPDATE_START_IN msgrequest */ 3657 + /* MC_CMD_NVRAM_UPDATE_START_IN msgrequest: Legacy NVRAM_UPDATE_START request. 3658 + * Use NVRAM_UPDATE_START_V2_IN in new code 3659 + */ 3669 3660 #define MC_CMD_NVRAM_UPDATE_START_IN_LEN 4 3670 3661 #define MC_CMD_NVRAM_UPDATE_START_IN_TYPE_OFST 0 3671 3662 /* Enum values, see field(s): */ 3672 3663 /* MC_CMD_NVRAM_TYPES/MC_CMD_NVRAM_TYPES_OUT/TYPES */ 3664 + 3665 + /* MC_CMD_NVRAM_UPDATE_START_V2_IN msgrequest: Extended NVRAM_UPDATE_START 3666 + * request with additional flags indicating version of command in use. See 3667 + * MC_CMD_NVRAM_UPDATE_FINISH_V2_OUT for details of extended functionality. Use 3668 + * paired up with NVRAM_UPDATE_FINISH_V2_IN. 3669 + */ 3670 + #define MC_CMD_NVRAM_UPDATE_START_V2_IN_LEN 8 3671 + #define MC_CMD_NVRAM_UPDATE_START_V2_IN_TYPE_OFST 0 3672 + /* Enum values, see field(s): */ 3673 + /* MC_CMD_NVRAM_TYPES/MC_CMD_NVRAM_TYPES_OUT/TYPES */ 3674 + #define MC_CMD_NVRAM_UPDATE_START_V2_IN_FLAGS_OFST 4 3675 + #define MC_CMD_NVRAM_UPDATE_START_V2_IN_FLAG_REPORT_VERIFY_RESULT_LBN 0 3676 + #define MC_CMD_NVRAM_UPDATE_START_V2_IN_FLAG_REPORT_VERIFY_RESULT_WIDTH 1 3673 3677 3674 3678 /* MC_CMD_NVRAM_UPDATE_START_OUT msgresponse */ 3675 3679 #define MC_CMD_NVRAM_UPDATE_START_OUT_LEN 0 ··· 3810 3784 3811 3785 #define MC_CMD_0x3c_PRIVILEGE_CTG SRIOV_CTG_ADMIN 3812 3786 3813 - /* MC_CMD_NVRAM_UPDATE_FINISH_IN msgrequest */ 3787 + /* MC_CMD_NVRAM_UPDATE_FINISH_IN msgrequest: Legacy NVRAM_UPDATE_FINISH 3788 + * request. Use NVRAM_UPDATE_FINISH_V2_IN in new code 3789 + */ 3814 3790 #define MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN 8 3815 3791 #define MC_CMD_NVRAM_UPDATE_FINISH_IN_TYPE_OFST 0 3816 3792 /* Enum values, see field(s): */ 3817 3793 /* MC_CMD_NVRAM_TYPES/MC_CMD_NVRAM_TYPES_OUT/TYPES */ 3818 3794 #define MC_CMD_NVRAM_UPDATE_FINISH_IN_REBOOT_OFST 4 3819 3795 3820 - /* MC_CMD_NVRAM_UPDATE_FINISH_OUT msgresponse */ 3796 + /* MC_CMD_NVRAM_UPDATE_FINISH_V2_IN msgrequest: Extended NVRAM_UPDATE_FINISH 3797 + * request with additional flags indicating version of NVRAM_UPDATE commands in 3798 + * use. See MC_CMD_NVRAM_UPDATE_FINISH_V2_OUT for details of extended 3799 + * functionality. Use paired up with NVRAM_UPDATE_START_V2_IN. 3800 + */ 3801 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_LEN 12 3802 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_TYPE_OFST 0 3803 + /* Enum values, see field(s): */ 3804 + /* MC_CMD_NVRAM_TYPES/MC_CMD_NVRAM_TYPES_OUT/TYPES */ 3805 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_REBOOT_OFST 4 3806 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_FLAGS_OFST 8 3807 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_FLAG_REPORT_VERIFY_RESULT_LBN 0 3808 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_IN_FLAG_REPORT_VERIFY_RESULT_WIDTH 1 3809 + 3810 + /* MC_CMD_NVRAM_UPDATE_FINISH_OUT msgresponse: Legacy NVRAM_UPDATE_FINISH 3811 + * response. Use NVRAM_UPDATE_FINISH_V2_OUT in new code 3812 + */ 3821 3813 #define MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN 0 3814 + 3815 + /* MC_CMD_NVRAM_UPDATE_FINISH_V2_OUT msgresponse: 3816 + * 3817 + * Extended NVRAM_UPDATE_FINISH response that communicates the result of secure 3818 + * firmware validation where applicable back to the host. 3819 + * 3820 + * Medford only: For signed firmware images, such as those for medford, the MC 3821 + * firmware verifies the signature before marking the firmware image as valid. 3822 + * This process takes a few seconds to complete. So is likely to take more than 3823 + * the MCDI timeout. Hence signature verification is initiated when 3824 + * MC_CMD_NVRAM_UPDATE_FINISH_V2_IN is received by the firmware, however, the 3825 + * MCDI command returns immediately with error code EAGAIN. Subsequent 3826 + * NVRAM_UPDATE_FINISH_V2_IN requests also return EAGAIN if the verification is 3827 + * in progress. Once the verification has completed, this response payload 3828 + * includes the results of the signature verification. Note that the nvram lock 3829 + * in firmware is only released after the verification has completed and the 3830 + * host has read back the result code from firmware. 3831 + */ 3832 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_OUT_LEN 4 3833 + /* Result of nvram update completion processing */ 3834 + #define MC_CMD_NVRAM_UPDATE_FINISH_V2_OUT_RESULT_CODE_OFST 0 3835 + /* enum: Verify succeeded without any errors. */ 3836 + #define MC_CMD_NVRAM_VERIFY_RC_SUCCESS 0x1 3837 + /* enum: CMS format verification failed due to an internal error. */ 3838 + #define MC_CMD_NVRAM_VERIFY_RC_CMS_CHECK_FAILED 0x2 3839 + /* enum: Invalid CMS format in image metadata. */ 3840 + #define MC_CMD_NVRAM_VERIFY_RC_INVALID_CMS_FORMAT 0x3 3841 + /* enum: Message digest verification failed due to an internal error. */ 3842 + #define MC_CMD_NVRAM_VERIFY_RC_MESSAGE_DIGEST_CHECK_FAILED 0x4 3843 + /* enum: Error in message digest calculated over the reflash-header, payload 3844 + * and reflash-trailer. 3845 + */ 3846 + #define MC_CMD_NVRAM_VERIFY_RC_BAD_MESSAGE_DIGEST 0x5 3847 + /* enum: Signature verification failed due to an internal error. */ 3848 + #define MC_CMD_NVRAM_VERIFY_RC_SIGNATURE_CHECK_FAILED 0x6 3849 + /* enum: There are no valid signatures in the image. */ 3850 + #define MC_CMD_NVRAM_VERIFY_RC_NO_VALID_SIGNATURES 0x7 3851 + /* enum: Trusted approvers verification failed due to an internal error. */ 3852 + #define MC_CMD_NVRAM_VERIFY_RC_TRUSTED_APPROVERS_CHECK_FAILED 0x8 3853 + /* enum: The Trusted approver's list is empty. */ 3854 + #define MC_CMD_NVRAM_VERIFY_RC_NO_TRUSTED_APPROVERS 0x9 3855 + /* enum: Signature chain verification failed due to an internal error. */ 3856 + #define MC_CMD_NVRAM_VERIFY_RC_SIGNATURE_CHAIN_CHECK_FAILED 0xa 3857 + /* enum: The signers of the signatures in the image are not listed in the 3858 + * Trusted approver's list. 3859 + */ 3860 + #define MC_CMD_NVRAM_VERIFY_RC_NO_SIGNATURE_MATCH 0xb 3822 3861 3823 3862 3824 3863 /***********************************/ ··· 4447 4356 /* MC_CMD_TESTASSERT_OUT msgresponse */ 4448 4357 #define MC_CMD_TESTASSERT_OUT_LEN 0 4449 4358 4359 + /* MC_CMD_TESTASSERT_V2_IN msgrequest */ 4360 + #define MC_CMD_TESTASSERT_V2_IN_LEN 4 4361 + /* How to provoke the assertion */ 4362 + #define MC_CMD_TESTASSERT_V2_IN_TYPE_OFST 0 4363 + /* enum: Assert using the FAIL_ASSERTION_WITH_USEFUL_VALUES macro. Unless 4364 + * you're testing firmware, this is what you want. 4365 + */ 4366 + #define MC_CMD_TESTASSERT_V2_IN_FAIL_ASSERTION_WITH_USEFUL_VALUES 0x0 4367 + /* enum: Assert using assert(0); */ 4368 + #define MC_CMD_TESTASSERT_V2_IN_ASSERT_FALSE 0x1 4369 + /* enum: Deliberately trigger a watchdog */ 4370 + #define MC_CMD_TESTASSERT_V2_IN_WATCHDOG 0x2 4371 + /* enum: Deliberately trigger a trap by loading from an invalid address */ 4372 + #define MC_CMD_TESTASSERT_V2_IN_LOAD_TRAP 0x3 4373 + /* enum: Deliberately trigger a trap by storing to an invalid address */ 4374 + #define MC_CMD_TESTASSERT_V2_IN_STORE_TRAP 0x4 4375 + /* enum: Jump to an invalid address */ 4376 + #define MC_CMD_TESTASSERT_V2_IN_JUMP_TRAP 0x5 4377 + 4378 + /* MC_CMD_TESTASSERT_V2_OUT msgresponse */ 4379 + #define MC_CMD_TESTASSERT_V2_OUT_LEN 0 4380 + 4450 4381 4451 4382 /***********************************/ 4452 4383 /* MC_CMD_WORKAROUND ··· 4534 4421 * (GET_PHY_CFG_OUT_MEDIA_TYPE); the valid 'page number' input values, and the 4535 4422 * output data, are interpreted on a per-type basis. For SFP+: PAGE=0 or 1 4536 4423 * returns a 128-byte block read from module I2C address 0xA0 offset 0 or 0x80. 4424 + * Anything else: currently undefined. Locks required: None. Return code: 0. 4537 4425 */ 4538 4426 #define MC_CMD_GET_PHY_MEDIA_INFO 0x4b 4539 4427 ··· 5476 5362 #define NVRAM_PARTITION_TYPE_EXPANSION_UEFI 0xd00 5477 5363 /* enum: Spare partition 0 */ 5478 5364 #define NVRAM_PARTITION_TYPE_SPARE_0 0x1000 5479 - /* enum: Spare partition 1 */ 5480 - #define NVRAM_PARTITION_TYPE_SPARE_1 0x1100 5365 + /* enum: Used for XIP code of shmbooted images */ 5366 + #define NVRAM_PARTITION_TYPE_XIP_SCRATCH 0x1100 5481 5367 /* enum: Spare partition 2 */ 5482 5368 #define NVRAM_PARTITION_TYPE_SPARE_2 0x1200 5483 - /* enum: Spare partition 3 */ 5484 - #define NVRAM_PARTITION_TYPE_SPARE_3 0x1300 5369 + /* enum: Manufacturing partition. Used during manufacture to pass information 5370 + * between XJTAG and Manftest. 5371 + */ 5372 + #define NVRAM_PARTITION_TYPE_MANUFACTURING 0x1300 5485 5373 /* enum: Spare partition 4 */ 5486 5374 #define NVRAM_PARTITION_TYPE_SPARE_4 0x1400 5487 5375 /* enum: Spare partition 5 */ ··· 5518 5402 #define LICENSED_APP_ID_CAPTURE_SOLARSYSTEM 0x40 5519 5403 /* enum: Network Access Control */ 5520 5404 #define LICENSED_APP_ID_NETWORK_ACCESS_CONTROL 0x80 5405 + /* enum: TCP Direct */ 5406 + #define LICENSED_APP_ID_TCP_DIRECT 0x100 5407 + /* enum: Low Latency */ 5408 + #define LICENSED_APP_ID_LOW_LATENCY 0x200 5409 + /* enum: SolarCapture Tap */ 5410 + #define LICENSED_APP_ID_SOLARCAPTURE_TAP 0x400 5411 + /* enum: Capture SolarSystem 40G */ 5412 + #define LICENSED_APP_ID_CAPTURE_SOLARSYSTEM_40G 0x800 5521 5413 #define LICENSED_APP_ID_ID_LBN 0 5522 5414 #define LICENSED_APP_ID_ID_WIDTH 32 5523 5415 ··· 5582 5458 #define LICENSED_V3_APPS_CAPTURE_SOLARSYSTEM_WIDTH 1 5583 5459 #define LICENSED_V3_APPS_NETWORK_ACCESS_CONTROL_LBN 7 5584 5460 #define LICENSED_V3_APPS_NETWORK_ACCESS_CONTROL_WIDTH 1 5461 + #define LICENSED_V3_APPS_TCP_DIRECT_LBN 8 5462 + #define LICENSED_V3_APPS_TCP_DIRECT_WIDTH 1 5463 + #define LICENSED_V3_APPS_LOW_LATENCY_LBN 9 5464 + #define LICENSED_V3_APPS_LOW_LATENCY_WIDTH 1 5465 + #define LICENSED_V3_APPS_SOLARCAPTURE_TAP_LBN 10 5466 + #define LICENSED_V3_APPS_SOLARCAPTURE_TAP_WIDTH 1 5467 + #define LICENSED_V3_APPS_CAPTURE_SOLARSYSTEM_40G_LBN 11 5468 + #define LICENSED_V3_APPS_CAPTURE_SOLARSYSTEM_40G_WIDTH 1 5585 5469 #define LICENSED_V3_APPS_MASK_LBN 0 5586 5470 #define LICENSED_V3_APPS_MASK_WIDTH 64 5587 5471 ··· 6120 5988 #define MC_CMD_INIT_TXQ_EXT_IN_FLAG_INNER_TCP_CSUM_EN_WIDTH 1 6121 5989 #define MC_CMD_INIT_TXQ_EXT_IN_FLAG_TSOV2_EN_LBN 12 6122 5990 #define MC_CMD_INIT_TXQ_EXT_IN_FLAG_TSOV2_EN_WIDTH 1 5991 + #define MC_CMD_INIT_TXQ_EXT_IN_FLAG_CTPIO_LBN 13 5992 + #define MC_CMD_INIT_TXQ_EXT_IN_FLAG_CTPIO_WIDTH 1 6123 5993 /* Owner ID to use if in buffer mode (zero if physical) */ 6124 5994 #define MC_CMD_INIT_TXQ_EXT_IN_OWNER_ID_OFST 20 6125 5995 /* The port ID associated with the v-adaptor which should contain this DMAQ. */ ··· 7862 7728 * tests (Medford development only) 7863 7729 */ 7864 7730 #define MC_CMD_GET_CAPABILITIES_OUT_RXPD_FW_TYPE_LAYER2_PERF 0x7 7731 + /* enum: Rules engine RX PD production firmware */ 7732 + #define MC_CMD_GET_CAPABILITIES_OUT_RXPD_FW_TYPE_RULES_ENGINE 0x8 7865 7733 /* enum: RX PD firmware for GUE parsing prototype (Medford development only) */ 7866 7734 #define MC_CMD_GET_CAPABILITIES_OUT_RXPD_FW_TYPE_TESTFW_GUE_PROTOTYPE 0xe 7867 7735 /* enum: RX PD firmware parsing but not filtering network overlay tunnel ··· 7899 7763 * tests (Medford development only) 7900 7764 */ 7901 7765 #define MC_CMD_GET_CAPABILITIES_OUT_TXPD_FW_TYPE_LAYER2_PERF 0x7 7766 + /* enum: Rules engine TX PD production firmware */ 7767 + #define MC_CMD_GET_CAPABILITIES_OUT_TXPD_FW_TYPE_RULES_ENGINE 0x8 7902 7768 /* enum: RX PD firmware for GUE parsing prototype (Medford development only) */ 7903 7769 #define MC_CMD_GET_CAPABILITIES_OUT_TXPD_FW_TYPE_TESTFW_GUE_PROTOTYPE 0xe 7904 7770 /* Hardware capabilities of NIC */ ··· 8051 7913 * tests (Medford development only) 8052 7914 */ 8053 7915 #define MC_CMD_GET_CAPABILITIES_V2_OUT_RXPD_FW_TYPE_LAYER2_PERF 0x7 7916 + /* enum: Rules engine RX PD production firmware */ 7917 + #define MC_CMD_GET_CAPABILITIES_V2_OUT_RXPD_FW_TYPE_RULES_ENGINE 0x8 8054 7918 /* enum: RX PD firmware for GUE parsing prototype (Medford development only) */ 8055 7919 #define MC_CMD_GET_CAPABILITIES_V2_OUT_RXPD_FW_TYPE_TESTFW_GUE_PROTOTYPE 0xe 8056 7920 /* enum: RX PD firmware parsing but not filtering network overlay tunnel ··· 8088 7948 * tests (Medford development only) 8089 7949 */ 8090 7950 #define MC_CMD_GET_CAPABILITIES_V2_OUT_TXPD_FW_TYPE_LAYER2_PERF 0x7 7951 + /* enum: Rules engine TX PD production firmware */ 7952 + #define MC_CMD_GET_CAPABILITIES_V2_OUT_TXPD_FW_TYPE_RULES_ENGINE 0x8 8091 7953 /* enum: RX PD firmware for GUE parsing prototype (Medford development only) */ 8092 7954 #define MC_CMD_GET_CAPABILITIES_V2_OUT_TXPD_FW_TYPE_TESTFW_GUE_PROTOTYPE 0xe 8093 7955 /* Hardware capabilities of NIC */ ··· 8122 7980 #define MC_CMD_GET_CAPABILITIES_V2_OUT_RX_SNIFF_WIDTH 1 8123 7981 #define MC_CMD_GET_CAPABILITIES_V2_OUT_TX_SNIFF_LBN 11 8124 7982 #define MC_CMD_GET_CAPABILITIES_V2_OUT_TX_SNIFF_WIDTH 1 7983 + #define MC_CMD_GET_CAPABILITIES_V2_OUT_NVRAM_UPDATE_REPORT_VERIFY_RESULT_LBN 12 7984 + #define MC_CMD_GET_CAPABILITIES_V2_OUT_NVRAM_UPDATE_REPORT_VERIFY_RESULT_WIDTH 1 8125 7985 /* Number of FATSOv2 contexts per datapath supported by this NIC. Not present 8126 7986 * on older firmware (check the length). 8127 7987 */ ··· 8391 8247 #define MC_CMD_GET_CAPABILITIES_V3_OUT_RX_SNIFF_WIDTH 1 8392 8248 #define MC_CMD_GET_CAPABILITIES_V3_OUT_TX_SNIFF_LBN 11 8393 8249 #define MC_CMD_GET_CAPABILITIES_V3_OUT_TX_SNIFF_WIDTH 1 8250 + #define MC_CMD_GET_CAPABILITIES_V3_OUT_NVRAM_UPDATE_REPORT_VERIFY_RESULT_LBN 12 8251 + #define MC_CMD_GET_CAPABILITIES_V3_OUT_NVRAM_UPDATE_REPORT_VERIFY_RESULT_WIDTH 1 8394 8252 /* Number of FATSOv2 contexts per datapath supported by this NIC. Not present 8395 8253 * on older firmware (check the length). 8396 8254 */ ··· 8450 8304 #define MC_CMD_GET_CAPABILITIES_V3_OUT_SIZE_PIO_BUFF_LEN 2 8451 8305 /* On chips later than Medford the amount of address space assigned to each VI 8452 8306 * is configurable. This is a global setting that the driver must query to 8453 - * discover the VI to address mapping. Cut-through PIO (CTPIO) in not available 8307 + * discover the VI to address mapping. Cut-through PIO (CTPIO) is not available 8454 8308 * with 8k VI windows. 8455 8309 */ 8456 8310 #define MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_OFST 72 ··· 10429 10283 * more data is returned. 10430 10284 */ 10431 10285 #define MC_CMD_PCIE_TUNE_IN_POLL_EYE_PLOT 0x6 10286 + /* enum: Enable the SERDES BIST and set it to generate a 200MHz square wave */ 10287 + #define MC_CMD_PCIE_TUNE_IN_BIST_SQUARE_WAVE 0x7 10432 10288 /* Align the arguments to 32 bits */ 10433 10289 #define MC_CMD_PCIE_TUNE_IN_PCIE_TUNE_RSVD_OFST 1 10434 10290 #define MC_CMD_PCIE_TUNE_IN_PCIE_TUNE_RSVD_LEN 3 ··· 10615 10467 #define MC_CMD_PCIE_TUNE_POLL_EYE_PLOT_OUT_SAMPLES_LEN 2 10616 10468 #define MC_CMD_PCIE_TUNE_POLL_EYE_PLOT_OUT_SAMPLES_MINNUM 0 10617 10469 #define MC_CMD_PCIE_TUNE_POLL_EYE_PLOT_OUT_SAMPLES_MAXNUM 126 10470 + 10471 + /* MC_CMD_PCIE_TUNE_BIST_SQUARE_WAVE_IN msgrequest */ 10472 + #define MC_CMD_PCIE_TUNE_BIST_SQUARE_WAVE_IN_LEN 0 10473 + 10474 + /* MC_CMD_PCIE_TUNE_BIST_SQUARE_WAVE_OUT msgrequest */ 10475 + #define MC_CMD_PCIE_TUNE_BIST_SQUARE_WAVE_OUT_LEN 0 10618 10476 10619 10477 10620 10478 /***********************************/ ··· 10937 10783 #define MC_CMD_0xd4_PRIVILEGE_CTG SRIOV_CTG_GENERAL 10938 10784 10939 10785 /* MC_CMD_LICENSED_V3_VALIDATE_APP_IN msgrequest */ 10940 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_LEN 72 10786 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_LEN 56 10787 + /* challenge for validation (384 bits) */ 10788 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_CHALLENGE_OFST 0 10789 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_CHALLENGE_LEN 48 10941 10790 /* application ID expressed as a single bit mask */ 10942 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_OFST 0 10791 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_OFST 48 10943 10792 #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_LEN 8 10944 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_LO_OFST 0 10945 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_HI_OFST 4 10946 - /* challenge for validation */ 10947 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_CHALLENGE_OFST 8 10948 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_CHALLENGE_LEN 64 10793 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_LO_OFST 48 10794 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_IN_APP_ID_HI_OFST 52 10949 10795 10950 10796 /* MC_CMD_LICENSED_V3_VALIDATE_APP_OUT msgresponse */ 10951 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_LEN 72 10797 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_LEN 116 10798 + /* validation response to challenge in the form of ECDSA signature consisting 10799 + * of two 384-bit integers, r and s, in big-endian order. The signature signs a 10800 + * SHA-384 digest of a message constructed from the concatenation of the input 10801 + * message and the remaining fields of this output message, e.g. challenge[48 10802 + * bytes] ... expiry_time[4 bytes] ... 10803 + */ 10804 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_RESPONSE_OFST 0 10805 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_RESPONSE_LEN 96 10952 10806 /* application expiry time */ 10953 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_TIME_OFST 0 10807 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_TIME_OFST 96 10954 10808 /* application expiry units */ 10955 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_UNITS_OFST 4 10809 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_UNITS_OFST 100 10956 10810 /* enum: expiry units are accounting units */ 10957 10811 #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_UNIT_ACC 0x0 10958 10812 /* enum: expiry units are calendar days */ 10959 10813 #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_EXPIRY_UNIT_DAYS 0x1 10960 - /* validation response to challenge */ 10961 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_RESPONSE_OFST 8 10962 - #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_RESPONSE_LEN 64 10814 + /* base MAC address of the NIC stored in NVRAM (note that this is a constant 10815 + * value for a given NIC regardless which function is calling, effectively this 10816 + * is PF0 base MAC address) 10817 + */ 10818 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_BASE_MACADDR_OFST 104 10819 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_BASE_MACADDR_LEN 6 10820 + /* MAC address of v-adaptor associated with the client. If no such v-adapator 10821 + * exists, then the field is filled with 0xFF. 10822 + */ 10823 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_VADAPTOR_MACADDR_OFST 110 10824 + #define MC_CMD_LICENSED_V3_VALIDATE_APP_OUT_VADAPTOR_MACADDR_LEN 6 10963 10825 10964 10826 10965 10827 /***********************************/ ··· 11002 10832 11003 10833 /* MC_CMD_LICENSED_V3_MASK_FEATURES_OUT msgresponse */ 11004 10834 #define MC_CMD_LICENSED_V3_MASK_FEATURES_OUT_LEN 0 10835 + 10836 + 10837 + /***********************************/ 10838 + /* MC_CMD_LICENSING_V3_TEMPORARY 10839 + * Perform operations to support installation of a single temporary license in 10840 + * the adapter, in addition to those found in the licensing partition. See 10841 + * SF-116124-SW for an overview of how this could be used. The license is 10842 + * stored in MC persistent data and so will survive a MC reboot, but will be 10843 + * erased when the adapter is power cycled 10844 + */ 10845 + #define MC_CMD_LICENSING_V3_TEMPORARY 0xd6 10846 + 10847 + #define MC_CMD_0xd6_PRIVILEGE_CTG SRIOV_CTG_GENERAL 10848 + 10849 + /* MC_CMD_LICENSING_V3_TEMPORARY_IN msgrequest */ 10850 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_LEN 4 10851 + /* operation code */ 10852 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_OP_OFST 0 10853 + /* enum: install a new license, overwriting any existing temporary license. 10854 + * This is an asynchronous operation owing to the time taken to validate an 10855 + * ECDSA license 10856 + */ 10857 + #define MC_CMD_LICENSING_V3_TEMPORARY_SET 0x0 10858 + /* enum: clear the license immediately rather than waiting for the next power 10859 + * cycle 10860 + */ 10861 + #define MC_CMD_LICENSING_V3_TEMPORARY_CLEAR 0x1 10862 + /* enum: get the status of the asynchronous MC_CMD_LICENSING_V3_TEMPORARY_SET 10863 + * operation 10864 + */ 10865 + #define MC_CMD_LICENSING_V3_TEMPORARY_STATUS 0x2 10866 + 10867 + /* MC_CMD_LICENSING_V3_TEMPORARY_IN_SET msgrequest */ 10868 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_SET_LEN 164 10869 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_SET_OP_OFST 0 10870 + /* ECDSA license and signature */ 10871 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_SET_LICENSE_OFST 4 10872 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_SET_LICENSE_LEN 160 10873 + 10874 + /* MC_CMD_LICENSING_V3_TEMPORARY_IN_CLEAR msgrequest */ 10875 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_CLEAR_LEN 4 10876 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_CLEAR_OP_OFST 0 10877 + 10878 + /* MC_CMD_LICENSING_V3_TEMPORARY_IN_STATUS msgrequest */ 10879 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_STATUS_LEN 4 10880 + #define MC_CMD_LICENSING_V3_TEMPORARY_IN_STATUS_OP_OFST 0 10881 + 10882 + /* MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS msgresponse */ 10883 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_LEN 12 10884 + /* status code */ 10885 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_STATUS_OFST 0 10886 + /* enum: finished validating and installing license */ 10887 + #define MC_CMD_LICENSING_V3_TEMPORARY_STATUS_OK 0x0 10888 + /* enum: license validation and installation in progress */ 10889 + #define MC_CMD_LICENSING_V3_TEMPORARY_STATUS_IN_PROGRESS 0x1 10890 + /* enum: licensing error. More specific error messages are not provided to 10891 + * avoid exposing details of the licensing system to the client 10892 + */ 10893 + #define MC_CMD_LICENSING_V3_TEMPORARY_STATUS_ERROR 0x2 10894 + /* bitmask of licensed features */ 10895 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_LICENSED_FEATURES_OFST 4 10896 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_LICENSED_FEATURES_LEN 8 10897 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_LICENSED_FEATURES_LO_OFST 4 10898 + #define MC_CMD_LICENSING_V3_TEMPORARY_OUT_STATUS_LICENSED_FEATURES_HI_OFST 8 11005 10899 11006 10900 11007 10901 /***********************************/ ··· 11939 11705 /* MC_CMD_RX_BALANCING_OUT msgresponse */ 11940 11706 #define MC_CMD_RX_BALANCING_OUT_LEN 0 11941 11707 11708 + 11709 + /***********************************/ 11710 + /* MC_CMD_NVRAM_PRIVATE_APPEND 11711 + * Append a single TLV to the MC_USAGE_TLV partition. Returns MC_CMD_ERR_EEXIST 11712 + * if the tag is already present. 11713 + */ 11714 + #define MC_CMD_NVRAM_PRIVATE_APPEND 0x11c 11715 + 11716 + #define MC_CMD_0x11c_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11717 + 11718 + /* MC_CMD_NVRAM_PRIVATE_APPEND_IN msgrequest */ 11719 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_LENMIN 9 11720 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_LENMAX 252 11721 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_LEN(num) (8+1*(num)) 11722 + /* The tag to be appended */ 11723 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_TAG_OFST 0 11724 + /* The length of the data */ 11725 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_LENGTH_OFST 4 11726 + /* The data to be contained in the TLV structure */ 11727 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_DATA_BUFFER_OFST 8 11728 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_DATA_BUFFER_LEN 1 11729 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_DATA_BUFFER_MINNUM 1 11730 + #define MC_CMD_NVRAM_PRIVATE_APPEND_IN_DATA_BUFFER_MAXNUM 244 11731 + 11732 + /* MC_CMD_NVRAM_PRIVATE_APPEND_OUT msgresponse */ 11733 + #define MC_CMD_NVRAM_PRIVATE_APPEND_OUT_LEN 0 11734 + 11735 + 11736 + /***********************************/ 11737 + /* MC_CMD_XPM_VERIFY_CONTENTS 11738 + * Verify that the contents of the XPM memory is correct (Medford only). This 11739 + * is used during manufacture to check that the XPM memory has been programmed 11740 + * correctly at ATE. 11741 + */ 11742 + #define MC_CMD_XPM_VERIFY_CONTENTS 0x11b 11743 + 11744 + #define MC_CMD_0x11b_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11745 + 11746 + /* MC_CMD_XPM_VERIFY_CONTENTS_IN msgrequest */ 11747 + #define MC_CMD_XPM_VERIFY_CONTENTS_IN_LEN 4 11748 + /* Data type to be checked */ 11749 + #define MC_CMD_XPM_VERIFY_CONTENTS_IN_DATA_TYPE_OFST 0 11750 + 11751 + /* MC_CMD_XPM_VERIFY_CONTENTS_OUT msgresponse */ 11752 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_LENMIN 12 11753 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_LENMAX 252 11754 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_LEN(num) (12+1*(num)) 11755 + /* Number of sectors found (test builds only) */ 11756 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_NUM_SECTORS_OFST 0 11757 + /* Number of bytes found (test builds only) */ 11758 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_NUM_BYTES_OFST 4 11759 + /* Length of signature */ 11760 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_SIG_LENGTH_OFST 8 11761 + /* Signature */ 11762 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_SIGNATURE_OFST 12 11763 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_SIGNATURE_LEN 1 11764 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_SIGNATURE_MINNUM 0 11765 + #define MC_CMD_XPM_VERIFY_CONTENTS_OUT_SIGNATURE_MAXNUM 240 11766 + 11767 + 11942 11768 /***********************************/ 11943 11769 /* MC_CMD_SET_EVQ_TMR 11944 11770 * Update the timer load, timer reload and timer mode values for a given EVQ. ··· 12091 11797 * enabled. 12092 11798 */ 12093 11799 #define MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_STEP_OFST 32 11800 + 11801 + 11802 + /***********************************/ 11803 + /* MC_CMD_ALLOCATE_TX_VFIFO_CP 11804 + * When we use the TX_vFIFO_ULL mode, we can allocate common pools using the 11805 + * non used switch buffers. 11806 + */ 11807 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP 0x11d 11808 + 11809 + #define MC_CMD_0x11d_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11810 + 11811 + /* MC_CMD_ALLOCATE_TX_VFIFO_CP_IN msgrequest */ 11812 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_LEN 20 11813 + /* Desired instance. Must be set to a specific instance, which is a function 11814 + * local queue index. 11815 + */ 11816 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_INSTANCE_OFST 0 11817 + /* Will the common pool be used as TX_vFIFO_ULL (1) */ 11818 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_MODE_OFST 4 11819 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_ENABLED 0x1 /* enum */ 11820 + /* enum: Using this interface without TX_vFIFO_ULL is not supported for now */ 11821 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_DISABLED 0x0 11822 + /* Number of buffers to reserve for the common pool */ 11823 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_SIZE_OFST 8 11824 + /* TX datapath to which the Common Pool is connected to. */ 11825 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_INGRESS_OFST 12 11826 + /* enum: Extracts information from function */ 11827 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_USE_FUNCTION_VALUE -0x1 11828 + /* Network port or RX Engine to which the common pool connects. */ 11829 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_EGRESS_OFST 16 11830 + /* enum: Extracts information from function */ 11831 + /* MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_USE_FUNCTION_VALUE -0x1 */ 11832 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_PORT0 0x0 /* enum */ 11833 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_PORT1 0x1 /* enum */ 11834 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_PORT2 0x2 /* enum */ 11835 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_PORT3 0x3 /* enum */ 11836 + /* enum: To enable Switch loopback with Rx engine 0 */ 11837 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_RX_ENGINE0 0x4 11838 + /* enum: To enable Switch loopback with Rx engine 1 */ 11839 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_IN_RX_ENGINE1 0x5 11840 + 11841 + /* MC_CMD_ALLOCATE_TX_VFIFO_CP_OUT msgresponse */ 11842 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_OUT_LEN 4 11843 + /* ID of the common pool allocated */ 11844 + #define MC_CMD_ALLOCATE_TX_VFIFO_CP_OUT_CP_ID_OFST 0 11845 + 11846 + 11847 + /***********************************/ 11848 + /* MC_CMD_ALLOCATE_TX_VFIFO_VFIFO 11849 + * When we use the TX_vFIFO_ULL mode, we can allocate vFIFOs using the 11850 + * previously allocated common pools. 11851 + */ 11852 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO 0x11e 11853 + 11854 + #define MC_CMD_0x11e_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11855 + 11856 + /* MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN msgrequest */ 11857 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_LEN 20 11858 + /* Common pool previously allocated to which the new vFIFO will be associated 11859 + */ 11860 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_CP_OFST 0 11861 + /* Port or RX engine to associate the vFIFO egress */ 11862 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_EGRESS_OFST 4 11863 + /* enum: Extracts information from common pool */ 11864 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_USE_CP_VALUE -0x1 11865 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_PORT0 0x0 /* enum */ 11866 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_PORT1 0x1 /* enum */ 11867 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_PORT2 0x2 /* enum */ 11868 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_PORT3 0x3 /* enum */ 11869 + /* enum: To enable Switch loopback with Rx engine 0 */ 11870 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_RX_ENGINE0 0x4 11871 + /* enum: To enable Switch loopback with Rx engine 1 */ 11872 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_RX_ENGINE1 0x5 11873 + /* Minimum number of buffers that the pool must have */ 11874 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_SIZE_OFST 8 11875 + /* enum: Do not check the space available */ 11876 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_NO_MINIMUM 0x0 11877 + /* Will the vFIFO be used as TX_vFIFO_ULL */ 11878 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_MODE_OFST 12 11879 + /* Network priority of the vFIFO,if applicable */ 11880 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_PRIORITY_OFST 16 11881 + /* enum: Search for the lowest unused priority */ 11882 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_IN_LOWEST_AVAILABLE -0x1 11883 + 11884 + /* MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_OUT msgresponse */ 11885 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_OUT_LEN 8 11886 + /* Short vFIFO ID */ 11887 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_OUT_VID_OFST 0 11888 + /* Network priority of the vFIFO */ 11889 + #define MC_CMD_ALLOCATE_TX_VFIFO_VFIFO_OUT_PRIORITY_OFST 4 11890 + 11891 + 11892 + /***********************************/ 11893 + /* MC_CMD_TEARDOWN_TX_VFIFO_VF 11894 + * This interface clears the configuration of the given vFIFO and leaves it 11895 + * ready to be re-used. 11896 + */ 11897 + #define MC_CMD_TEARDOWN_TX_VFIFO_VF 0x11f 11898 + 11899 + #define MC_CMD_0x11f_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11900 + 11901 + /* MC_CMD_TEARDOWN_TX_VFIFO_VF_IN msgrequest */ 11902 + #define MC_CMD_TEARDOWN_TX_VFIFO_VF_IN_LEN 4 11903 + /* Short vFIFO ID */ 11904 + #define MC_CMD_TEARDOWN_TX_VFIFO_VF_IN_VFIFO_OFST 0 11905 + 11906 + /* MC_CMD_TEARDOWN_TX_VFIFO_VF_OUT msgresponse */ 11907 + #define MC_CMD_TEARDOWN_TX_VFIFO_VF_OUT_LEN 0 11908 + 11909 + 11910 + /***********************************/ 11911 + /* MC_CMD_DEALLOCATE_TX_VFIFO_CP 11912 + * This interface clears the configuration of the given common pool and leaves 11913 + * it ready to be re-used. 11914 + */ 11915 + #define MC_CMD_DEALLOCATE_TX_VFIFO_CP 0x121 11916 + 11917 + #define MC_CMD_0x121_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11918 + 11919 + /* MC_CMD_DEALLOCATE_TX_VFIFO_CP_IN msgrequest */ 11920 + #define MC_CMD_DEALLOCATE_TX_VFIFO_CP_IN_LEN 4 11921 + /* Common pool ID given when pool allocated */ 11922 + #define MC_CMD_DEALLOCATE_TX_VFIFO_CP_IN_POOL_ID_OFST 0 11923 + 11924 + /* MC_CMD_DEALLOCATE_TX_VFIFO_CP_OUT msgresponse */ 11925 + #define MC_CMD_DEALLOCATE_TX_VFIFO_CP_OUT_LEN 0 11926 + 11927 + 11928 + /***********************************/ 11929 + /* MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS 11930 + * This interface allows the host to find out how many common pool buffers are 11931 + * not yet assigned. 11932 + */ 11933 + #define MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS 0x124 11934 + 11935 + #define MC_CMD_0x124_PRIVILEGE_CTG SRIOV_CTG_ADMIN 11936 + 11937 + /* MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_IN msgrequest */ 11938 + #define MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_IN_LEN 0 11939 + 11940 + /* MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_OUT msgresponse */ 11941 + #define MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_OUT_LEN 8 11942 + /* Available buffers for the ENG to NET vFIFOs. */ 11943 + #define MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_OUT_NET_OFST 0 11944 + /* Available buffers for the ENG to ENG and NET to ENG vFIFOs. */ 11945 + #define MC_CMD_SWITCH_GET_UNASSIGNED_BUFFERS_OUT_ENG_OFST 4 11946 + 12094 11947 12095 11948 #endif /* MCDI_PCOL_H */
+50 -2
drivers/net/ethernet/sfc/net_driver.h
··· 189 189 * @channel: The associated channel 190 190 * @core_txq: The networking core TX queue structure 191 191 * @buffer: The software buffer ring 192 - * @tsoh_page: Array of pages of TSO header buffers 192 + * @cb_page: Array of pages of copy buffers. Carved up according to 193 + * %EFX_TX_CB_ORDER into %EFX_TX_CB_SIZE-sized chunks. 193 194 * @txd: The hardware descriptor ring 194 195 * @ptr_mask: The size of the ring minus 1. 195 196 * @piobuf: PIO buffer region for this TX queue (shared with its partner). 196 197 * Size of the region is efx_piobuf_size. 197 198 * @piobuf_offset: Buffer offset to be specified in PIO descriptors 198 199 * @initialised: Has hardware queue been initialised? 200 + * @tx_min_size: Minimum transmit size for this queue. Depends on HW. 201 + * @handle_tso: TSO xmit preparation handler. Sets up the TSO metadata and 202 + * may also map tx data, depending on the nature of the TSO implementation. 199 203 * @read_count: Current read pointer. 200 204 * This is the number of buffers that have been removed from both rings. 201 205 * @old_write_count: The value of @write_count when last checked. ··· 225 221 * @tso_long_headers: Number of packets with headers too long for standard 226 222 * blocks 227 223 * @tso_packets: Number of packets via the TSO xmit path 224 + * @tso_fallbacks: Number of times TSO fallback used 228 225 * @pushes: Number of times the TX push feature has been used 229 226 * @pio_packets: Number of times the TX PIO feature has been used 230 227 * @xmit_more_available: Are any packets waiting to be pushed to the NIC 228 + * @cb_packets: Number of times the TX copybreak feature has been used 231 229 * @empty_read_count: If the completion path has seen the queue as empty 232 230 * and the transmission path has not yet checked this, the value of 233 231 * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0. ··· 242 236 struct efx_channel *channel; 243 237 struct netdev_queue *core_txq; 244 238 struct efx_tx_buffer *buffer; 245 - struct efx_buffer *tsoh_page; 239 + struct efx_buffer *cb_page; 246 240 struct efx_special_buffer txd; 247 241 unsigned int ptr_mask; 248 242 void __iomem *piobuf; 249 243 unsigned int piobuf_offset; 250 244 bool initialised; 245 + unsigned int tx_min_size; 246 + 247 + /* Function pointers used in the fast path. */ 248 + int (*handle_tso)(struct efx_tx_queue*, struct sk_buff*, bool *); 251 249 252 250 /* Members used mainly on the completion path */ 253 251 unsigned int read_count ____cacheline_aligned_in_smp; ··· 267 257 unsigned int tso_bursts; 268 258 unsigned int tso_long_headers; 269 259 unsigned int tso_packets; 260 + unsigned int tso_fallbacks; 270 261 unsigned int pushes; 271 262 unsigned int pio_packets; 272 263 bool xmit_more_available; 264 + unsigned int cb_packets; 273 265 /* Statistics to supplement MAC stats */ 274 266 unsigned long tx_packets; 275 267 ··· 280 268 #define EFX_EMPTY_COUNT_VALID 0x80000000 281 269 atomic_t flush_outstanding; 282 270 }; 271 + 272 + #define EFX_TX_CB_ORDER 7 273 + #define EFX_TX_CB_SIZE (1 << EFX_TX_CB_ORDER) - NET_IP_ALIGN 283 274 284 275 /** 285 276 * struct efx_rx_buffer - An Efx RX data buffer ··· 1227 1212 * and tx_type will already have been validated but this operation 1228 1213 * must validate and update rx_filter. 1229 1214 * @set_mac_address: Set the MAC address of the device 1215 + * @tso_versions: Returns mask of firmware-assisted TSO versions supported. 1216 + * If %NULL, then device does not support any TSO version. 1230 1217 * @revision: Hardware architecture revision 1231 1218 * @txd_ptr_tbl_base: TX descriptor ring base address 1232 1219 * @rxd_ptr_tbl_base: RX descriptor ring base address ··· 1305 1288 void (*tx_init)(struct efx_tx_queue *tx_queue); 1306 1289 void (*tx_remove)(struct efx_tx_queue *tx_queue); 1307 1290 void (*tx_write)(struct efx_tx_queue *tx_queue); 1291 + unsigned int (*tx_limit_len)(struct efx_tx_queue *tx_queue, 1292 + dma_addr_t dma_addr, unsigned int len); 1308 1293 int (*rx_push_rss_config)(struct efx_nic *efx, bool user, 1309 1294 const u32 *rx_indir_table); 1310 1295 int (*rx_probe)(struct efx_rx_queue *rx_queue); ··· 1385 1366 void (*vswitching_remove)(struct efx_nic *efx); 1386 1367 int (*get_mac_address)(struct efx_nic *efx, unsigned char *perm_addr); 1387 1368 int (*set_mac_address)(struct efx_nic *efx); 1369 + u32 (*tso_versions)(struct efx_nic *efx); 1388 1370 1389 1371 int revision; 1390 1372 unsigned int txd_ptr_tbl_base; ··· 1563 1543 const struct net_device *net_dev = efx->net_dev; 1564 1544 1565 1545 return net_dev->features | net_dev->hw_features; 1546 + } 1547 + 1548 + /* Get the current TX queue insert index. */ 1549 + static inline unsigned int 1550 + efx_tx_queue_get_insert_index(const struct efx_tx_queue *tx_queue) 1551 + { 1552 + return tx_queue->insert_count & tx_queue->ptr_mask; 1553 + } 1554 + 1555 + /* Get a TX buffer. */ 1556 + static inline struct efx_tx_buffer * 1557 + __efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue) 1558 + { 1559 + return &tx_queue->buffer[efx_tx_queue_get_insert_index(tx_queue)]; 1560 + } 1561 + 1562 + /* Get a TX buffer, checking it's not currently in use. */ 1563 + static inline struct efx_tx_buffer * 1564 + efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue) 1565 + { 1566 + struct efx_tx_buffer *buffer = 1567 + __efx_tx_queue_get_insert_buffer(tx_queue); 1568 + 1569 + EFX_BUG_ON_PARANOID(buffer->len); 1570 + EFX_BUG_ON_PARANOID(buffer->flags); 1571 + EFX_BUG_ON_PARANOID(buffer->unmap_len); 1572 + 1573 + return buffer; 1566 1574 } 1567 1575 1568 1576 #endif /* EFX_NET_DRIVER_H */
+2
drivers/net/ethernet/sfc/nic.h
··· 681 681 void efx_farch_tx_fini(struct efx_tx_queue *tx_queue); 682 682 void efx_farch_tx_remove(struct efx_tx_queue *tx_queue); 683 683 void efx_farch_tx_write(struct efx_tx_queue *tx_queue); 684 + unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue, 685 + dma_addr_t dma_addr, unsigned int len); 684 686 int efx_farch_rx_probe(struct efx_rx_queue *rx_queue); 685 687 void efx_farch_rx_init(struct efx_rx_queue *rx_queue); 686 688 void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
+1
drivers/net/ethernet/sfc/siena.c
··· 977 977 .tx_init = efx_farch_tx_init, 978 978 .tx_remove = efx_farch_tx_remove, 979 979 .tx_write = efx_farch_tx_write, 980 + .tx_limit_len = efx_farch_tx_limit_len, 980 981 .rx_push_rss_config = siena_rx_push_rss_config, 981 982 .rx_probe = efx_farch_rx_probe, 982 983 .rx_init = efx_farch_rx_init,
+290 -765
drivers/net/ethernet/sfc/tx.c
··· 22 22 #include "efx.h" 23 23 #include "io.h" 24 24 #include "nic.h" 25 + #include "tx.h" 25 26 #include "workarounds.h" 26 27 #include "ef10_regs.h" 27 28 ··· 34 33 35 34 #endif /* EFX_USE_PIO */ 36 35 37 - static inline unsigned int 38 - efx_tx_queue_get_insert_index(const struct efx_tx_queue *tx_queue) 36 + static inline u8 *efx_tx_get_copy_buffer(struct efx_tx_queue *tx_queue, 37 + struct efx_tx_buffer *buffer) 39 38 { 40 - return tx_queue->insert_count & tx_queue->ptr_mask; 39 + unsigned int index = efx_tx_queue_get_insert_index(tx_queue); 40 + struct efx_buffer *page_buf = 41 + &tx_queue->cb_page[index >> (PAGE_SHIFT - EFX_TX_CB_ORDER)]; 42 + unsigned int offset = 43 + ((index << EFX_TX_CB_ORDER) + NET_IP_ALIGN) & (PAGE_SIZE - 1); 44 + 45 + if (unlikely(!page_buf->addr) && 46 + efx_nic_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE, 47 + GFP_ATOMIC)) 48 + return NULL; 49 + buffer->dma_addr = page_buf->dma_addr + offset; 50 + buffer->unmap_len = 0; 51 + return (u8 *)page_buf->addr + offset; 41 52 } 42 53 43 - static inline struct efx_tx_buffer * 44 - __efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue) 54 + u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue, 55 + struct efx_tx_buffer *buffer, size_t len) 45 56 { 46 - return &tx_queue->buffer[efx_tx_queue_get_insert_index(tx_queue)]; 47 - } 48 - 49 - static inline struct efx_tx_buffer * 50 - efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue) 51 - { 52 - struct efx_tx_buffer *buffer = 53 - __efx_tx_queue_get_insert_buffer(tx_queue); 54 - 55 - EFX_BUG_ON_PARANOID(buffer->len); 56 - EFX_BUG_ON_PARANOID(buffer->flags); 57 - EFX_BUG_ON_PARANOID(buffer->unmap_len); 58 - 59 - return buffer; 57 + if (len > EFX_TX_CB_SIZE) 58 + return NULL; 59 + return efx_tx_get_copy_buffer(tx_queue, buffer); 60 60 } 61 61 62 62 static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue, ··· 90 88 91 89 buffer->len = 0; 92 90 buffer->flags = 0; 93 - } 94 - 95 - static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, 96 - struct sk_buff *skb); 97 - 98 - static inline unsigned 99 - efx_max_tx_len(struct efx_nic *efx, dma_addr_t dma_addr) 100 - { 101 - /* Depending on the NIC revision, we can use descriptor 102 - * lengths up to 8K or 8K-1. However, since PCI Express 103 - * devices must split read requests at 4K boundaries, there is 104 - * little benefit from using descriptors that cross those 105 - * boundaries and we keep things simple by not doing so. 106 - */ 107 - unsigned len = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1; 108 - 109 - /* Work around hardware bug for unaligned buffers. */ 110 - if (EFX_WORKAROUND_5391(efx) && (dma_addr & 0xf)) 111 - len = min_t(unsigned, len, 512 - (dma_addr & 0xf)); 112 - 113 - return len; 114 91 } 115 92 116 93 unsigned int efx_tx_max_skb_descs(struct efx_nic *efx) ··· 152 171 if (likely(!efx->loopback_selftest)) 153 172 netif_tx_start_queue(txq1->core_txq); 154 173 } 174 + } 175 + 176 + static int efx_enqueue_skb_copy(struct efx_tx_queue *tx_queue, 177 + struct sk_buff *skb) 178 + { 179 + unsigned int min_len = tx_queue->tx_min_size; 180 + unsigned int copy_len = skb->len; 181 + struct efx_tx_buffer *buffer; 182 + u8 *copy_buffer; 183 + int rc; 184 + 185 + EFX_BUG_ON_PARANOID(copy_len > EFX_TX_CB_SIZE); 186 + 187 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 188 + 189 + copy_buffer = efx_tx_get_copy_buffer(tx_queue, buffer); 190 + if (unlikely(!copy_buffer)) 191 + return -ENOMEM; 192 + 193 + rc = skb_copy_bits(skb, 0, copy_buffer, copy_len); 194 + EFX_WARN_ON_PARANOID(rc); 195 + if (unlikely(copy_len < min_len)) { 196 + memset(copy_buffer + copy_len, 0, min_len - copy_len); 197 + buffer->len = min_len; 198 + } else { 199 + buffer->len = copy_len; 200 + } 201 + 202 + buffer->skb = skb; 203 + buffer->flags = EFX_TX_BUF_SKB; 204 + 205 + ++tx_queue->insert_count; 206 + return rc; 155 207 } 156 208 157 209 #ifdef EFX_USE_PIO ··· 281 267 EFX_BUG_ON_PARANOID(skb_shinfo(skb)->frag_list); 282 268 } 283 269 284 - static struct efx_tx_buffer * 285 - efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue, struct sk_buff *skb) 270 + static int efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue, 271 + struct sk_buff *skb) 286 272 { 287 273 struct efx_tx_buffer *buffer = 288 274 efx_tx_queue_get_insert_buffer(tx_queue); ··· 306 292 efx_flush_copy_buffer(tx_queue->efx, piobuf, &copy_buf); 307 293 } else { 308 294 /* Pad the write to the size of a cache line. 309 - * We can do this because we know the skb_shared_info sruct is 295 + * We can do this because we know the skb_shared_info struct is 310 296 * after the source, and the destination buffer is big enough. 311 297 */ 312 298 BUILD_BUG_ON(L1_CACHE_BYTES > ··· 315 301 ALIGN(skb->len, L1_CACHE_BYTES) >> 3); 316 302 } 317 303 304 + buffer->skb = skb; 305 + buffer->flags = EFX_TX_BUF_SKB | EFX_TX_BUF_OPTION; 306 + 318 307 EFX_POPULATE_QWORD_5(buffer->option, 319 308 ESF_DZ_TX_DESC_IS_OPT, 1, 320 309 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_PIO, ··· 325 308 ESF_DZ_TX_PIO_BYTE_CNT, skb->len, 326 309 ESF_DZ_TX_PIO_BUF_ADDR, 327 310 tx_queue->piobuf_offset); 328 - ++tx_queue->pio_packets; 329 311 ++tx_queue->insert_count; 330 - return buffer; 312 + return 0; 331 313 } 332 314 #endif /* EFX_USE_PIO */ 315 + 316 + static struct efx_tx_buffer *efx_tx_map_chunk(struct efx_tx_queue *tx_queue, 317 + dma_addr_t dma_addr, 318 + size_t len) 319 + { 320 + const struct efx_nic_type *nic_type = tx_queue->efx->type; 321 + struct efx_tx_buffer *buffer; 322 + unsigned int dma_len; 323 + 324 + /* Map the fragment taking account of NIC-dependent DMA limits. */ 325 + do { 326 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 327 + dma_len = nic_type->tx_limit_len(tx_queue, dma_addr, len); 328 + 329 + buffer->len = dma_len; 330 + buffer->dma_addr = dma_addr; 331 + buffer->flags = EFX_TX_BUF_CONT; 332 + len -= dma_len; 333 + dma_addr += dma_len; 334 + ++tx_queue->insert_count; 335 + } while (len); 336 + 337 + return buffer; 338 + } 339 + 340 + /* Map all data from an SKB for DMA and create descriptors on the queue. 341 + */ 342 + static int efx_tx_map_data(struct efx_tx_queue *tx_queue, struct sk_buff *skb, 343 + unsigned int segment_count) 344 + { 345 + struct efx_nic *efx = tx_queue->efx; 346 + struct device *dma_dev = &efx->pci_dev->dev; 347 + unsigned int frag_index, nr_frags; 348 + dma_addr_t dma_addr, unmap_addr; 349 + unsigned short dma_flags; 350 + size_t len, unmap_len; 351 + 352 + nr_frags = skb_shinfo(skb)->nr_frags; 353 + frag_index = 0; 354 + 355 + /* Map header data. */ 356 + len = skb_headlen(skb); 357 + dma_addr = dma_map_single(dma_dev, skb->data, len, DMA_TO_DEVICE); 358 + dma_flags = EFX_TX_BUF_MAP_SINGLE; 359 + unmap_len = len; 360 + unmap_addr = dma_addr; 361 + 362 + if (unlikely(dma_mapping_error(dma_dev, dma_addr))) 363 + return -EIO; 364 + 365 + if (segment_count) { 366 + /* For TSO we need to put the header in to a separate 367 + * descriptor. Map this separately if necessary. 368 + */ 369 + size_t header_len = skb_transport_header(skb) - skb->data + 370 + (tcp_hdr(skb)->doff << 2u); 371 + 372 + if (header_len != len) { 373 + tx_queue->tso_long_headers++; 374 + efx_tx_map_chunk(tx_queue, dma_addr, header_len); 375 + len -= header_len; 376 + dma_addr += header_len; 377 + } 378 + } 379 + 380 + /* Add descriptors for each fragment. */ 381 + do { 382 + struct efx_tx_buffer *buffer; 383 + skb_frag_t *fragment; 384 + 385 + buffer = efx_tx_map_chunk(tx_queue, dma_addr, len); 386 + 387 + /* The final descriptor for a fragment is responsible for 388 + * unmapping the whole fragment. 389 + */ 390 + buffer->flags = EFX_TX_BUF_CONT | dma_flags; 391 + buffer->unmap_len = unmap_len; 392 + buffer->dma_offset = buffer->dma_addr - unmap_addr; 393 + 394 + if (frag_index >= nr_frags) { 395 + /* Store SKB details with the final buffer for 396 + * the completion. 397 + */ 398 + buffer->skb = skb; 399 + buffer->flags = EFX_TX_BUF_SKB | dma_flags; 400 + return 0; 401 + } 402 + 403 + /* Move on to the next fragment. */ 404 + fragment = &skb_shinfo(skb)->frags[frag_index++]; 405 + len = skb_frag_size(fragment); 406 + dma_addr = skb_frag_dma_map(dma_dev, fragment, 407 + 0, len, DMA_TO_DEVICE); 408 + dma_flags = 0; 409 + unmap_len = len; 410 + unmap_addr = dma_addr; 411 + 412 + if (unlikely(dma_mapping_error(dma_dev, dma_addr))) 413 + return -EIO; 414 + } while (1); 415 + } 416 + 417 + /* Remove buffers put into a tx_queue. None of the buffers must have 418 + * an skb attached. 419 + */ 420 + static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue) 421 + { 422 + struct efx_tx_buffer *buffer; 423 + 424 + /* Work backwards until we hit the original insert pointer value */ 425 + while (tx_queue->insert_count != tx_queue->write_count) { 426 + --tx_queue->insert_count; 427 + buffer = __efx_tx_queue_get_insert_buffer(tx_queue); 428 + efx_dequeue_buffer(tx_queue, buffer, NULL, NULL); 429 + } 430 + } 431 + 432 + /* 433 + * Fallback to software TSO. 434 + * 435 + * This is used if we are unable to send a GSO packet through hardware TSO. 436 + * This should only ever happen due to per-queue restrictions - unsupported 437 + * packets should first be filtered by the feature flags. 438 + * 439 + * Returns 0 on success, error code otherwise. 440 + */ 441 + static int efx_tx_tso_fallback(struct efx_tx_queue *tx_queue, 442 + struct sk_buff *skb) 443 + { 444 + struct sk_buff *segments, *next; 445 + 446 + segments = skb_gso_segment(skb, 0); 447 + if (IS_ERR(segments)) 448 + return PTR_ERR(segments); 449 + 450 + dev_kfree_skb_any(skb); 451 + skb = segments; 452 + 453 + while (skb) { 454 + next = skb->next; 455 + skb->next = NULL; 456 + 457 + if (next) 458 + skb->xmit_more = true; 459 + efx_enqueue_skb(tx_queue, skb); 460 + skb = next; 461 + } 462 + 463 + return 0; 464 + } 333 465 334 466 /* 335 467 * Add a socket buffer to a TX queue ··· 498 332 */ 499 333 netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb) 500 334 { 501 - struct efx_nic *efx = tx_queue->efx; 502 - struct device *dma_dev = &efx->pci_dev->dev; 503 - struct efx_tx_buffer *buffer; 504 - unsigned int old_insert_count = tx_queue->insert_count; 505 - skb_frag_t *fragment; 506 - unsigned int len, unmap_len = 0; 507 - dma_addr_t dma_addr, unmap_addr = 0; 508 - unsigned int dma_len; 509 - unsigned short dma_flags; 510 - int i = 0; 335 + bool data_mapped = false; 336 + unsigned int segments; 337 + unsigned int skb_len; 338 + int rc; 511 339 512 - if (skb_shinfo(skb)->gso_size) 513 - return efx_enqueue_skb_tso(tx_queue, skb); 340 + skb_len = skb->len; 341 + segments = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 0; 342 + if (segments == 1) 343 + segments = 0; /* Don't use TSO for a single segment. */ 514 344 515 - /* Get size of the initial fragment */ 516 - len = skb_headlen(skb); 517 - 518 - /* Pad if necessary */ 519 - if (EFX_WORKAROUND_15592(efx) && skb->len <= 32) { 520 - EFX_BUG_ON_PARANOID(skb->data_len); 521 - len = 32 + 1; 522 - if (skb_pad(skb, len - skb->len)) 523 - return NETDEV_TX_OK; 524 - } 525 - 526 - /* Consider using PIO for short packets */ 527 - #ifdef EFX_USE_PIO 528 - if (skb->len <= efx_piobuf_size && !skb->xmit_more && 529 - efx_nic_may_tx_pio(tx_queue)) { 530 - buffer = efx_enqueue_skb_pio(tx_queue, skb); 531 - dma_flags = EFX_TX_BUF_OPTION; 532 - goto finish_packet; 533 - } 534 - #endif 535 - 536 - /* Map for DMA. Use dma_map_single rather than dma_map_page 537 - * since this is more efficient on machines with sparse 538 - * memory. 345 + /* Handle TSO first - it's *possible* (although unlikely) that we might 346 + * be passed a packet to segment that's smaller than the copybreak/PIO 347 + * size limit. 539 348 */ 540 - dma_flags = EFX_TX_BUF_MAP_SINGLE; 541 - dma_addr = dma_map_single(dma_dev, skb->data, len, PCI_DMA_TODEVICE); 542 - 543 - /* Process all fragments */ 544 - while (1) { 545 - if (unlikely(dma_mapping_error(dma_dev, dma_addr))) 546 - goto dma_err; 547 - 548 - /* Store fields for marking in the per-fragment final 549 - * descriptor */ 550 - unmap_len = len; 551 - unmap_addr = dma_addr; 552 - 553 - /* Add to TX queue, splitting across DMA boundaries */ 554 - do { 555 - buffer = efx_tx_queue_get_insert_buffer(tx_queue); 556 - 557 - dma_len = efx_max_tx_len(efx, dma_addr); 558 - if (likely(dma_len >= len)) 559 - dma_len = len; 560 - 561 - /* Fill out per descriptor fields */ 562 - buffer->len = dma_len; 563 - buffer->dma_addr = dma_addr; 564 - buffer->flags = EFX_TX_BUF_CONT; 565 - len -= dma_len; 566 - dma_addr += dma_len; 567 - ++tx_queue->insert_count; 568 - } while (len); 569 - 570 - /* Transfer ownership of the unmapping to the final buffer */ 571 - buffer->flags = EFX_TX_BUF_CONT | dma_flags; 572 - buffer->unmap_len = unmap_len; 573 - buffer->dma_offset = buffer->dma_addr - unmap_addr; 574 - unmap_len = 0; 575 - 576 - /* Get address and size of next fragment */ 577 - if (i >= skb_shinfo(skb)->nr_frags) 578 - break; 579 - fragment = &skb_shinfo(skb)->frags[i]; 580 - len = skb_frag_size(fragment); 581 - i++; 582 - /* Map for DMA */ 583 - dma_flags = 0; 584 - dma_addr = skb_frag_dma_map(dma_dev, fragment, 0, len, 585 - DMA_TO_DEVICE); 349 + if (segments) { 350 + EFX_BUG_ON_PARANOID(!tx_queue->handle_tso); 351 + rc = tx_queue->handle_tso(tx_queue, skb, &data_mapped); 352 + if (rc == -EINVAL) { 353 + rc = efx_tx_tso_fallback(tx_queue, skb); 354 + tx_queue->tso_fallbacks++; 355 + if (rc == 0) 356 + return 0; 357 + } 358 + if (rc) 359 + goto err; 360 + #ifdef EFX_USE_PIO 361 + } else if (skb_len <= efx_piobuf_size && !skb->xmit_more && 362 + efx_nic_may_tx_pio(tx_queue)) { 363 + /* Use PIO for short packets with an empty queue. */ 364 + if (efx_enqueue_skb_pio(tx_queue, skb)) 365 + goto err; 366 + tx_queue->pio_packets++; 367 + data_mapped = true; 368 + #endif 369 + } else if (skb_len < tx_queue->tx_min_size || 370 + (skb->data_len && skb_len <= EFX_TX_CB_SIZE)) { 371 + /* Pad short packets or coalesce short fragmented packets. */ 372 + if (efx_enqueue_skb_copy(tx_queue, skb)) 373 + goto err; 374 + tx_queue->cb_packets++; 375 + data_mapped = true; 586 376 } 587 377 588 - /* Transfer ownership of the skb to the final buffer */ 589 - #ifdef EFX_USE_PIO 590 - finish_packet: 591 - #endif 592 - buffer->skb = skb; 593 - buffer->flags = EFX_TX_BUF_SKB | dma_flags; 378 + /* Map for DMA and create descriptors if we haven't done so already. */ 379 + if (!data_mapped && (efx_tx_map_data(tx_queue, skb, segments))) 380 + goto err; 594 381 595 - netdev_tx_sent_queue(tx_queue->core_txq, skb->len); 596 - 597 - efx_tx_maybe_stop_queue(tx_queue); 382 + /* Update BQL */ 383 + netdev_tx_sent_queue(tx_queue->core_txq, skb_len); 598 384 599 385 /* Pass off to hardware */ 600 386 if (!skb->xmit_more || netif_xmit_stopped(tx_queue->core_txq)) { ··· 564 446 tx_queue->xmit_more_available = skb->xmit_more; 565 447 } 566 448 567 - tx_queue->tx_packets++; 449 + if (segments) { 450 + tx_queue->tso_bursts++; 451 + tx_queue->tso_packets += segments; 452 + tx_queue->tx_packets += segments; 453 + } else { 454 + tx_queue->tx_packets++; 455 + } 456 + 457 + efx_tx_maybe_stop_queue(tx_queue); 568 458 569 459 return NETDEV_TX_OK; 570 460 571 - dma_err: 572 - netif_err(efx, tx_err, efx->net_dev, 573 - " TX queue %d could not map skb with %d bytes %d " 574 - "fragments for DMA\n", tx_queue->queue, skb->len, 575 - skb_shinfo(skb)->nr_frags + 1); 576 461 577 - /* Mark the packet as transmitted, and free the SKB ourselves */ 462 + err: 463 + efx_enqueue_unwind(tx_queue); 578 464 dev_kfree_skb_any(skb); 579 - 580 - /* Work backwards until we hit the original insert pointer value */ 581 - while (tx_queue->insert_count != old_insert_count) { 582 - unsigned int pkts_compl = 0, bytes_compl = 0; 583 - --tx_queue->insert_count; 584 - buffer = __efx_tx_queue_get_insert_buffer(tx_queue); 585 - efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl); 586 - } 587 - 588 - /* Free the fragment we were mid-way through pushing */ 589 - if (unmap_len) { 590 - if (dma_flags & EFX_TX_BUF_MAP_SINGLE) 591 - dma_unmap_single(dma_dev, unmap_addr, unmap_len, 592 - DMA_TO_DEVICE); 593 - else 594 - dma_unmap_page(dma_dev, unmap_addr, unmap_len, 595 - DMA_TO_DEVICE); 596 - } 597 - 598 465 return NETDEV_TX_OK; 599 466 } 600 467 ··· 770 667 } 771 668 } 772 669 773 - /* Size of page-based TSO header buffers. Larger blocks must be 774 - * allocated from the heap. 775 - */ 776 - #define TSOH_STD_SIZE 128 777 - #define TSOH_PER_PAGE (PAGE_SIZE / TSOH_STD_SIZE) 778 - 779 - /* At most half the descriptors in the queue at any time will refer to 780 - * a TSO header buffer, since they must always be followed by a 781 - * payload descriptor referring to an skb. 782 - */ 783 - static unsigned int efx_tsoh_page_count(struct efx_tx_queue *tx_queue) 670 + static unsigned int efx_tx_cb_page_count(struct efx_tx_queue *tx_queue) 784 671 { 785 - return DIV_ROUND_UP(tx_queue->ptr_mask + 1, 2 * TSOH_PER_PAGE); 672 + return DIV_ROUND_UP(tx_queue->ptr_mask + 1, PAGE_SIZE >> EFX_TX_CB_ORDER); 786 673 } 787 674 788 675 int efx_probe_tx_queue(struct efx_tx_queue *tx_queue) ··· 796 703 if (!tx_queue->buffer) 797 704 return -ENOMEM; 798 705 799 - if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD) { 800 - tx_queue->tsoh_page = 801 - kcalloc(efx_tsoh_page_count(tx_queue), 802 - sizeof(tx_queue->tsoh_page[0]), GFP_KERNEL); 803 - if (!tx_queue->tsoh_page) { 804 - rc = -ENOMEM; 805 - goto fail1; 806 - } 706 + tx_queue->cb_page = kcalloc(efx_tx_cb_page_count(tx_queue), 707 + sizeof(tx_queue->cb_page[0]), GFP_KERNEL); 708 + if (!tx_queue->cb_page) { 709 + rc = -ENOMEM; 710 + goto fail1; 807 711 } 808 712 809 713 /* Allocate hardware ring */ ··· 811 721 return 0; 812 722 813 723 fail2: 814 - kfree(tx_queue->tsoh_page); 815 - tx_queue->tsoh_page = NULL; 724 + kfree(tx_queue->cb_page); 725 + tx_queue->cb_page = NULL; 816 726 fail1: 817 727 kfree(tx_queue->buffer); 818 728 tx_queue->buffer = NULL; ··· 821 731 822 732 void efx_init_tx_queue(struct efx_tx_queue *tx_queue) 823 733 { 824 - netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev, 734 + struct efx_nic *efx = tx_queue->efx; 735 + 736 + netif_dbg(efx, drv, efx->net_dev, 825 737 "initialising TX queue %d\n", tx_queue->queue); 826 738 827 739 tx_queue->insert_count = 0; ··· 833 741 tx_queue->old_read_count = 0; 834 742 tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID; 835 743 tx_queue->xmit_more_available = false; 744 + 745 + /* Set up default function pointers. These may get replaced by 746 + * efx_nic_init_tx() based off NIC/queue capabilities. 747 + */ 748 + tx_queue->handle_tso = efx_enqueue_skb_tso; 749 + 750 + /* Some older hardware requires Tx writes larger than 32. */ 751 + tx_queue->tx_min_size = EFX_WORKAROUND_15592(efx) ? 33 : 0; 836 752 837 753 /* Set up TX descriptor ring */ 838 754 efx_nic_init_tx(tx_queue); ··· 881 781 "destroying TX queue %d\n", tx_queue->queue); 882 782 efx_nic_remove_tx(tx_queue); 883 783 884 - if (tx_queue->tsoh_page) { 885 - for (i = 0; i < efx_tsoh_page_count(tx_queue); i++) 784 + if (tx_queue->cb_page) { 785 + for (i = 0; i < efx_tx_cb_page_count(tx_queue); i++) 886 786 efx_nic_free_buffer(tx_queue->efx, 887 - &tx_queue->tsoh_page[i]); 888 - kfree(tx_queue->tsoh_page); 889 - tx_queue->tsoh_page = NULL; 787 + &tx_queue->cb_page[i]); 788 + kfree(tx_queue->cb_page); 789 + tx_queue->cb_page = NULL; 890 790 } 891 791 892 792 kfree(tx_queue->buffer); 893 793 tx_queue->buffer = NULL; 894 - } 895 - 896 - 897 - /* Efx TCP segmentation acceleration. 898 - * 899 - * Why? Because by doing it here in the driver we can go significantly 900 - * faster than the GSO. 901 - * 902 - * Requires TX checksum offload support. 903 - */ 904 - 905 - #define PTR_DIFF(p1, p2) ((u8 *)(p1) - (u8 *)(p2)) 906 - 907 - /** 908 - * struct tso_state - TSO state for an SKB 909 - * @out_len: Remaining length in current segment 910 - * @seqnum: Current sequence number 911 - * @ipv4_id: Current IPv4 ID, host endian 912 - * @packet_space: Remaining space in current packet 913 - * @dma_addr: DMA address of current position 914 - * @in_len: Remaining length in current SKB fragment 915 - * @unmap_len: Length of SKB fragment 916 - * @unmap_addr: DMA address of SKB fragment 917 - * @dma_flags: TX buffer flags for DMA mapping - %EFX_TX_BUF_MAP_SINGLE or 0 918 - * @protocol: Network protocol (after any VLAN header) 919 - * @ip_off: Offset of IP header 920 - * @tcp_off: Offset of TCP header 921 - * @header_len: Number of bytes of header 922 - * @ip_base_len: IPv4 tot_len or IPv6 payload_len, before TCP payload 923 - * @header_dma_addr: Header DMA address, when using option descriptors 924 - * @header_unmap_len: Header DMA mapped length, or 0 if not using option 925 - * descriptors 926 - * 927 - * The state used during segmentation. It is put into this data structure 928 - * just to make it easy to pass into inline functions. 929 - */ 930 - struct tso_state { 931 - /* Output position */ 932 - unsigned out_len; 933 - unsigned seqnum; 934 - u16 ipv4_id; 935 - unsigned packet_space; 936 - 937 - /* Input position */ 938 - dma_addr_t dma_addr; 939 - unsigned in_len; 940 - unsigned unmap_len; 941 - dma_addr_t unmap_addr; 942 - unsigned short dma_flags; 943 - 944 - __be16 protocol; 945 - unsigned int ip_off; 946 - unsigned int tcp_off; 947 - unsigned header_len; 948 - unsigned int ip_base_len; 949 - dma_addr_t header_dma_addr; 950 - unsigned int header_unmap_len; 951 - }; 952 - 953 - 954 - /* 955 - * Verify that our various assumptions about sk_buffs and the conditions 956 - * under which TSO will be attempted hold true. Return the protocol number. 957 - */ 958 - static __be16 efx_tso_check_protocol(struct sk_buff *skb) 959 - { 960 - __be16 protocol = skb->protocol; 961 - 962 - EFX_BUG_ON_PARANOID(((struct ethhdr *)skb->data)->h_proto != 963 - protocol); 964 - if (protocol == htons(ETH_P_8021Q)) { 965 - struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 966 - protocol = veh->h_vlan_encapsulated_proto; 967 - } 968 - 969 - if (protocol == htons(ETH_P_IP)) { 970 - EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP); 971 - } else { 972 - EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IPV6)); 973 - EFX_BUG_ON_PARANOID(ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP); 974 - } 975 - EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data) 976 - + (tcp_hdr(skb)->doff << 2u)) > 977 - skb_headlen(skb)); 978 - 979 - return protocol; 980 - } 981 - 982 - static u8 *efx_tsoh_get_buffer(struct efx_tx_queue *tx_queue, 983 - struct efx_tx_buffer *buffer, unsigned int len) 984 - { 985 - u8 *result; 986 - 987 - EFX_BUG_ON_PARANOID(buffer->len); 988 - EFX_BUG_ON_PARANOID(buffer->flags); 989 - EFX_BUG_ON_PARANOID(buffer->unmap_len); 990 - 991 - if (likely(len <= TSOH_STD_SIZE - NET_IP_ALIGN)) { 992 - unsigned index = 993 - (tx_queue->insert_count & tx_queue->ptr_mask) / 2; 994 - struct efx_buffer *page_buf = 995 - &tx_queue->tsoh_page[index / TSOH_PER_PAGE]; 996 - unsigned offset = 997 - TSOH_STD_SIZE * (index % TSOH_PER_PAGE) + NET_IP_ALIGN; 998 - 999 - if (unlikely(!page_buf->addr) && 1000 - efx_nic_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE, 1001 - GFP_ATOMIC)) 1002 - return NULL; 1003 - 1004 - result = (u8 *)page_buf->addr + offset; 1005 - buffer->dma_addr = page_buf->dma_addr + offset; 1006 - buffer->flags = EFX_TX_BUF_CONT; 1007 - } else { 1008 - tx_queue->tso_long_headers++; 1009 - 1010 - buffer->heap_buf = kmalloc(NET_IP_ALIGN + len, GFP_ATOMIC); 1011 - if (unlikely(!buffer->heap_buf)) 1012 - return NULL; 1013 - result = (u8 *)buffer->heap_buf + NET_IP_ALIGN; 1014 - buffer->flags = EFX_TX_BUF_CONT | EFX_TX_BUF_HEAP; 1015 - } 1016 - 1017 - buffer->len = len; 1018 - 1019 - return result; 1020 - } 1021 - 1022 - /** 1023 - * efx_tx_queue_insert - push descriptors onto the TX queue 1024 - * @tx_queue: Efx TX queue 1025 - * @dma_addr: DMA address of fragment 1026 - * @len: Length of fragment 1027 - * @final_buffer: The final buffer inserted into the queue 1028 - * 1029 - * Push descriptors onto the TX queue. 1030 - */ 1031 - static void efx_tx_queue_insert(struct efx_tx_queue *tx_queue, 1032 - dma_addr_t dma_addr, unsigned len, 1033 - struct efx_tx_buffer **final_buffer) 1034 - { 1035 - struct efx_tx_buffer *buffer; 1036 - struct efx_nic *efx = tx_queue->efx; 1037 - unsigned dma_len; 1038 - 1039 - EFX_BUG_ON_PARANOID(len <= 0); 1040 - 1041 - while (1) { 1042 - buffer = efx_tx_queue_get_insert_buffer(tx_queue); 1043 - ++tx_queue->insert_count; 1044 - 1045 - EFX_BUG_ON_PARANOID(tx_queue->insert_count - 1046 - tx_queue->read_count >= 1047 - efx->txq_entries); 1048 - 1049 - buffer->dma_addr = dma_addr; 1050 - 1051 - dma_len = efx_max_tx_len(efx, dma_addr); 1052 - 1053 - /* If there is enough space to send then do so */ 1054 - if (dma_len >= len) 1055 - break; 1056 - 1057 - buffer->len = dma_len; 1058 - buffer->flags = EFX_TX_BUF_CONT; 1059 - dma_addr += dma_len; 1060 - len -= dma_len; 1061 - } 1062 - 1063 - EFX_BUG_ON_PARANOID(!len); 1064 - buffer->len = len; 1065 - *final_buffer = buffer; 1066 - } 1067 - 1068 - 1069 - /* 1070 - * Put a TSO header into the TX queue. 1071 - * 1072 - * This is special-cased because we know that it is small enough to fit in 1073 - * a single fragment, and we know it doesn't cross a page boundary. It 1074 - * also allows us to not worry about end-of-packet etc. 1075 - */ 1076 - static int efx_tso_put_header(struct efx_tx_queue *tx_queue, 1077 - struct efx_tx_buffer *buffer, u8 *header) 1078 - { 1079 - if (unlikely(buffer->flags & EFX_TX_BUF_HEAP)) { 1080 - buffer->dma_addr = dma_map_single(&tx_queue->efx->pci_dev->dev, 1081 - header, buffer->len, 1082 - DMA_TO_DEVICE); 1083 - if (unlikely(dma_mapping_error(&tx_queue->efx->pci_dev->dev, 1084 - buffer->dma_addr))) { 1085 - kfree(buffer->heap_buf); 1086 - buffer->len = 0; 1087 - buffer->flags = 0; 1088 - return -ENOMEM; 1089 - } 1090 - buffer->unmap_len = buffer->len; 1091 - buffer->dma_offset = 0; 1092 - buffer->flags |= EFX_TX_BUF_MAP_SINGLE; 1093 - } 1094 - 1095 - ++tx_queue->insert_count; 1096 - return 0; 1097 - } 1098 - 1099 - 1100 - /* Remove buffers put into a tx_queue. None of the buffers must have 1101 - * an skb attached. 1102 - */ 1103 - static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue, 1104 - unsigned int insert_count) 1105 - { 1106 - struct efx_tx_buffer *buffer; 1107 - 1108 - /* Work backwards until we hit the original insert pointer value */ 1109 - while (tx_queue->insert_count != insert_count) { 1110 - --tx_queue->insert_count; 1111 - buffer = __efx_tx_queue_get_insert_buffer(tx_queue); 1112 - efx_dequeue_buffer(tx_queue, buffer, NULL, NULL); 1113 - } 1114 - } 1115 - 1116 - 1117 - /* Parse the SKB header and initialise state. */ 1118 - static int tso_start(struct tso_state *st, struct efx_nic *efx, 1119 - struct efx_tx_queue *tx_queue, 1120 - const struct sk_buff *skb) 1121 - { 1122 - struct device *dma_dev = &efx->pci_dev->dev; 1123 - unsigned int header_len, in_len; 1124 - bool use_opt_desc = false; 1125 - dma_addr_t dma_addr; 1126 - 1127 - if (tx_queue->tso_version == 1) 1128 - use_opt_desc = true; 1129 - 1130 - st->ip_off = skb_network_header(skb) - skb->data; 1131 - st->tcp_off = skb_transport_header(skb) - skb->data; 1132 - header_len = st->tcp_off + (tcp_hdr(skb)->doff << 2u); 1133 - in_len = skb_headlen(skb) - header_len; 1134 - st->header_len = header_len; 1135 - st->in_len = in_len; 1136 - if (st->protocol == htons(ETH_P_IP)) { 1137 - st->ip_base_len = st->header_len - st->ip_off; 1138 - st->ipv4_id = ntohs(ip_hdr(skb)->id); 1139 - } else { 1140 - st->ip_base_len = st->header_len - st->tcp_off; 1141 - st->ipv4_id = 0; 1142 - } 1143 - st->seqnum = ntohl(tcp_hdr(skb)->seq); 1144 - 1145 - EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg); 1146 - EFX_BUG_ON_PARANOID(tcp_hdr(skb)->syn); 1147 - EFX_BUG_ON_PARANOID(tcp_hdr(skb)->rst); 1148 - 1149 - st->out_len = skb->len - header_len; 1150 - 1151 - if (!use_opt_desc) { 1152 - st->header_unmap_len = 0; 1153 - 1154 - if (likely(in_len == 0)) { 1155 - st->dma_flags = 0; 1156 - st->unmap_len = 0; 1157 - return 0; 1158 - } 1159 - 1160 - dma_addr = dma_map_single(dma_dev, skb->data + header_len, 1161 - in_len, DMA_TO_DEVICE); 1162 - st->dma_flags = EFX_TX_BUF_MAP_SINGLE; 1163 - st->dma_addr = dma_addr; 1164 - st->unmap_addr = dma_addr; 1165 - st->unmap_len = in_len; 1166 - } else { 1167 - dma_addr = dma_map_single(dma_dev, skb->data, 1168 - skb_headlen(skb), DMA_TO_DEVICE); 1169 - st->header_dma_addr = dma_addr; 1170 - st->header_unmap_len = skb_headlen(skb); 1171 - st->dma_flags = 0; 1172 - st->dma_addr = dma_addr + header_len; 1173 - st->unmap_len = 0; 1174 - } 1175 - 1176 - return unlikely(dma_mapping_error(dma_dev, dma_addr)) ? -ENOMEM : 0; 1177 - } 1178 - 1179 - static int tso_get_fragment(struct tso_state *st, struct efx_nic *efx, 1180 - skb_frag_t *frag) 1181 - { 1182 - st->unmap_addr = skb_frag_dma_map(&efx->pci_dev->dev, frag, 0, 1183 - skb_frag_size(frag), DMA_TO_DEVICE); 1184 - if (likely(!dma_mapping_error(&efx->pci_dev->dev, st->unmap_addr))) { 1185 - st->dma_flags = 0; 1186 - st->unmap_len = skb_frag_size(frag); 1187 - st->in_len = skb_frag_size(frag); 1188 - st->dma_addr = st->unmap_addr; 1189 - return 0; 1190 - } 1191 - return -ENOMEM; 1192 - } 1193 - 1194 - 1195 - /** 1196 - * tso_fill_packet_with_fragment - form descriptors for the current fragment 1197 - * @tx_queue: Efx TX queue 1198 - * @skb: Socket buffer 1199 - * @st: TSO state 1200 - * 1201 - * Form descriptors for the current fragment, until we reach the end 1202 - * of fragment or end-of-packet. 1203 - */ 1204 - static void tso_fill_packet_with_fragment(struct efx_tx_queue *tx_queue, 1205 - const struct sk_buff *skb, 1206 - struct tso_state *st) 1207 - { 1208 - struct efx_tx_buffer *buffer; 1209 - int n; 1210 - 1211 - if (st->in_len == 0) 1212 - return; 1213 - if (st->packet_space == 0) 1214 - return; 1215 - 1216 - EFX_BUG_ON_PARANOID(st->in_len <= 0); 1217 - EFX_BUG_ON_PARANOID(st->packet_space <= 0); 1218 - 1219 - n = min(st->in_len, st->packet_space); 1220 - 1221 - st->packet_space -= n; 1222 - st->out_len -= n; 1223 - st->in_len -= n; 1224 - 1225 - efx_tx_queue_insert(tx_queue, st->dma_addr, n, &buffer); 1226 - 1227 - if (st->out_len == 0) { 1228 - /* Transfer ownership of the skb */ 1229 - buffer->skb = skb; 1230 - buffer->flags = EFX_TX_BUF_SKB; 1231 - } else if (st->packet_space != 0) { 1232 - buffer->flags = EFX_TX_BUF_CONT; 1233 - } 1234 - 1235 - if (st->in_len == 0) { 1236 - /* Transfer ownership of the DMA mapping */ 1237 - buffer->unmap_len = st->unmap_len; 1238 - buffer->dma_offset = buffer->unmap_len - buffer->len; 1239 - buffer->flags |= st->dma_flags; 1240 - st->unmap_len = 0; 1241 - } 1242 - 1243 - st->dma_addr += n; 1244 - } 1245 - 1246 - 1247 - /** 1248 - * tso_start_new_packet - generate a new header and prepare for the new packet 1249 - * @tx_queue: Efx TX queue 1250 - * @skb: Socket buffer 1251 - * @st: TSO state 1252 - * 1253 - * Generate a new header and prepare for the new packet. Return 0 on 1254 - * success, or -%ENOMEM if failed to alloc header. 1255 - */ 1256 - static int tso_start_new_packet(struct efx_tx_queue *tx_queue, 1257 - const struct sk_buff *skb, 1258 - struct tso_state *st) 1259 - { 1260 - struct efx_tx_buffer *buffer = 1261 - efx_tx_queue_get_insert_buffer(tx_queue); 1262 - bool is_last = st->out_len <= skb_shinfo(skb)->gso_size; 1263 - u8 tcp_flags_clear; 1264 - 1265 - if (!is_last) { 1266 - st->packet_space = skb_shinfo(skb)->gso_size; 1267 - tcp_flags_clear = 0x09; /* mask out FIN and PSH */ 1268 - } else { 1269 - st->packet_space = st->out_len; 1270 - tcp_flags_clear = 0x00; 1271 - } 1272 - 1273 - if (!st->header_unmap_len) { 1274 - /* Allocate and insert a DMA-mapped header buffer. */ 1275 - struct tcphdr *tsoh_th; 1276 - unsigned ip_length; 1277 - u8 *header; 1278 - int rc; 1279 - 1280 - header = efx_tsoh_get_buffer(tx_queue, buffer, st->header_len); 1281 - if (!header) 1282 - return -ENOMEM; 1283 - 1284 - tsoh_th = (struct tcphdr *)(header + st->tcp_off); 1285 - 1286 - /* Copy and update the headers. */ 1287 - memcpy(header, skb->data, st->header_len); 1288 - 1289 - tsoh_th->seq = htonl(st->seqnum); 1290 - ((u8 *)tsoh_th)[13] &= ~tcp_flags_clear; 1291 - 1292 - ip_length = st->ip_base_len + st->packet_space; 1293 - 1294 - if (st->protocol == htons(ETH_P_IP)) { 1295 - struct iphdr *tsoh_iph = 1296 - (struct iphdr *)(header + st->ip_off); 1297 - 1298 - tsoh_iph->tot_len = htons(ip_length); 1299 - tsoh_iph->id = htons(st->ipv4_id); 1300 - } else { 1301 - struct ipv6hdr *tsoh_iph = 1302 - (struct ipv6hdr *)(header + st->ip_off); 1303 - 1304 - tsoh_iph->payload_len = htons(ip_length); 1305 - } 1306 - 1307 - rc = efx_tso_put_header(tx_queue, buffer, header); 1308 - if (unlikely(rc)) 1309 - return rc; 1310 - } else { 1311 - /* Send the original headers with a TSO option descriptor 1312 - * in front 1313 - */ 1314 - u8 tcp_flags = ((u8 *)tcp_hdr(skb))[13] & ~tcp_flags_clear; 1315 - 1316 - buffer->flags = EFX_TX_BUF_OPTION; 1317 - buffer->len = 0; 1318 - buffer->unmap_len = 0; 1319 - EFX_POPULATE_QWORD_5(buffer->option, 1320 - ESF_DZ_TX_DESC_IS_OPT, 1, 1321 - ESF_DZ_TX_OPTION_TYPE, 1322 - ESE_DZ_TX_OPTION_DESC_TSO, 1323 - ESF_DZ_TX_TSO_TCP_FLAGS, tcp_flags, 1324 - ESF_DZ_TX_TSO_IP_ID, st->ipv4_id, 1325 - ESF_DZ_TX_TSO_TCP_SEQNO, st->seqnum); 1326 - ++tx_queue->insert_count; 1327 - 1328 - /* We mapped the headers in tso_start(). Unmap them 1329 - * when the last segment is completed. 1330 - */ 1331 - buffer = efx_tx_queue_get_insert_buffer(tx_queue); 1332 - buffer->dma_addr = st->header_dma_addr; 1333 - buffer->len = st->header_len; 1334 - if (is_last) { 1335 - buffer->flags = EFX_TX_BUF_CONT | EFX_TX_BUF_MAP_SINGLE; 1336 - buffer->unmap_len = st->header_unmap_len; 1337 - buffer->dma_offset = 0; 1338 - /* Ensure we only unmap them once in case of a 1339 - * later DMA mapping error and rollback 1340 - */ 1341 - st->header_unmap_len = 0; 1342 - } else { 1343 - buffer->flags = EFX_TX_BUF_CONT; 1344 - buffer->unmap_len = 0; 1345 - } 1346 - ++tx_queue->insert_count; 1347 - } 1348 - 1349 - st->seqnum += skb_shinfo(skb)->gso_size; 1350 - 1351 - /* Linux leaves suitable gaps in the IP ID space for us to fill. */ 1352 - ++st->ipv4_id; 1353 - 1354 - ++tx_queue->tso_packets; 1355 - 1356 - ++tx_queue->tx_packets; 1357 - 1358 - return 0; 1359 - } 1360 - 1361 - 1362 - /** 1363 - * efx_enqueue_skb_tso - segment and transmit a TSO socket buffer 1364 - * @tx_queue: Efx TX queue 1365 - * @skb: Socket buffer 1366 - * 1367 - * Context: You must hold netif_tx_lock() to call this function. 1368 - * 1369 - * Add socket buffer @skb to @tx_queue, doing TSO or return != 0 if 1370 - * @skb was not enqueued. In all cases @skb is consumed. Return 1371 - * %NETDEV_TX_OK. 1372 - */ 1373 - static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, 1374 - struct sk_buff *skb) 1375 - { 1376 - struct efx_nic *efx = tx_queue->efx; 1377 - unsigned int old_insert_count = tx_queue->insert_count; 1378 - int frag_i, rc; 1379 - struct tso_state state; 1380 - 1381 - /* Find the packet protocol and sanity-check it */ 1382 - state.protocol = efx_tso_check_protocol(skb); 1383 - 1384 - rc = tso_start(&state, efx, tx_queue, skb); 1385 - if (rc) 1386 - goto mem_err; 1387 - 1388 - if (likely(state.in_len == 0)) { 1389 - /* Grab the first payload fragment. */ 1390 - EFX_BUG_ON_PARANOID(skb_shinfo(skb)->nr_frags < 1); 1391 - frag_i = 0; 1392 - rc = tso_get_fragment(&state, efx, 1393 - skb_shinfo(skb)->frags + frag_i); 1394 - if (rc) 1395 - goto mem_err; 1396 - } else { 1397 - /* Payload starts in the header area. */ 1398 - frag_i = -1; 1399 - } 1400 - 1401 - if (tso_start_new_packet(tx_queue, skb, &state) < 0) 1402 - goto mem_err; 1403 - 1404 - while (1) { 1405 - tso_fill_packet_with_fragment(tx_queue, skb, &state); 1406 - 1407 - /* Move onto the next fragment? */ 1408 - if (state.in_len == 0) { 1409 - if (++frag_i >= skb_shinfo(skb)->nr_frags) 1410 - /* End of payload reached. */ 1411 - break; 1412 - rc = tso_get_fragment(&state, efx, 1413 - skb_shinfo(skb)->frags + frag_i); 1414 - if (rc) 1415 - goto mem_err; 1416 - } 1417 - 1418 - /* Start at new packet? */ 1419 - if (state.packet_space == 0 && 1420 - tso_start_new_packet(tx_queue, skb, &state) < 0) 1421 - goto mem_err; 1422 - } 1423 - 1424 - netdev_tx_sent_queue(tx_queue->core_txq, skb->len); 1425 - 1426 - efx_tx_maybe_stop_queue(tx_queue); 1427 - 1428 - /* Pass off to hardware */ 1429 - if (!skb->xmit_more || netif_xmit_stopped(tx_queue->core_txq)) { 1430 - struct efx_tx_queue *txq2 = efx_tx_queue_partner(tx_queue); 1431 - 1432 - /* There could be packets left on the partner queue if those 1433 - * SKBs had skb->xmit_more set. If we do not push those they 1434 - * could be left for a long time and cause a netdev watchdog. 1435 - */ 1436 - if (txq2->xmit_more_available) 1437 - efx_nic_push_buffers(txq2); 1438 - 1439 - efx_nic_push_buffers(tx_queue); 1440 - } else { 1441 - tx_queue->xmit_more_available = skb->xmit_more; 1442 - } 1443 - 1444 - tx_queue->tso_bursts++; 1445 - return NETDEV_TX_OK; 1446 - 1447 - mem_err: 1448 - netif_err(efx, tx_err, efx->net_dev, 1449 - "Out of memory for TSO headers, or DMA mapping error\n"); 1450 - dev_kfree_skb_any(skb); 1451 - 1452 - /* Free the DMA mapping we were in the process of writing out */ 1453 - if (state.unmap_len) { 1454 - if (state.dma_flags & EFX_TX_BUF_MAP_SINGLE) 1455 - dma_unmap_single(&efx->pci_dev->dev, state.unmap_addr, 1456 - state.unmap_len, DMA_TO_DEVICE); 1457 - else 1458 - dma_unmap_page(&efx->pci_dev->dev, state.unmap_addr, 1459 - state.unmap_len, DMA_TO_DEVICE); 1460 - } 1461 - 1462 - /* Free the header DMA mapping, if using option descriptors */ 1463 - if (state.header_unmap_len) 1464 - dma_unmap_single(&efx->pci_dev->dev, state.header_dma_addr, 1465 - state.header_unmap_len, DMA_TO_DEVICE); 1466 - 1467 - efx_enqueue_unwind(tx_queue, old_insert_count); 1468 - return NETDEV_TX_OK; 1469 794 }
+27
drivers/net/ethernet/sfc/tx.h
··· 1 + /**************************************************************************** 2 + * Driver for Solarflare network controllers and boards 3 + * Copyright 2005-2006 Fen Systems Ltd. 4 + * Copyright 2006-2015 Solarflare Communications Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License version 2 as published 8 + * by the Free Software Foundation, incorporated herein by reference. 9 + */ 10 + 11 + #ifndef EFX_TX_H 12 + #define EFX_TX_H 13 + 14 + #include <linux/types.h> 15 + 16 + /* Driver internal tx-path related declarations. */ 17 + 18 + unsigned int efx_tx_limit_len(struct efx_tx_queue *tx_queue, 19 + dma_addr_t dma_addr, unsigned int len); 20 + 21 + u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue, 22 + struct efx_tx_buffer *buffer, size_t len); 23 + 24 + int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, struct sk_buff *skb, 25 + bool *data_mapped); 26 + 27 + #endif /* EFX_TX_H */
+452
drivers/net/ethernet/sfc/tx_tso.c
··· 1 + /**************************************************************************** 2 + * Driver for Solarflare network controllers and boards 3 + * Copyright 2005-2006 Fen Systems Ltd. 4 + * Copyright 2005-2015 Solarflare Communications Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License version 2 as published 8 + * by the Free Software Foundation, incorporated herein by reference. 9 + */ 10 + 11 + #include <linux/pci.h> 12 + #include <linux/tcp.h> 13 + #include <linux/ip.h> 14 + #include <linux/in.h> 15 + #include <linux/ipv6.h> 16 + #include <linux/slab.h> 17 + #include <net/ipv6.h> 18 + #include <linux/if_ether.h> 19 + #include <linux/highmem.h> 20 + #include <linux/moduleparam.h> 21 + #include <linux/cache.h> 22 + #include "net_driver.h" 23 + #include "efx.h" 24 + #include "io.h" 25 + #include "nic.h" 26 + #include "tx.h" 27 + #include "workarounds.h" 28 + #include "ef10_regs.h" 29 + 30 + /* Efx legacy TCP segmentation acceleration. 31 + * 32 + * Utilises firmware support to go faster than GSO (but not as fast as TSOv2). 33 + * 34 + * Requires TX checksum offload support. 35 + */ 36 + 37 + #define PTR_DIFF(p1, p2) ((u8 *)(p1) - (u8 *)(p2)) 38 + 39 + /** 40 + * struct tso_state - TSO state for an SKB 41 + * @out_len: Remaining length in current segment 42 + * @seqnum: Current sequence number 43 + * @ipv4_id: Current IPv4 ID, host endian 44 + * @packet_space: Remaining space in current packet 45 + * @dma_addr: DMA address of current position 46 + * @in_len: Remaining length in current SKB fragment 47 + * @unmap_len: Length of SKB fragment 48 + * @unmap_addr: DMA address of SKB fragment 49 + * @protocol: Network protocol (after any VLAN header) 50 + * @ip_off: Offset of IP header 51 + * @tcp_off: Offset of TCP header 52 + * @header_len: Number of bytes of header 53 + * @ip_base_len: IPv4 tot_len or IPv6 payload_len, before TCP payload 54 + * @header_dma_addr: Header DMA address 55 + * @header_unmap_len: Header DMA mapped length 56 + * 57 + * The state used during segmentation. It is put into this data structure 58 + * just to make it easy to pass into inline functions. 59 + */ 60 + struct tso_state { 61 + /* Output position */ 62 + unsigned int out_len; 63 + unsigned int seqnum; 64 + u16 ipv4_id; 65 + unsigned int packet_space; 66 + 67 + /* Input position */ 68 + dma_addr_t dma_addr; 69 + unsigned int in_len; 70 + unsigned int unmap_len; 71 + dma_addr_t unmap_addr; 72 + 73 + __be16 protocol; 74 + unsigned int ip_off; 75 + unsigned int tcp_off; 76 + unsigned int header_len; 77 + unsigned int ip_base_len; 78 + dma_addr_t header_dma_addr; 79 + unsigned int header_unmap_len; 80 + }; 81 + 82 + static inline void prefetch_ptr(struct efx_tx_queue *tx_queue) 83 + { 84 + unsigned int insert_ptr = efx_tx_queue_get_insert_index(tx_queue); 85 + char *ptr; 86 + 87 + ptr = (char *) (tx_queue->buffer + insert_ptr); 88 + prefetch(ptr); 89 + prefetch(ptr + 0x80); 90 + 91 + ptr = (char *) (((efx_qword_t *)tx_queue->txd.buf.addr) + insert_ptr); 92 + prefetch(ptr); 93 + prefetch(ptr + 0x80); 94 + } 95 + 96 + /** 97 + * efx_tx_queue_insert - push descriptors onto the TX queue 98 + * @tx_queue: Efx TX queue 99 + * @dma_addr: DMA address of fragment 100 + * @len: Length of fragment 101 + * @final_buffer: The final buffer inserted into the queue 102 + * 103 + * Push descriptors onto the TX queue. 104 + */ 105 + static void efx_tx_queue_insert(struct efx_tx_queue *tx_queue, 106 + dma_addr_t dma_addr, unsigned int len, 107 + struct efx_tx_buffer **final_buffer) 108 + { 109 + struct efx_tx_buffer *buffer; 110 + unsigned int dma_len; 111 + 112 + EFX_BUG_ON_PARANOID(len <= 0); 113 + 114 + while (1) { 115 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 116 + ++tx_queue->insert_count; 117 + 118 + EFX_BUG_ON_PARANOID(tx_queue->insert_count - 119 + tx_queue->read_count >= 120 + tx_queue->efx->txq_entries); 121 + 122 + buffer->dma_addr = dma_addr; 123 + 124 + dma_len = tx_queue->efx->type->tx_limit_len(tx_queue, 125 + dma_addr, len); 126 + 127 + /* If there's space for everything this is our last buffer. */ 128 + if (dma_len >= len) 129 + break; 130 + 131 + buffer->len = dma_len; 132 + buffer->flags = EFX_TX_BUF_CONT; 133 + dma_addr += dma_len; 134 + len -= dma_len; 135 + } 136 + 137 + EFX_BUG_ON_PARANOID(!len); 138 + buffer->len = len; 139 + *final_buffer = buffer; 140 + } 141 + 142 + /* 143 + * Verify that our various assumptions about sk_buffs and the conditions 144 + * under which TSO will be attempted hold true. Return the protocol number. 145 + */ 146 + static __be16 efx_tso_check_protocol(struct sk_buff *skb) 147 + { 148 + __be16 protocol = skb->protocol; 149 + 150 + EFX_BUG_ON_PARANOID(((struct ethhdr *)skb->data)->h_proto != 151 + protocol); 152 + if (protocol == htons(ETH_P_8021Q)) { 153 + struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 154 + 155 + protocol = veh->h_vlan_encapsulated_proto; 156 + } 157 + 158 + if (protocol == htons(ETH_P_IP)) { 159 + EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP); 160 + } else { 161 + EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IPV6)); 162 + EFX_BUG_ON_PARANOID(ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP); 163 + } 164 + EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data) 165 + + (tcp_hdr(skb)->doff << 2u)) > 166 + skb_headlen(skb)); 167 + 168 + return protocol; 169 + } 170 + 171 + 172 + /* Parse the SKB header and initialise state. */ 173 + static int tso_start(struct tso_state *st, struct efx_nic *efx, 174 + struct efx_tx_queue *tx_queue, 175 + const struct sk_buff *skb) 176 + { 177 + struct device *dma_dev = &efx->pci_dev->dev; 178 + unsigned int header_len, in_len; 179 + dma_addr_t dma_addr; 180 + 181 + st->ip_off = skb_network_header(skb) - skb->data; 182 + st->tcp_off = skb_transport_header(skb) - skb->data; 183 + header_len = st->tcp_off + (tcp_hdr(skb)->doff << 2u); 184 + in_len = skb_headlen(skb) - header_len; 185 + st->header_len = header_len; 186 + st->in_len = in_len; 187 + if (st->protocol == htons(ETH_P_IP)) { 188 + st->ip_base_len = st->header_len - st->ip_off; 189 + st->ipv4_id = ntohs(ip_hdr(skb)->id); 190 + } else { 191 + st->ip_base_len = st->header_len - st->tcp_off; 192 + st->ipv4_id = 0; 193 + } 194 + st->seqnum = ntohl(tcp_hdr(skb)->seq); 195 + 196 + EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg); 197 + EFX_BUG_ON_PARANOID(tcp_hdr(skb)->syn); 198 + EFX_BUG_ON_PARANOID(tcp_hdr(skb)->rst); 199 + 200 + st->out_len = skb->len - header_len; 201 + 202 + dma_addr = dma_map_single(dma_dev, skb->data, 203 + skb_headlen(skb), DMA_TO_DEVICE); 204 + st->header_dma_addr = dma_addr; 205 + st->header_unmap_len = skb_headlen(skb); 206 + st->dma_addr = dma_addr + header_len; 207 + st->unmap_len = 0; 208 + 209 + return unlikely(dma_mapping_error(dma_dev, dma_addr)) ? -ENOMEM : 0; 210 + } 211 + 212 + static int tso_get_fragment(struct tso_state *st, struct efx_nic *efx, 213 + skb_frag_t *frag) 214 + { 215 + st->unmap_addr = skb_frag_dma_map(&efx->pci_dev->dev, frag, 0, 216 + skb_frag_size(frag), DMA_TO_DEVICE); 217 + if (likely(!dma_mapping_error(&efx->pci_dev->dev, st->unmap_addr))) { 218 + st->unmap_len = skb_frag_size(frag); 219 + st->in_len = skb_frag_size(frag); 220 + st->dma_addr = st->unmap_addr; 221 + return 0; 222 + } 223 + return -ENOMEM; 224 + } 225 + 226 + 227 + /** 228 + * tso_fill_packet_with_fragment - form descriptors for the current fragment 229 + * @tx_queue: Efx TX queue 230 + * @skb: Socket buffer 231 + * @st: TSO state 232 + * 233 + * Form descriptors for the current fragment, until we reach the end 234 + * of fragment or end-of-packet. 235 + */ 236 + static void tso_fill_packet_with_fragment(struct efx_tx_queue *tx_queue, 237 + const struct sk_buff *skb, 238 + struct tso_state *st) 239 + { 240 + struct efx_tx_buffer *buffer; 241 + int n; 242 + 243 + if (st->in_len == 0) 244 + return; 245 + if (st->packet_space == 0) 246 + return; 247 + 248 + EFX_BUG_ON_PARANOID(st->in_len <= 0); 249 + EFX_BUG_ON_PARANOID(st->packet_space <= 0); 250 + 251 + n = min(st->in_len, st->packet_space); 252 + 253 + st->packet_space -= n; 254 + st->out_len -= n; 255 + st->in_len -= n; 256 + 257 + efx_tx_queue_insert(tx_queue, st->dma_addr, n, &buffer); 258 + 259 + if (st->out_len == 0) { 260 + /* Transfer ownership of the skb */ 261 + buffer->skb = skb; 262 + buffer->flags = EFX_TX_BUF_SKB; 263 + } else if (st->packet_space != 0) { 264 + buffer->flags = EFX_TX_BUF_CONT; 265 + } 266 + 267 + if (st->in_len == 0) { 268 + /* Transfer ownership of the DMA mapping */ 269 + buffer->unmap_len = st->unmap_len; 270 + buffer->dma_offset = buffer->unmap_len - buffer->len; 271 + st->unmap_len = 0; 272 + } 273 + 274 + st->dma_addr += n; 275 + } 276 + 277 + 278 + #define TCP_FLAGS_OFFSET 13 279 + 280 + /** 281 + * tso_start_new_packet - generate a new header and prepare for the new packet 282 + * @tx_queue: Efx TX queue 283 + * @skb: Socket buffer 284 + * @st: TSO state 285 + * 286 + * Generate a new header and prepare for the new packet. Return 0 on 287 + * success, or -%ENOMEM if failed to alloc header, or other negative error. 288 + */ 289 + static int tso_start_new_packet(struct efx_tx_queue *tx_queue, 290 + const struct sk_buff *skb, 291 + struct tso_state *st) 292 + { 293 + struct efx_tx_buffer *buffer = 294 + efx_tx_queue_get_insert_buffer(tx_queue); 295 + bool is_last = st->out_len <= skb_shinfo(skb)->gso_size; 296 + u8 tcp_flags_mask, tcp_flags; 297 + 298 + if (!is_last) { 299 + st->packet_space = skb_shinfo(skb)->gso_size; 300 + tcp_flags_mask = 0x09; /* mask out FIN and PSH */ 301 + } else { 302 + st->packet_space = st->out_len; 303 + tcp_flags_mask = 0x00; 304 + } 305 + 306 + if (WARN_ON(!st->header_unmap_len)) 307 + return -EINVAL; 308 + /* Send the original headers with a TSO option descriptor 309 + * in front 310 + */ 311 + tcp_flags = ((u8 *)tcp_hdr(skb))[TCP_FLAGS_OFFSET] & ~tcp_flags_mask; 312 + 313 + buffer->flags = EFX_TX_BUF_OPTION; 314 + buffer->len = 0; 315 + buffer->unmap_len = 0; 316 + EFX_POPULATE_QWORD_5(buffer->option, 317 + ESF_DZ_TX_DESC_IS_OPT, 1, 318 + ESF_DZ_TX_OPTION_TYPE, 319 + ESE_DZ_TX_OPTION_DESC_TSO, 320 + ESF_DZ_TX_TSO_TCP_FLAGS, tcp_flags, 321 + ESF_DZ_TX_TSO_IP_ID, st->ipv4_id, 322 + ESF_DZ_TX_TSO_TCP_SEQNO, st->seqnum); 323 + ++tx_queue->insert_count; 324 + 325 + /* We mapped the headers in tso_start(). Unmap them 326 + * when the last segment is completed. 327 + */ 328 + buffer = efx_tx_queue_get_insert_buffer(tx_queue); 329 + buffer->dma_addr = st->header_dma_addr; 330 + buffer->len = st->header_len; 331 + if (is_last) { 332 + buffer->flags = EFX_TX_BUF_CONT | EFX_TX_BUF_MAP_SINGLE; 333 + buffer->unmap_len = st->header_unmap_len; 334 + buffer->dma_offset = 0; 335 + /* Ensure we only unmap them once in case of a 336 + * later DMA mapping error and rollback 337 + */ 338 + st->header_unmap_len = 0; 339 + } else { 340 + buffer->flags = EFX_TX_BUF_CONT; 341 + buffer->unmap_len = 0; 342 + } 343 + ++tx_queue->insert_count; 344 + 345 + st->seqnum += skb_shinfo(skb)->gso_size; 346 + 347 + /* Linux leaves suitable gaps in the IP ID space for us to fill. */ 348 + ++st->ipv4_id; 349 + 350 + return 0; 351 + } 352 + 353 + /** 354 + * efx_enqueue_skb_tso - segment and transmit a TSO socket buffer 355 + * @tx_queue: Efx TX queue 356 + * @skb: Socket buffer 357 + * @data_mapped: Did we map the data? Always set to true 358 + * by this on success. 359 + * 360 + * Context: You must hold netif_tx_lock() to call this function. 361 + * 362 + * Add socket buffer @skb to @tx_queue, doing TSO or return != 0 if 363 + * @skb was not enqueued. @skb is consumed unless return value is 364 + * %EINVAL. 365 + */ 366 + int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, 367 + struct sk_buff *skb, 368 + bool *data_mapped) 369 + { 370 + struct efx_nic *efx = tx_queue->efx; 371 + int frag_i, rc; 372 + struct tso_state state; 373 + 374 + if (tx_queue->tso_version != 1) 375 + return -EINVAL; 376 + 377 + prefetch(skb->data); 378 + 379 + /* Find the packet protocol and sanity-check it */ 380 + state.protocol = efx_tso_check_protocol(skb); 381 + 382 + EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count); 383 + 384 + rc = tso_start(&state, efx, tx_queue, skb); 385 + if (rc) 386 + goto fail; 387 + 388 + if (likely(state.in_len == 0)) { 389 + /* Grab the first payload fragment. */ 390 + EFX_BUG_ON_PARANOID(skb_shinfo(skb)->nr_frags < 1); 391 + frag_i = 0; 392 + rc = tso_get_fragment(&state, efx, 393 + skb_shinfo(skb)->frags + frag_i); 394 + if (rc) 395 + goto fail; 396 + } else { 397 + /* Payload starts in the header area. */ 398 + frag_i = -1; 399 + } 400 + 401 + rc = tso_start_new_packet(tx_queue, skb, &state); 402 + if (rc) 403 + goto fail; 404 + 405 + prefetch_ptr(tx_queue); 406 + 407 + while (1) { 408 + tso_fill_packet_with_fragment(tx_queue, skb, &state); 409 + 410 + /* Move onto the next fragment? */ 411 + if (state.in_len == 0) { 412 + if (++frag_i >= skb_shinfo(skb)->nr_frags) 413 + /* End of payload reached. */ 414 + break; 415 + rc = tso_get_fragment(&state, efx, 416 + skb_shinfo(skb)->frags + frag_i); 417 + if (rc) 418 + goto fail; 419 + } 420 + 421 + /* Start at new packet? */ 422 + if (state.packet_space == 0) { 423 + rc = tso_start_new_packet(tx_queue, skb, &state); 424 + if (rc) 425 + goto fail; 426 + } 427 + } 428 + 429 + *data_mapped = true; 430 + 431 + return 0; 432 + 433 + fail: 434 + if (rc == -ENOMEM) 435 + netif_err(efx, tx_err, efx->net_dev, 436 + "Out of memory for TSO headers, or DMA mapping error\n"); 437 + else 438 + netif_err(efx, tx_err, efx->net_dev, "TSO failed, rc = %d\n", rc); 439 + 440 + /* Free the DMA mapping we were in the process of writing out */ 441 + if (state.unmap_len) { 442 + dma_unmap_page(&efx->pci_dev->dev, state.unmap_addr, 443 + state.unmap_len, DMA_TO_DEVICE); 444 + } 445 + 446 + /* Free the header DMA mapping */ 447 + if (state.header_unmap_len) 448 + dma_unmap_single(&efx->pci_dev->dev, state.header_dma_addr, 449 + state.header_unmap_len, DMA_TO_DEVICE); 450 + 451 + return rc; 452 + }