blob: d414328b35c953b11c996e8e7aaa70d340272c08 [file] [log] [blame]
Alex Elder84f9bd12020-03-05 22:28:24 -06001// SPDX-License-Identifier: GPL-2.0
2
3/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2019-2020 Linaro Ltd.
5 */
6
7#include <linux/types.h>
8#include <linux/device.h>
9#include <linux/slab.h>
10#include <linux/bitfield.h>
11#include <linux/if_rmnet.h>
Alex Elder84f9bd12020-03-05 22:28:24 -060012#include <linux/dma-direction.h>
13
14#include "gsi.h"
15#include "gsi_trans.h"
16#include "ipa.h"
17#include "ipa_data.h"
18#include "ipa_endpoint.h"
19#include "ipa_cmd.h"
20#include "ipa_mem.h"
21#include "ipa_modem.h"
22#include "ipa_table.h"
23#include "ipa_gsi.h"
24
25#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
26
27#define IPA_REPLENISH_BATCH 16
28
Alex Elder6fcd4222020-03-20 11:02:20 -050029/* RX buffer is 1 page (or a power-of-2 contiguous pages) */
30#define IPA_RX_BUFFER_SIZE 8192 /* PAGE_SIZE > 4096 wastes a LOT */
Alex Elder84f9bd12020-03-05 22:28:24 -060031
32/* The amount of RX buffer space consumed by standard skb overhead */
33#define IPA_RX_BUFFER_OVERHEAD (PAGE_SIZE - SKB_MAX_ORDER(NET_SKB_PAD, 0))
34
Alex Elder8730f452020-06-11 14:48:30 -050035/* Where to find the QMAP mux_id for a packet within modem-supplied metadata */
36#define IPA_ENDPOINT_QMAP_METADATA_MASK 0x000000ff /* host byte order */
37
Alex Elder84f9bd12020-03-05 22:28:24 -060038#define IPA_ENDPOINT_RESET_AGGR_RETRY_MAX 3
Alex Elder1d866522020-06-29 16:55:22 -050039#define IPA_AGGR_TIME_LIMIT_DEFAULT 500 /* microseconds */
Alex Elder84f9bd12020-03-05 22:28:24 -060040
Alex Elder84f9bd12020-03-05 22:28:24 -060041/** enum ipa_status_opcode - status element opcode hardware values */
42enum ipa_status_opcode {
43 IPA_STATUS_OPCODE_PACKET = 0x01,
44 IPA_STATUS_OPCODE_NEW_FRAG_RULE = 0x02,
45 IPA_STATUS_OPCODE_DROPPED_PACKET = 0x04,
46 IPA_STATUS_OPCODE_SUSPENDED_PACKET = 0x08,
47 IPA_STATUS_OPCODE_LOG = 0x10,
48 IPA_STATUS_OPCODE_DCMP = 0x20,
49 IPA_STATUS_OPCODE_PACKET_2ND_PASS = 0x40,
50};
51
52/** enum ipa_status_exception - status element exception type */
53enum ipa_status_exception {
54 /* 0 means no exception */
55 IPA_STATUS_EXCEPTION_DEAGGR = 0x01,
56 IPA_STATUS_EXCEPTION_IPTYPE = 0x04,
57 IPA_STATUS_EXCEPTION_PACKET_LENGTH = 0x08,
58 IPA_STATUS_EXCEPTION_FRAG_RULE_MISS = 0x10,
59 IPA_STATUS_EXCEPTION_SW_FILT = 0x20,
60 /* The meaning of the next value depends on whether the IP version */
61 IPA_STATUS_EXCEPTION_NAT = 0x40, /* IPv4 */
62 IPA_STATUS_EXCEPTION_IPV6CT = IPA_STATUS_EXCEPTION_NAT,
63};
64
65/* Status element provided by hardware */
66struct ipa_status {
67 u8 opcode; /* enum ipa_status_opcode */
68 u8 exception; /* enum ipa_status_exception */
69 __le16 mask;
70 __le16 pkt_len;
71 u8 endp_src_idx;
72 u8 endp_dst_idx;
73 __le32 metadata;
74 __le32 flags1;
75 __le64 flags2;
76 __le32 flags3;
77 __le32 flags4;
78};
79
80/* Field masks for struct ipa_status structure fields */
81
82#define IPA_STATUS_SRC_IDX_FMASK GENMASK(4, 0)
83
84#define IPA_STATUS_DST_IDX_FMASK GENMASK(4, 0)
85
86#define IPA_STATUS_FLAGS1_FLT_LOCAL_FMASK GENMASK(0, 0)
87#define IPA_STATUS_FLAGS1_FLT_HASH_FMASK GENMASK(1, 1)
88#define IPA_STATUS_FLAGS1_FLT_GLOBAL_FMASK GENMASK(2, 2)
89#define IPA_STATUS_FLAGS1_FLT_RET_HDR_FMASK GENMASK(3, 3)
90#define IPA_STATUS_FLAGS1_FLT_RULE_ID_FMASK GENMASK(13, 4)
91#define IPA_STATUS_FLAGS1_RT_LOCAL_FMASK GENMASK(14, 14)
92#define IPA_STATUS_FLAGS1_RT_HASH_FMASK GENMASK(15, 15)
93#define IPA_STATUS_FLAGS1_UCP_FMASK GENMASK(16, 16)
94#define IPA_STATUS_FLAGS1_RT_TBL_IDX_FMASK GENMASK(21, 17)
95#define IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK GENMASK(31, 22)
96
97#define IPA_STATUS_FLAGS2_NAT_HIT_FMASK GENMASK_ULL(0, 0)
98#define IPA_STATUS_FLAGS2_NAT_ENTRY_IDX_FMASK GENMASK_ULL(13, 1)
99#define IPA_STATUS_FLAGS2_NAT_TYPE_FMASK GENMASK_ULL(15, 14)
100#define IPA_STATUS_FLAGS2_TAG_INFO_FMASK GENMASK_ULL(63, 16)
101
102#define IPA_STATUS_FLAGS3_SEQ_NUM_FMASK GENMASK(7, 0)
103#define IPA_STATUS_FLAGS3_TOD_CTR_FMASK GENMASK(31, 8)
104
105#define IPA_STATUS_FLAGS4_HDR_LOCAL_FMASK GENMASK(0, 0)
106#define IPA_STATUS_FLAGS4_HDR_OFFSET_FMASK GENMASK(10, 1)
107#define IPA_STATUS_FLAGS4_FRAG_HIT_FMASK GENMASK(11, 11)
108#define IPA_STATUS_FLAGS4_FRAG_RULE_FMASK GENMASK(15, 12)
109#define IPA_STATUS_FLAGS4_HW_SPECIFIC_FMASK GENMASK(31, 16)
110
111#ifdef IPA_VALIDATE
112
113static void ipa_endpoint_validate_build(void)
114{
115 /* The aggregation byte limit defines the point at which an
116 * aggregation window will close. It is programmed into the
117 * IPA hardware as a number of KB. We don't use "hard byte
118 * limit" aggregation, which means that we need to supply
119 * enough space in a receive buffer to hold a complete MTU
120 * plus normal skb overhead *after* that aggregation byte
121 * limit has been crossed.
122 *
123 * This check just ensures we don't define a receive buffer
124 * size that would exceed what we can represent in the field
125 * that is used to program its size.
126 */
127 BUILD_BUG_ON(IPA_RX_BUFFER_SIZE >
128 field_max(AGGR_BYTE_LIMIT_FMASK) * SZ_1K +
129 IPA_MTU + IPA_RX_BUFFER_OVERHEAD);
130
131 /* I honestly don't know where this requirement comes from. But
132 * it holds, and if we someday need to loosen the constraint we
133 * can try to track it down.
134 */
135 BUILD_BUG_ON(sizeof(struct ipa_status) % 4);
136}
137
138static bool ipa_endpoint_data_valid_one(struct ipa *ipa, u32 count,
139 const struct ipa_gsi_endpoint_data *all_data,
140 const struct ipa_gsi_endpoint_data *data)
141{
142 const struct ipa_gsi_endpoint_data *other_data;
143 struct device *dev = &ipa->pdev->dev;
144 enum ipa_endpoint_name other_name;
145
146 if (ipa_gsi_endpoint_data_empty(data))
147 return true;
148
149 if (!data->toward_ipa) {
150 if (data->endpoint.filter_support) {
151 dev_err(dev, "filtering not supported for "
152 "RX endpoint %u\n",
153 data->endpoint_id);
154 return false;
155 }
156
157 return true; /* Nothing more to check for RX */
158 }
159
160 if (data->endpoint.config.status_enable) {
161 other_name = data->endpoint.config.tx.status_endpoint;
162 if (other_name >= count) {
163 dev_err(dev, "status endpoint name %u out of range "
164 "for endpoint %u\n",
165 other_name, data->endpoint_id);
166 return false;
167 }
168
169 /* Status endpoint must be defined... */
170 other_data = &all_data[other_name];
171 if (ipa_gsi_endpoint_data_empty(other_data)) {
172 dev_err(dev, "DMA endpoint name %u undefined "
173 "for endpoint %u\n",
174 other_name, data->endpoint_id);
175 return false;
176 }
177
178 /* ...and has to be an RX endpoint... */
179 if (other_data->toward_ipa) {
180 dev_err(dev,
181 "status endpoint for endpoint %u not RX\n",
182 data->endpoint_id);
183 return false;
184 }
185
186 /* ...and if it's to be an AP endpoint... */
187 if (other_data->ee_id == GSI_EE_AP) {
188 /* ...make sure it has status enabled. */
189 if (!other_data->endpoint.config.status_enable) {
190 dev_err(dev,
191 "status not enabled for endpoint %u\n",
192 other_data->endpoint_id);
193 return false;
194 }
195 }
196 }
197
198 if (data->endpoint.config.dma_mode) {
199 other_name = data->endpoint.config.dma_endpoint;
200 if (other_name >= count) {
201 dev_err(dev, "DMA endpoint name %u out of range "
202 "for endpoint %u\n",
203 other_name, data->endpoint_id);
204 return false;
205 }
206
207 other_data = &all_data[other_name];
208 if (ipa_gsi_endpoint_data_empty(other_data)) {
209 dev_err(dev, "DMA endpoint name %u undefined "
210 "for endpoint %u\n",
211 other_name, data->endpoint_id);
212 return false;
213 }
214 }
215
216 return true;
217}
218
219static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count,
220 const struct ipa_gsi_endpoint_data *data)
221{
222 const struct ipa_gsi_endpoint_data *dp = data;
223 struct device *dev = &ipa->pdev->dev;
224 enum ipa_endpoint_name name;
225
226 ipa_endpoint_validate_build();
227
228 if (count > IPA_ENDPOINT_COUNT) {
229 dev_err(dev, "too many endpoints specified (%u > %u)\n",
230 count, IPA_ENDPOINT_COUNT);
231 return false;
232 }
233
234 /* Make sure needed endpoints have defined data */
235 if (ipa_gsi_endpoint_data_empty(&data[IPA_ENDPOINT_AP_COMMAND_TX])) {
236 dev_err(dev, "command TX endpoint not defined\n");
237 return false;
238 }
239 if (ipa_gsi_endpoint_data_empty(&data[IPA_ENDPOINT_AP_LAN_RX])) {
240 dev_err(dev, "LAN RX endpoint not defined\n");
241 return false;
242 }
243 if (ipa_gsi_endpoint_data_empty(&data[IPA_ENDPOINT_AP_MODEM_TX])) {
244 dev_err(dev, "AP->modem TX endpoint not defined\n");
245 return false;
246 }
247 if (ipa_gsi_endpoint_data_empty(&data[IPA_ENDPOINT_AP_MODEM_RX])) {
248 dev_err(dev, "AP<-modem RX endpoint not defined\n");
249 return false;
250 }
251
252 for (name = 0; name < count; name++, dp++)
253 if (!ipa_endpoint_data_valid_one(ipa, count, data, dp))
254 return false;
255
256 return true;
257}
258
259#else /* !IPA_VALIDATE */
260
261static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count,
262 const struct ipa_gsi_endpoint_data *data)
263{
264 return true;
265}
266
267#endif /* !IPA_VALIDATE */
268
269/* Allocate a transaction to use on a non-command endpoint */
270static struct gsi_trans *ipa_endpoint_trans_alloc(struct ipa_endpoint *endpoint,
271 u32 tre_count)
272{
273 struct gsi *gsi = &endpoint->ipa->gsi;
274 u32 channel_id = endpoint->channel_id;
275 enum dma_data_direction direction;
276
277 direction = endpoint->toward_ipa ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
278
279 return gsi_channel_trans_alloc(gsi, channel_id, tre_count, direction);
280}
281
282/* suspend_delay represents suspend for RX, delay for TX endpoints.
283 * Note that suspend is not supported starting with IPA v4.0.
284 */
Alex Elder4900bf32020-05-04 18:37:11 -0500285static bool
Alex Elder84f9bd12020-03-05 22:28:24 -0600286ipa_endpoint_init_ctrl(struct ipa_endpoint *endpoint, bool suspend_delay)
287{
288 u32 offset = IPA_REG_ENDP_INIT_CTRL_N_OFFSET(endpoint->endpoint_id);
289 struct ipa *ipa = endpoint->ipa;
Alex Elder4900bf32020-05-04 18:37:11 -0500290 bool state;
Alex Elder84f9bd12020-03-05 22:28:24 -0600291 u32 mask;
292 u32 val;
293
Alex Elder4fa95242020-05-04 18:37:12 -0500294 /* Suspend is not supported for IPA v4.0+. Delay doesn't work
295 * correctly on IPA v4.2.
296 *
297 * if (endpoint->toward_ipa)
298 * assert(ipa->version != IPA_VERSION_4.2);
299 * else
300 * assert(ipa->version == IPA_VERSION_3_5_1);
301 */
Alex Elder84f9bd12020-03-05 22:28:24 -0600302 mask = endpoint->toward_ipa ? ENDP_DELAY_FMASK : ENDP_SUSPEND_FMASK;
303
304 val = ioread32(ipa->reg_virt + offset);
Alex Elder4900bf32020-05-04 18:37:11 -0500305 /* Don't bother if it's already in the requested state */
306 state = !!(val & mask);
307 if (suspend_delay != state) {
308 val ^= mask;
309 iowrite32(val, ipa->reg_virt + offset);
310 }
Alex Elder84f9bd12020-03-05 22:28:24 -0600311
Alex Elder4900bf32020-05-04 18:37:11 -0500312 return state;
Alex Elder84f9bd12020-03-05 22:28:24 -0600313}
314
Alex Elder4fa95242020-05-04 18:37:12 -0500315/* We currently don't care what the previous state was for delay mode */
316static void
317ipa_endpoint_program_delay(struct ipa_endpoint *endpoint, bool enable)
318{
319 /* assert(endpoint->toward_ipa); */
320
321 (void)ipa_endpoint_init_ctrl(endpoint, enable);
322}
323
324/* Returns previous suspend state (true means it was enabled) */
325static bool
326ipa_endpoint_program_suspend(struct ipa_endpoint *endpoint, bool enable)
327{
328 /* assert(!endpoint->toward_ipa); */
329
330 return ipa_endpoint_init_ctrl(endpoint, enable);
331}
332
Alex Elder84f9bd12020-03-05 22:28:24 -0600333/* Enable or disable delay or suspend mode on all modem endpoints */
334void ipa_endpoint_modem_pause_all(struct ipa *ipa, bool enable)
335{
336 bool support_suspend;
337 u32 endpoint_id;
338
Alex Elder4fa95242020-05-04 18:37:12 -0500339 /* DELAY mode doesn't work correctly on IPA v4.2 */
Alex Elder84f9bd12020-03-05 22:28:24 -0600340 if (ipa->version == IPA_VERSION_4_2)
341 return;
342
343 /* Only IPA v3.5.1 supports SUSPEND mode on RX endpoints */
344 support_suspend = ipa->version == IPA_VERSION_3_5_1;
345
346 for (endpoint_id = 0; endpoint_id < IPA_ENDPOINT_MAX; endpoint_id++) {
347 struct ipa_endpoint *endpoint = &ipa->endpoint[endpoint_id];
348
349 if (endpoint->ee_id != GSI_EE_MODEM)
350 continue;
351
352 /* Set TX delay mode, or for IPA v3.5.1 RX suspend mode */
Alex Elder4fa95242020-05-04 18:37:12 -0500353 if (endpoint->toward_ipa)
354 ipa_endpoint_program_delay(endpoint, enable);
355 else if (support_suspend)
356 (void)ipa_endpoint_program_suspend(endpoint, enable);
Alex Elder84f9bd12020-03-05 22:28:24 -0600357 }
358}
359
360/* Reset all modem endpoints to use the default exception endpoint */
361int ipa_endpoint_modem_exception_reset_all(struct ipa *ipa)
362{
363 u32 initialized = ipa->initialized;
364 struct gsi_trans *trans;
365 u32 count;
366
367 /* We need one command per modem TX endpoint. We can get an upper
368 * bound on that by assuming all initialized endpoints are modem->IPA.
369 * That won't happen, and we could be more precise, but this is fine
Wang Wenhu8fa54b12020-05-26 20:19:24 -0700370 * for now. We need to end the transaction with a "tag process."
Alex Elder84f9bd12020-03-05 22:28:24 -0600371 */
372 count = hweight32(initialized) + ipa_cmd_tag_process_count();
373 trans = ipa_cmd_trans_alloc(ipa, count);
374 if (!trans) {
375 dev_err(&ipa->pdev->dev,
376 "no transaction to reset modem exception endpoints\n");
377 return -EBUSY;
378 }
379
380 while (initialized) {
381 u32 endpoint_id = __ffs(initialized);
382 struct ipa_endpoint *endpoint;
383 u32 offset;
384
385 initialized ^= BIT(endpoint_id);
386
387 /* We only reset modem TX endpoints */
388 endpoint = &ipa->endpoint[endpoint_id];
389 if (!(endpoint->ee_id == GSI_EE_MODEM && endpoint->toward_ipa))
390 continue;
391
392 offset = IPA_REG_ENDP_STATUS_N_OFFSET(endpoint_id);
393
394 /* Value written is 0, and all bits are updated. That
395 * means status is disabled on the endpoint, and as a
396 * result all other fields in the register are ignored.
397 */
398 ipa_cmd_register_write_add(trans, offset, 0, ~0, false);
399 }
400
401 ipa_cmd_tag_process_add(trans);
402
403 /* XXX This should have a 1 second timeout */
404 gsi_trans_commit_wait(trans);
405
406 return 0;
407}
408
409static void ipa_endpoint_init_cfg(struct ipa_endpoint *endpoint)
410{
411 u32 offset = IPA_REG_ENDP_INIT_CFG_N_OFFSET(endpoint->endpoint_id);
412 u32 val = 0;
413
414 /* FRAG_OFFLOAD_EN is 0 */
415 if (endpoint->data->checksum) {
416 if (endpoint->toward_ipa) {
417 u32 checksum_offset;
418
419 val |= u32_encode_bits(IPA_CS_OFFLOAD_UL,
420 CS_OFFLOAD_EN_FMASK);
421 /* Checksum header offset is in 4-byte units */
422 checksum_offset = sizeof(struct rmnet_map_header);
423 checksum_offset /= sizeof(u32);
424 val |= u32_encode_bits(checksum_offset,
425 CS_METADATA_HDR_OFFSET_FMASK);
426 } else {
427 val |= u32_encode_bits(IPA_CS_OFFLOAD_DL,
428 CS_OFFLOAD_EN_FMASK);
429 }
430 } else {
431 val |= u32_encode_bits(IPA_CS_OFFLOAD_NONE,
432 CS_OFFLOAD_EN_FMASK);
433 }
434 /* CS_GEN_QMB_MASTER_SEL is 0 */
435
436 iowrite32(val, endpoint->ipa->reg_virt + offset);
437}
438
Alex Elder8730f452020-06-11 14:48:30 -0500439/**
440 * We program QMAP endpoints so each packet received is preceded by a QMAP
441 * header structure. The QMAP header contains a 1-byte mux_id and 2-byte
442 * packet size field, and we have the IPA hardware populate both for each
443 * received packet. The header is configured (in the HDR_EXT register)
444 * to use big endian format.
445 *
446 * The packet size is written into the QMAP header's pkt_len field. That
447 * location is defined here using the HDR_OFST_PKT_SIZE field.
448 *
449 * The mux_id comes from a 4-byte metadata value supplied with each packet
450 * by the modem. It is *not* a QMAP header, but it does contain the mux_id
451 * value that we want, in its low-order byte. A bitmask defined in the
452 * endpoint's METADATA_MASK register defines which byte within the modem
453 * metadata contains the mux_id. And the OFST_METADATA field programmed
454 * here indicates where the extracted byte should be placed within the QMAP
455 * header.
456 */
Alex Elder84f9bd12020-03-05 22:28:24 -0600457static void ipa_endpoint_init_hdr(struct ipa_endpoint *endpoint)
458{
459 u32 offset = IPA_REG_ENDP_INIT_HDR_N_OFFSET(endpoint->endpoint_id);
460 u32 val = 0;
461
462 if (endpoint->data->qmap) {
463 size_t header_size = sizeof(struct rmnet_map_header);
464
Alex Elder8730f452020-06-11 14:48:30 -0500465 /* We might supply a checksum header after the QMAP header */
Alex Elder84f9bd12020-03-05 22:28:24 -0600466 if (endpoint->toward_ipa && endpoint->data->checksum)
467 header_size += sizeof(struct rmnet_map_ul_csum_header);
Alex Elder84f9bd12020-03-05 22:28:24 -0600468 val |= u32_encode_bits(header_size, HDR_LEN_FMASK);
Alex Elder84f9bd12020-03-05 22:28:24 -0600469
Alex Elderf330fda2020-06-11 14:48:33 -0500470 /* Define how to fill fields in a received QMAP header */
Alex Elder8730f452020-06-11 14:48:30 -0500471 if (!endpoint->toward_ipa) {
472 u32 off; /* Field offset within header */
473
474 /* Where IPA will write the metadata value */
475 off = offsetof(struct rmnet_map_header, mux_id);
476 val |= u32_encode_bits(off, HDR_OFST_METADATA_FMASK);
477
478 /* Where IPA will write the length */
479 off = offsetof(struct rmnet_map_header, pkt_len);
Alex Elder84f9bd12020-03-05 22:28:24 -0600480 val |= HDR_OFST_PKT_SIZE_VALID_FMASK;
Alex Elder8730f452020-06-11 14:48:30 -0500481 val |= u32_encode_bits(off, HDR_OFST_PKT_SIZE_FMASK);
Alex Elder84f9bd12020-03-05 22:28:24 -0600482 }
Alex Elder8730f452020-06-11 14:48:30 -0500483 /* For QMAP TX, metadata offset is 0 (modem assumes this) */
484 val |= HDR_OFST_METADATA_VALID_FMASK;
485
486 /* HDR_ADDITIONAL_CONST_LEN is 0; (RX only) */
Alex Elder84f9bd12020-03-05 22:28:24 -0600487 /* HDR_A5_MUX is 0 */
488 /* HDR_LEN_INC_DEAGG_HDR is 0 */
Alex Elder8730f452020-06-11 14:48:30 -0500489 /* HDR_METADATA_REG_VALID is 0 (TX only) */
Alex Elder84f9bd12020-03-05 22:28:24 -0600490 }
491
492 iowrite32(val, endpoint->ipa->reg_virt + offset);
493}
494
495static void ipa_endpoint_init_hdr_ext(struct ipa_endpoint *endpoint)
496{
497 u32 offset = IPA_REG_ENDP_INIT_HDR_EXT_N_OFFSET(endpoint->endpoint_id);
498 u32 pad_align = endpoint->data->rx.pad_align;
499 u32 val = 0;
500
501 val |= HDR_ENDIANNESS_FMASK; /* big endian */
Alex Elderf330fda2020-06-11 14:48:33 -0500502
503 /* A QMAP header contains a 6 bit pad field at offset 0. The RMNet
504 * driver assumes this field is meaningful in packets it receives,
505 * and assumes the header's payload length includes that padding.
506 * The RMNet driver does *not* pad packets it sends, however, so
507 * the pad field (although 0) should be ignored.
508 */
509 if (endpoint->data->qmap && !endpoint->toward_ipa) {
510 val |= HDR_TOTAL_LEN_OR_PAD_VALID_FMASK;
511 /* HDR_TOTAL_LEN_OR_PAD is 0 (pad, not total_len) */
512 val |= HDR_PAYLOAD_LEN_INC_PADDING_FMASK;
513 /* HDR_TOTAL_LEN_OR_PAD_OFFSET is 0 */
514 }
515
Alex Elder84f9bd12020-03-05 22:28:24 -0600516 /* HDR_PAYLOAD_LEN_INC_PADDING is 0 */
Alex Elder84f9bd12020-03-05 22:28:24 -0600517 if (!endpoint->toward_ipa)
518 val |= u32_encode_bits(pad_align, HDR_PAD_TO_ALIGNMENT_FMASK);
519
520 iowrite32(val, endpoint->ipa->reg_virt + offset);
521}
522
Alex Elder84f9bd12020-03-05 22:28:24 -0600523
524static void ipa_endpoint_init_hdr_metadata_mask(struct ipa_endpoint *endpoint)
525{
526 u32 endpoint_id = endpoint->endpoint_id;
527 u32 val = 0;
528 u32 offset;
529
530 offset = IPA_REG_ENDP_INIT_HDR_METADATA_MASK_N_OFFSET(endpoint_id);
531
Alex Elder8730f452020-06-11 14:48:30 -0500532 /* Note that HDR_ENDIANNESS indicates big endian header fields */
Alex Elder84f9bd12020-03-05 22:28:24 -0600533 if (!endpoint->toward_ipa && endpoint->data->qmap)
Alex Elder8730f452020-06-11 14:48:30 -0500534 val = cpu_to_be32(IPA_ENDPOINT_QMAP_METADATA_MASK);
Alex Elder84f9bd12020-03-05 22:28:24 -0600535
536 iowrite32(val, endpoint->ipa->reg_virt + offset);
537}
538
539static void ipa_endpoint_init_mode(struct ipa_endpoint *endpoint)
540{
541 u32 offset = IPA_REG_ENDP_INIT_MODE_N_OFFSET(endpoint->endpoint_id);
542 u32 val;
543
544 if (endpoint->toward_ipa && endpoint->data->dma_mode) {
545 enum ipa_endpoint_name name = endpoint->data->dma_endpoint;
546 u32 dma_endpoint_id;
547
548 dma_endpoint_id = endpoint->ipa->name_map[name]->endpoint_id;
549
550 val = u32_encode_bits(IPA_DMA, MODE_FMASK);
551 val |= u32_encode_bits(dma_endpoint_id, DEST_PIPE_INDEX_FMASK);
552 } else {
553 val = u32_encode_bits(IPA_BASIC, MODE_FMASK);
554 }
555 /* Other bitfields unspecified (and 0) */
556
557 iowrite32(val, endpoint->ipa->reg_virt + offset);
558}
559
560/* Compute the aggregation size value to use for a given buffer size */
561static u32 ipa_aggr_size_kb(u32 rx_buffer_size)
562{
563 /* We don't use "hard byte limit" aggregation, so we define the
564 * aggregation limit such that our buffer has enough space *after*
565 * that limit to receive a full MTU of data, plus overhead.
566 */
567 rx_buffer_size -= IPA_MTU + IPA_RX_BUFFER_OVERHEAD;
568
569 return rx_buffer_size / SZ_1K;
570}
571
572static void ipa_endpoint_init_aggr(struct ipa_endpoint *endpoint)
573{
574 u32 offset = IPA_REG_ENDP_INIT_AGGR_N_OFFSET(endpoint->endpoint_id);
575 u32 val = 0;
576
577 if (endpoint->data->aggregation) {
578 if (!endpoint->toward_ipa) {
Alex Elder84f9bd12020-03-05 22:28:24 -0600579 u32 limit;
580
581 val |= u32_encode_bits(IPA_ENABLE_AGGR, AGGR_EN_FMASK);
582 val |= u32_encode_bits(IPA_GENERIC, AGGR_TYPE_FMASK);
Alex Elder9e88cb52020-06-29 16:55:23 -0500583
584 limit = ipa_aggr_size_kb(IPA_RX_BUFFER_SIZE);
585 val |= u32_encode_bits(limit, AGGR_BYTE_LIMIT_FMASK);
Alex Elder1d866522020-06-29 16:55:22 -0500586
Alex Elder84f9bd12020-03-05 22:28:24 -0600587 limit = IPA_AGGR_TIME_LIMIT_DEFAULT;
Alex Elder1d866522020-06-29 16:55:22 -0500588 limit = DIV_ROUND_CLOSEST(limit, IPA_AGGR_GRANULARITY);
589 val |= u32_encode_bits(limit, AGGR_TIME_LIMIT_FMASK);
590
Alex Elder9e88cb52020-06-29 16:55:23 -0500591 /* AGGR_PKT_LIMIT is 0 (unlimited) */
592
Alex Elder84f9bd12020-03-05 22:28:24 -0600593 if (endpoint->data->rx.aggr_close_eof)
594 val |= AGGR_SW_EOF_ACTIVE_FMASK;
595 /* AGGR_HARD_BYTE_LIMIT_ENABLE is 0 */
596 } else {
597 val |= u32_encode_bits(IPA_ENABLE_DEAGGR,
598 AGGR_EN_FMASK);
599 val |= u32_encode_bits(IPA_QCMAP, AGGR_TYPE_FMASK);
600 /* other fields ignored */
601 }
602 /* AGGR_FORCE_CLOSE is 0 */
603 } else {
604 val |= u32_encode_bits(IPA_BYPASS_AGGR, AGGR_EN_FMASK);
605 /* other fields ignored */
606 }
607
608 iowrite32(val, endpoint->ipa->reg_virt + offset);
609}
610
611/* A return value of 0 indicates an error */
612static u32 ipa_reg_init_hol_block_timer_val(struct ipa *ipa, u32 microseconds)
613{
614 u32 scale;
615 u32 base;
616 u32 val;
617
618 if (!microseconds)
619 return 0; /* invalid delay */
620
621 /* Timer is represented in units of clock ticks. */
622 if (ipa->version < IPA_VERSION_4_2)
623 return microseconds; /* XXX Needs to be computed */
624
625 /* IPA v4.2 represents the tick count as base * scale */
626 scale = 1; /* XXX Needs to be computed */
627 if (scale > field_max(SCALE_FMASK))
628 return 0; /* scale too big */
629
630 base = DIV_ROUND_CLOSEST(microseconds, scale);
631 if (base > field_max(BASE_VALUE_FMASK))
632 return 0; /* microseconds too big */
633
634 val = u32_encode_bits(scale, SCALE_FMASK);
635 val |= u32_encode_bits(base, BASE_VALUE_FMASK);
636
637 return val;
638}
639
640static int ipa_endpoint_init_hol_block_timer(struct ipa_endpoint *endpoint,
641 u32 microseconds)
642{
643 u32 endpoint_id = endpoint->endpoint_id;
644 struct ipa *ipa = endpoint->ipa;
645 u32 offset;
646 u32 val;
647
648 /* XXX We'll fix this when the register definition is clear */
649 if (microseconds) {
650 struct device *dev = &ipa->pdev->dev;
651
652 dev_err(dev, "endpoint %u non-zero HOLB period (ignoring)\n",
653 endpoint_id);
654 microseconds = 0;
655 }
656
657 if (microseconds) {
658 val = ipa_reg_init_hol_block_timer_val(ipa, microseconds);
659 if (!val)
660 return -EINVAL;
661 } else {
662 val = 0; /* timeout is immediate */
663 }
664 offset = IPA_REG_ENDP_INIT_HOL_BLOCK_TIMER_N_OFFSET(endpoint_id);
665 iowrite32(val, ipa->reg_virt + offset);
666
667 return 0;
668}
669
670static void
671ipa_endpoint_init_hol_block_enable(struct ipa_endpoint *endpoint, bool enable)
672{
673 u32 endpoint_id = endpoint->endpoint_id;
674 u32 offset;
675 u32 val;
676
677 val = u32_encode_bits(enable ? 1 : 0, HOL_BLOCK_EN_FMASK);
678 offset = IPA_REG_ENDP_INIT_HOL_BLOCK_EN_N_OFFSET(endpoint_id);
679 iowrite32(val, endpoint->ipa->reg_virt + offset);
680}
681
682void ipa_endpoint_modem_hol_block_clear_all(struct ipa *ipa)
683{
684 u32 i;
685
686 for (i = 0; i < IPA_ENDPOINT_MAX; i++) {
687 struct ipa_endpoint *endpoint = &ipa->endpoint[i];
688
Alex Elderf8d34df2020-06-30 08:33:00 -0500689 if (endpoint->toward_ipa || endpoint->ee_id != GSI_EE_MODEM)
Alex Elder84f9bd12020-03-05 22:28:24 -0600690 continue;
691
692 (void)ipa_endpoint_init_hol_block_timer(endpoint, 0);
693 ipa_endpoint_init_hol_block_enable(endpoint, true);
694 }
695}
696
697static void ipa_endpoint_init_deaggr(struct ipa_endpoint *endpoint)
698{
699 u32 offset = IPA_REG_ENDP_INIT_DEAGGR_N_OFFSET(endpoint->endpoint_id);
700 u32 val = 0;
701
702 /* DEAGGR_HDR_LEN is 0 */
703 /* PACKET_OFFSET_VALID is 0 */
704 /* PACKET_OFFSET_LOCATION is ignored (not valid) */
705 /* MAX_PACKET_LEN is 0 (not enforced) */
706
707 iowrite32(val, endpoint->ipa->reg_virt + offset);
708}
709
710static void ipa_endpoint_init_seq(struct ipa_endpoint *endpoint)
711{
712 u32 offset = IPA_REG_ENDP_INIT_SEQ_N_OFFSET(endpoint->endpoint_id);
713 u32 seq_type = endpoint->seq_type;
714 u32 val = 0;
715
Alex Elder636edea2020-06-11 14:48:32 -0500716 /* Sequencer type is made up of four nibbles */
Alex Elder84f9bd12020-03-05 22:28:24 -0600717 val |= u32_encode_bits(seq_type & 0xf, HPS_SEQ_TYPE_FMASK);
718 val |= u32_encode_bits((seq_type >> 4) & 0xf, DPS_SEQ_TYPE_FMASK);
Alex Elder636edea2020-06-11 14:48:32 -0500719 /* The second two apply to replicated packets */
720 val |= u32_encode_bits((seq_type >> 8) & 0xf, HPS_REP_SEQ_TYPE_FMASK);
721 val |= u32_encode_bits((seq_type >> 12) & 0xf, DPS_REP_SEQ_TYPE_FMASK);
Alex Elder84f9bd12020-03-05 22:28:24 -0600722
723 iowrite32(val, endpoint->ipa->reg_virt + offset);
724}
725
726/**
727 * ipa_endpoint_skb_tx() - Transmit a socket buffer
728 * @endpoint: Endpoint pointer
729 * @skb: Socket buffer to send
730 *
731 * Returns: 0 if successful, or a negative error code
732 */
733int ipa_endpoint_skb_tx(struct ipa_endpoint *endpoint, struct sk_buff *skb)
734{
735 struct gsi_trans *trans;
736 u32 nr_frags;
737 int ret;
738
739 /* Make sure source endpoint's TLV FIFO has enough entries to
740 * hold the linear portion of the skb and all its fragments.
741 * If not, see if we can linearize it before giving up.
742 */
743 nr_frags = skb_shinfo(skb)->nr_frags;
744 if (1 + nr_frags > endpoint->trans_tre_max) {
745 if (skb_linearize(skb))
746 return -E2BIG;
747 nr_frags = 0;
748 }
749
750 trans = ipa_endpoint_trans_alloc(endpoint, 1 + nr_frags);
751 if (!trans)
752 return -EBUSY;
753
754 ret = gsi_trans_skb_add(trans, skb);
755 if (ret)
756 goto err_trans_free;
757 trans->data = skb; /* transaction owns skb now */
758
759 gsi_trans_commit(trans, !netdev_xmit_more());
760
761 return 0;
762
763err_trans_free:
764 gsi_trans_free(trans);
765
766 return -ENOMEM;
767}
768
769static void ipa_endpoint_status(struct ipa_endpoint *endpoint)
770{
771 u32 endpoint_id = endpoint->endpoint_id;
772 struct ipa *ipa = endpoint->ipa;
773 u32 val = 0;
774 u32 offset;
775
776 offset = IPA_REG_ENDP_STATUS_N_OFFSET(endpoint_id);
777
778 if (endpoint->data->status_enable) {
779 val |= STATUS_EN_FMASK;
780 if (endpoint->toward_ipa) {
781 enum ipa_endpoint_name name;
782 u32 status_endpoint_id;
783
784 name = endpoint->data->tx.status_endpoint;
785 status_endpoint_id = ipa->name_map[name]->endpoint_id;
786
787 val |= u32_encode_bits(status_endpoint_id,
788 STATUS_ENDP_FMASK);
789 }
790 /* STATUS_LOCATION is 0 (status element precedes packet) */
791 /* The next field is present for IPA v4.0 and above */
792 /* STATUS_PKT_SUPPRESS_FMASK is 0 */
793 }
794
795 iowrite32(val, ipa->reg_virt + offset);
796}
797
798static int ipa_endpoint_replenish_one(struct ipa_endpoint *endpoint)
799{
800 struct gsi_trans *trans;
801 bool doorbell = false;
802 struct page *page;
803 u32 offset;
804 u32 len;
805 int ret;
806
Alex Elder6fcd4222020-03-20 11:02:20 -0500807 page = dev_alloc_pages(get_order(IPA_RX_BUFFER_SIZE));
Alex Elder84f9bd12020-03-05 22:28:24 -0600808 if (!page)
809 return -ENOMEM;
810
811 trans = ipa_endpoint_trans_alloc(endpoint, 1);
812 if (!trans)
813 goto err_free_pages;
814
815 /* Offset the buffer to make space for skb headroom */
816 offset = NET_SKB_PAD;
817 len = IPA_RX_BUFFER_SIZE - offset;
818
819 ret = gsi_trans_page_add(trans, page, len, offset);
820 if (ret)
821 goto err_trans_free;
822 trans->data = page; /* transaction owns page now */
823
824 if (++endpoint->replenish_ready == IPA_REPLENISH_BATCH) {
825 doorbell = true;
826 endpoint->replenish_ready = 0;
827 }
828
829 gsi_trans_commit(trans, doorbell);
830
831 return 0;
832
833err_trans_free:
834 gsi_trans_free(trans);
835err_free_pages:
Alex Elder6fcd4222020-03-20 11:02:20 -0500836 __free_pages(page, get_order(IPA_RX_BUFFER_SIZE));
Alex Elder84f9bd12020-03-05 22:28:24 -0600837
838 return -ENOMEM;
839}
840
841/**
842 * ipa_endpoint_replenish() - Replenish the Rx packets cache.
843 *
844 * Allocate RX packet wrapper structures with maximal socket buffers
845 * for an endpoint. These are supplied to the hardware, which fills
846 * them with incoming data.
847 */
848static void ipa_endpoint_replenish(struct ipa_endpoint *endpoint, u32 count)
849{
850 struct gsi *gsi;
851 u32 backlog;
852
853 if (!endpoint->replenish_enabled) {
854 if (count)
855 atomic_add(count, &endpoint->replenish_saved);
856 return;
857 }
858
859
860 while (atomic_dec_not_zero(&endpoint->replenish_backlog))
861 if (ipa_endpoint_replenish_one(endpoint))
862 goto try_again_later;
863 if (count)
864 atomic_add(count, &endpoint->replenish_backlog);
865
866 return;
867
868try_again_later:
869 /* The last one didn't succeed, so fix the backlog */
870 backlog = atomic_inc_return(&endpoint->replenish_backlog);
871
872 if (count)
873 atomic_add(count, &endpoint->replenish_backlog);
874
875 /* Whenever a receive buffer transaction completes we'll try to
876 * replenish again. It's unlikely, but if we fail to supply even
877 * one buffer, nothing will trigger another replenish attempt.
878 * Receive buffer transactions use one TRE, so schedule work to
879 * try replenishing again if our backlog is *all* available TREs.
880 */
881 gsi = &endpoint->ipa->gsi;
882 if (backlog == gsi_channel_tre_max(gsi, endpoint->channel_id))
883 schedule_delayed_work(&endpoint->replenish_work,
884 msecs_to_jiffies(1));
885}
886
887static void ipa_endpoint_replenish_enable(struct ipa_endpoint *endpoint)
888{
889 struct gsi *gsi = &endpoint->ipa->gsi;
890 u32 max_backlog;
891 u32 saved;
892
893 endpoint->replenish_enabled = true;
894 while ((saved = atomic_xchg(&endpoint->replenish_saved, 0)))
895 atomic_add(saved, &endpoint->replenish_backlog);
896
897 /* Start replenishing if hardware currently has no buffers */
898 max_backlog = gsi_channel_tre_max(gsi, endpoint->channel_id);
899 if (atomic_read(&endpoint->replenish_backlog) == max_backlog)
900 ipa_endpoint_replenish(endpoint, 0);
901}
902
903static void ipa_endpoint_replenish_disable(struct ipa_endpoint *endpoint)
904{
905 u32 backlog;
906
907 endpoint->replenish_enabled = false;
908 while ((backlog = atomic_xchg(&endpoint->replenish_backlog, 0)))
909 atomic_add(backlog, &endpoint->replenish_saved);
910}
911
912static void ipa_endpoint_replenish_work(struct work_struct *work)
913{
914 struct delayed_work *dwork = to_delayed_work(work);
915 struct ipa_endpoint *endpoint;
916
917 endpoint = container_of(dwork, struct ipa_endpoint, replenish_work);
918
919 ipa_endpoint_replenish(endpoint, 0);
920}
921
922static void ipa_endpoint_skb_copy(struct ipa_endpoint *endpoint,
923 void *data, u32 len, u32 extra)
924{
925 struct sk_buff *skb;
926
927 skb = __dev_alloc_skb(len, GFP_ATOMIC);
928 if (skb) {
929 skb_put(skb, len);
930 memcpy(skb->data, data, len);
931 skb->truesize += extra;
932 }
933
934 /* Now receive it, or drop it if there's no netdev */
935 if (endpoint->netdev)
936 ipa_modem_skb_rx(endpoint->netdev, skb);
937 else if (skb)
938 dev_kfree_skb_any(skb);
939}
940
941static bool ipa_endpoint_skb_build(struct ipa_endpoint *endpoint,
942 struct page *page, u32 len)
943{
944 struct sk_buff *skb;
945
946 /* Nothing to do if there's no netdev */
947 if (!endpoint->netdev)
948 return false;
949
950 /* assert(len <= SKB_WITH_OVERHEAD(IPA_RX_BUFFER_SIZE-NET_SKB_PAD)); */
951 skb = build_skb(page_address(page), IPA_RX_BUFFER_SIZE);
952 if (skb) {
953 /* Reserve the headroom and account for the data */
954 skb_reserve(skb, NET_SKB_PAD);
955 skb_put(skb, len);
956 }
957
958 /* Receive the buffer (or record drop if unable to build it) */
959 ipa_modem_skb_rx(endpoint->netdev, skb);
960
961 return skb != NULL;
962}
963
964/* The format of a packet status element is the same for several status
965 * types (opcodes). The NEW_FRAG_RULE, LOG, DCMP (decompression) types
966 * aren't currently supported
967 */
968static bool ipa_status_format_packet(enum ipa_status_opcode opcode)
969{
970 switch (opcode) {
971 case IPA_STATUS_OPCODE_PACKET:
972 case IPA_STATUS_OPCODE_DROPPED_PACKET:
973 case IPA_STATUS_OPCODE_SUSPENDED_PACKET:
974 case IPA_STATUS_OPCODE_PACKET_2ND_PASS:
975 return true;
976 default:
977 return false;
978 }
979}
980
981static bool ipa_endpoint_status_skip(struct ipa_endpoint *endpoint,
982 const struct ipa_status *status)
983{
984 u32 endpoint_id;
985
986 if (!ipa_status_format_packet(status->opcode))
987 return true;
988 if (!status->pkt_len)
989 return true;
990 endpoint_id = u32_get_bits(status->endp_dst_idx,
991 IPA_STATUS_DST_IDX_FMASK);
992 if (endpoint_id != endpoint->endpoint_id)
993 return true;
994
995 return false; /* Don't skip this packet, process it */
996}
997
998/* Return whether the status indicates the packet should be dropped */
999static bool ipa_status_drop_packet(const struct ipa_status *status)
1000{
1001 u32 val;
1002
1003 /* Deaggregation exceptions we drop; others we consume */
1004 if (status->exception)
1005 return status->exception == IPA_STATUS_EXCEPTION_DEAGGR;
1006
1007 /* Drop the packet if it fails to match a routing rule; otherwise no */
1008 val = le32_get_bits(status->flags1, IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK);
1009
1010 return val == field_max(IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK);
1011}
1012
1013static void ipa_endpoint_status_parse(struct ipa_endpoint *endpoint,
1014 struct page *page, u32 total_len)
1015{
1016 void *data = page_address(page) + NET_SKB_PAD;
1017 u32 unused = IPA_RX_BUFFER_SIZE - total_len;
1018 u32 resid = total_len;
1019
1020 while (resid) {
1021 const struct ipa_status *status = data;
1022 u32 align;
1023 u32 len;
1024
1025 if (resid < sizeof(*status)) {
1026 dev_err(&endpoint->ipa->pdev->dev,
1027 "short message (%u bytes < %zu byte status)\n",
1028 resid, sizeof(*status));
1029 break;
1030 }
1031
1032 /* Skip over status packets that lack packet data */
1033 if (ipa_endpoint_status_skip(endpoint, status)) {
1034 data += sizeof(*status);
1035 resid -= sizeof(*status);
1036 continue;
1037 }
1038
1039 /* Compute the amount of buffer space consumed by the
1040 * packet, including the status element. If the hardware
1041 * is configured to pad packet data to an aligned boundary,
1042 * account for that. And if checksum offload is is enabled
1043 * a trailer containing computed checksum information will
1044 * be appended.
1045 */
1046 align = endpoint->data->rx.pad_align ? : 1;
1047 len = le16_to_cpu(status->pkt_len);
1048 len = sizeof(*status) + ALIGN(len, align);
1049 if (endpoint->data->checksum)
1050 len += sizeof(struct rmnet_map_dl_csum_trailer);
1051
1052 /* Charge the new packet with a proportional fraction of
1053 * the unused space in the original receive buffer.
1054 * XXX Charge a proportion of the *whole* receive buffer?
1055 */
1056 if (!ipa_status_drop_packet(status)) {
1057 u32 extra = unused * len / total_len;
1058 void *data2 = data + sizeof(*status);
1059 u32 len2 = le16_to_cpu(status->pkt_len);
1060
1061 /* Client receives only packet data (no status) */
1062 ipa_endpoint_skb_copy(endpoint, data2, len2, extra);
1063 }
1064
1065 /* Consume status and the full packet it describes */
1066 data += len;
1067 resid -= len;
1068 }
1069}
1070
1071/* Complete a TX transaction, command or from ipa_endpoint_skb_tx() */
1072static void ipa_endpoint_tx_complete(struct ipa_endpoint *endpoint,
1073 struct gsi_trans *trans)
1074{
1075}
1076
1077/* Complete transaction initiated in ipa_endpoint_replenish_one() */
1078static void ipa_endpoint_rx_complete(struct ipa_endpoint *endpoint,
1079 struct gsi_trans *trans)
1080{
1081 struct page *page;
1082
1083 ipa_endpoint_replenish(endpoint, 1);
1084
1085 if (trans->cancelled)
1086 return;
1087
1088 /* Parse or build a socket buffer using the actual received length */
1089 page = trans->data;
1090 if (endpoint->data->status_enable)
1091 ipa_endpoint_status_parse(endpoint, page, trans->len);
1092 else if (ipa_endpoint_skb_build(endpoint, page, trans->len))
1093 trans->data = NULL; /* Pages have been consumed */
1094}
1095
1096void ipa_endpoint_trans_complete(struct ipa_endpoint *endpoint,
1097 struct gsi_trans *trans)
1098{
1099 if (endpoint->toward_ipa)
1100 ipa_endpoint_tx_complete(endpoint, trans);
1101 else
1102 ipa_endpoint_rx_complete(endpoint, trans);
1103}
1104
1105void ipa_endpoint_trans_release(struct ipa_endpoint *endpoint,
1106 struct gsi_trans *trans)
1107{
1108 if (endpoint->toward_ipa) {
1109 struct ipa *ipa = endpoint->ipa;
1110
1111 /* Nothing to do for command transactions */
1112 if (endpoint != ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]) {
1113 struct sk_buff *skb = trans->data;
1114
1115 if (skb)
1116 dev_kfree_skb_any(skb);
1117 }
1118 } else {
1119 struct page *page = trans->data;
1120
1121 if (page)
Alex Elder6fcd4222020-03-20 11:02:20 -05001122 __free_pages(page, get_order(IPA_RX_BUFFER_SIZE));
Alex Elder84f9bd12020-03-05 22:28:24 -06001123 }
1124}
1125
1126void ipa_endpoint_default_route_set(struct ipa *ipa, u32 endpoint_id)
1127{
1128 u32 val;
1129
1130 /* ROUTE_DIS is 0 */
1131 val = u32_encode_bits(endpoint_id, ROUTE_DEF_PIPE_FMASK);
1132 val |= ROUTE_DEF_HDR_TABLE_FMASK;
1133 val |= u32_encode_bits(0, ROUTE_DEF_HDR_OFST_FMASK);
1134 val |= u32_encode_bits(endpoint_id, ROUTE_FRAG_DEF_PIPE_FMASK);
1135 val |= ROUTE_DEF_RETAIN_HDR_FMASK;
1136
1137 iowrite32(val, ipa->reg_virt + IPA_REG_ROUTE_OFFSET);
1138}
1139
1140void ipa_endpoint_default_route_clear(struct ipa *ipa)
1141{
1142 ipa_endpoint_default_route_set(ipa, 0);
1143}
1144
1145static bool ipa_endpoint_aggr_active(struct ipa_endpoint *endpoint)
1146{
1147 u32 mask = BIT(endpoint->endpoint_id);
1148 struct ipa *ipa = endpoint->ipa;
1149 u32 offset;
1150 u32 val;
1151
1152 /* assert(mask & ipa->available); */
1153 offset = ipa_reg_state_aggr_active_offset(ipa->version);
1154 val = ioread32(ipa->reg_virt + offset);
1155
1156 return !!(val & mask);
1157}
1158
1159static void ipa_endpoint_force_close(struct ipa_endpoint *endpoint)
1160{
1161 u32 mask = BIT(endpoint->endpoint_id);
1162 struct ipa *ipa = endpoint->ipa;
1163
1164 /* assert(mask & ipa->available); */
1165 iowrite32(mask, ipa->reg_virt + IPA_REG_AGGR_FORCE_CLOSE_OFFSET);
1166}
1167
1168/**
1169 * ipa_endpoint_reset_rx_aggr() - Reset RX endpoint with aggregation active
1170 * @endpoint: Endpoint to be reset
1171 *
1172 * If aggregation is active on an RX endpoint when a reset is performed
1173 * on its underlying GSI channel, a special sequence of actions must be
1174 * taken to ensure the IPA pipeline is properly cleared.
1175 *
1176 * @Return: 0 if successful, or a negative error code
1177 */
1178static int ipa_endpoint_reset_rx_aggr(struct ipa_endpoint *endpoint)
1179{
1180 struct device *dev = &endpoint->ipa->pdev->dev;
1181 struct ipa *ipa = endpoint->ipa;
Alex Elder84f9bd12020-03-05 22:28:24 -06001182 struct gsi *gsi = &ipa->gsi;
Alex Elder4fa95242020-05-04 18:37:12 -05001183 bool suspended = false;
Alex Elder84f9bd12020-03-05 22:28:24 -06001184 dma_addr_t addr;
Alex Elderf86a1902020-05-04 18:30:02 -05001185 bool legacy;
Alex Elder84f9bd12020-03-05 22:28:24 -06001186 u32 retries;
1187 u32 len = 1;
1188 void *virt;
1189 int ret;
1190
1191 virt = kzalloc(len, GFP_KERNEL);
1192 if (!virt)
1193 return -ENOMEM;
1194
1195 addr = dma_map_single(dev, virt, len, DMA_FROM_DEVICE);
1196 if (dma_mapping_error(dev, addr)) {
1197 ret = -ENOMEM;
1198 goto out_kfree;
1199 }
1200
1201 /* Force close aggregation before issuing the reset */
1202 ipa_endpoint_force_close(endpoint);
1203
1204 /* Reset and reconfigure the channel with the doorbell engine
1205 * disabled. Then poll until we know aggregation is no longer
1206 * active. We'll re-enable the doorbell (if appropriate) when
1207 * we reset again below.
1208 */
1209 gsi_channel_reset(gsi, endpoint->channel_id, false);
1210
1211 /* Make sure the channel isn't suspended */
1212 if (endpoint->ipa->version == IPA_VERSION_3_5_1)
Alex Elder4fa95242020-05-04 18:37:12 -05001213 suspended = ipa_endpoint_program_suspend(endpoint, false);
Alex Elder84f9bd12020-03-05 22:28:24 -06001214
1215 /* Start channel and do a 1 byte read */
1216 ret = gsi_channel_start(gsi, endpoint->channel_id);
1217 if (ret)
1218 goto out_suspend_again;
1219
1220 ret = gsi_trans_read_byte(gsi, endpoint->channel_id, addr);
1221 if (ret)
1222 goto err_endpoint_stop;
1223
1224 /* Wait for aggregation to be closed on the channel */
1225 retries = IPA_ENDPOINT_RESET_AGGR_RETRY_MAX;
1226 do {
1227 if (!ipa_endpoint_aggr_active(endpoint))
1228 break;
1229 msleep(1);
1230 } while (retries--);
1231
1232 /* Check one last time */
1233 if (ipa_endpoint_aggr_active(endpoint))
1234 dev_err(dev, "endpoint %u still active during reset\n",
1235 endpoint->endpoint_id);
1236
1237 gsi_trans_read_byte_done(gsi, endpoint->channel_id);
1238
Alex Elderf30dcb72020-05-04 18:53:44 -05001239 ret = gsi_channel_stop(gsi, endpoint->channel_id);
Alex Elder84f9bd12020-03-05 22:28:24 -06001240 if (ret)
1241 goto out_suspend_again;
1242
1243 /* Finally, reset and reconfigure the channel again (re-enabling the
1244 * the doorbell engine if appropriate). Sleep for 1 millisecond to
1245 * complete the channel reset sequence. Finish by suspending the
1246 * channel again (if necessary).
1247 */
Alex Elderf86a1902020-05-04 18:30:02 -05001248 legacy = ipa->version == IPA_VERSION_3_5_1;
1249 gsi_channel_reset(gsi, endpoint->channel_id, legacy);
Alex Elder84f9bd12020-03-05 22:28:24 -06001250
1251 msleep(1);
1252
1253 goto out_suspend_again;
1254
1255err_endpoint_stop:
Alex Elderf30dcb72020-05-04 18:53:44 -05001256 (void)gsi_channel_stop(gsi, endpoint->channel_id);
Alex Elder84f9bd12020-03-05 22:28:24 -06001257out_suspend_again:
Alex Elder4fa95242020-05-04 18:37:12 -05001258 if (suspended)
1259 (void)ipa_endpoint_program_suspend(endpoint, true);
Alex Elder84f9bd12020-03-05 22:28:24 -06001260 dma_unmap_single(dev, addr, len, DMA_FROM_DEVICE);
1261out_kfree:
1262 kfree(virt);
1263
1264 return ret;
1265}
1266
1267static void ipa_endpoint_reset(struct ipa_endpoint *endpoint)
1268{
1269 u32 channel_id = endpoint->channel_id;
1270 struct ipa *ipa = endpoint->ipa;
Alex Elder84f9bd12020-03-05 22:28:24 -06001271 bool special;
Alex Elderf86a1902020-05-04 18:30:02 -05001272 bool legacy;
Alex Elder84f9bd12020-03-05 22:28:24 -06001273 int ret = 0;
1274
1275 /* On IPA v3.5.1, if an RX endpoint is reset while aggregation
1276 * is active, we need to handle things specially to recover.
1277 * All other cases just need to reset the underlying GSI channel.
1278 *
1279 * IPA v3.5.1 enables the doorbell engine. Newer versions do not.
1280 */
Alex Elderf86a1902020-05-04 18:30:02 -05001281 legacy = ipa->version == IPA_VERSION_3_5_1;
Alex Elder84f9bd12020-03-05 22:28:24 -06001282 special = !endpoint->toward_ipa && endpoint->data->aggregation;
1283 if (special && ipa_endpoint_aggr_active(endpoint))
1284 ret = ipa_endpoint_reset_rx_aggr(endpoint);
1285 else
Alex Elderf86a1902020-05-04 18:30:02 -05001286 gsi_channel_reset(&ipa->gsi, channel_id, legacy);
Alex Elder84f9bd12020-03-05 22:28:24 -06001287
1288 if (ret)
1289 dev_err(&ipa->pdev->dev,
1290 "error %d resetting channel %u for endpoint %u\n",
1291 ret, endpoint->channel_id, endpoint->endpoint_id);
1292}
1293
Alex Elder84f9bd12020-03-05 22:28:24 -06001294static void ipa_endpoint_program(struct ipa_endpoint *endpoint)
1295{
Alex Elder84f9bd12020-03-05 22:28:24 -06001296 if (endpoint->toward_ipa) {
Alex Elder4fa95242020-05-04 18:37:12 -05001297 if (endpoint->ipa->version != IPA_VERSION_4_2)
Alex Eldera4dcad32020-05-04 18:37:13 -05001298 ipa_endpoint_program_delay(endpoint, false);
Alex Elder84f9bd12020-03-05 22:28:24 -06001299 ipa_endpoint_init_hdr_ext(endpoint);
1300 ipa_endpoint_init_aggr(endpoint);
1301 ipa_endpoint_init_deaggr(endpoint);
1302 ipa_endpoint_init_seq(endpoint);
1303 } else {
Alex Elder4fa95242020-05-04 18:37:12 -05001304 if (endpoint->ipa->version == IPA_VERSION_3_5_1)
1305 (void)ipa_endpoint_program_suspend(endpoint, false);
Alex Elder84f9bd12020-03-05 22:28:24 -06001306 ipa_endpoint_init_hdr_ext(endpoint);
1307 ipa_endpoint_init_aggr(endpoint);
1308 }
1309 ipa_endpoint_init_cfg(endpoint);
1310 ipa_endpoint_init_hdr(endpoint);
1311 ipa_endpoint_init_hdr_metadata_mask(endpoint);
1312 ipa_endpoint_init_mode(endpoint);
1313 ipa_endpoint_status(endpoint);
1314}
1315
1316int ipa_endpoint_enable_one(struct ipa_endpoint *endpoint)
1317{
1318 struct ipa *ipa = endpoint->ipa;
1319 struct gsi *gsi = &ipa->gsi;
1320 int ret;
1321
1322 ret = gsi_channel_start(gsi, endpoint->channel_id);
1323 if (ret) {
1324 dev_err(&ipa->pdev->dev,
1325 "error %d starting %cX channel %u for endpoint %u\n",
1326 ret, endpoint->toward_ipa ? 'T' : 'R',
1327 endpoint->channel_id, endpoint->endpoint_id);
1328 return ret;
1329 }
1330
1331 if (!endpoint->toward_ipa) {
1332 ipa_interrupt_suspend_enable(ipa->interrupt,
1333 endpoint->endpoint_id);
1334 ipa_endpoint_replenish_enable(endpoint);
1335 }
1336
1337 ipa->enabled |= BIT(endpoint->endpoint_id);
1338
1339 return 0;
1340}
1341
1342void ipa_endpoint_disable_one(struct ipa_endpoint *endpoint)
1343{
1344 u32 mask = BIT(endpoint->endpoint_id);
1345 struct ipa *ipa = endpoint->ipa;
Alex Elderf30dcb72020-05-04 18:53:44 -05001346 struct gsi *gsi = &ipa->gsi;
Alex Elder84f9bd12020-03-05 22:28:24 -06001347 int ret;
1348
Alex Elderf30dcb72020-05-04 18:53:44 -05001349 if (!(ipa->enabled & mask))
Alex Elder84f9bd12020-03-05 22:28:24 -06001350 return;
1351
Alex Elderf30dcb72020-05-04 18:53:44 -05001352 ipa->enabled ^= mask;
Alex Elder84f9bd12020-03-05 22:28:24 -06001353
1354 if (!endpoint->toward_ipa) {
1355 ipa_endpoint_replenish_disable(endpoint);
1356 ipa_interrupt_suspend_disable(ipa->interrupt,
1357 endpoint->endpoint_id);
1358 }
1359
1360 /* Note that if stop fails, the channel's state is not well-defined */
Alex Elderf30dcb72020-05-04 18:53:44 -05001361 ret = gsi_channel_stop(gsi, endpoint->channel_id);
Alex Elder84f9bd12020-03-05 22:28:24 -06001362 if (ret)
1363 dev_err(&ipa->pdev->dev,
1364 "error %d attempting to stop endpoint %u\n", ret,
1365 endpoint->endpoint_id);
1366}
1367
1368/**
1369 * ipa_endpoint_suspend_aggr() - Emulate suspend interrupt
1370 * @endpoint_id: Endpoint on which to emulate a suspend
1371 *
1372 * Emulate suspend IPA interrupt to unsuspend an endpoint suspended
1373 * with an open aggregation frame. This is to work around a hardware
1374 * issue in IPA version 3.5.1 where the suspend interrupt will not be
1375 * generated when it should be.
1376 */
1377static void ipa_endpoint_suspend_aggr(struct ipa_endpoint *endpoint)
1378{
1379 struct ipa *ipa = endpoint->ipa;
1380
1381 /* assert(ipa->version == IPA_VERSION_3_5_1); */
1382
1383 if (!endpoint->data->aggregation)
1384 return;
1385
1386 /* Nothing to do if the endpoint doesn't have aggregation open */
1387 if (!ipa_endpoint_aggr_active(endpoint))
1388 return;
1389
1390 /* Force close aggregation */
1391 ipa_endpoint_force_close(endpoint);
1392
1393 ipa_interrupt_simulate_suspend(ipa->interrupt);
1394}
1395
1396void ipa_endpoint_suspend_one(struct ipa_endpoint *endpoint)
1397{
1398 struct device *dev = &endpoint->ipa->pdev->dev;
1399 struct gsi *gsi = &endpoint->ipa->gsi;
1400 bool stop_channel;
1401 int ret;
1402
1403 if (!(endpoint->ipa->enabled & BIT(endpoint->endpoint_id)))
1404 return;
1405
1406 if (!endpoint->toward_ipa)
1407 ipa_endpoint_replenish_disable(endpoint);
1408
1409 /* IPA v3.5.1 doesn't use channel stop for suspend */
1410 stop_channel = endpoint->ipa->version != IPA_VERSION_3_5_1;
1411 if (!endpoint->toward_ipa && !stop_channel) {
1412 /* Due to a hardware bug, a client suspended with an open
1413 * aggregation frame will not generate a SUSPEND IPA
1414 * interrupt. We work around this by force-closing the
1415 * aggregation frame, then simulating the arrival of such
1416 * an interrupt.
1417 */
Alex Elder4fa95242020-05-04 18:37:12 -05001418 (void)ipa_endpoint_program_suspend(endpoint, true);
Alex Elder84f9bd12020-03-05 22:28:24 -06001419 ipa_endpoint_suspend_aggr(endpoint);
1420 }
1421
1422 ret = gsi_channel_suspend(gsi, endpoint->channel_id, stop_channel);
1423 if (ret)
1424 dev_err(dev, "error %d suspending channel %u\n", ret,
1425 endpoint->channel_id);
1426}
1427
1428void ipa_endpoint_resume_one(struct ipa_endpoint *endpoint)
1429{
1430 struct device *dev = &endpoint->ipa->pdev->dev;
1431 struct gsi *gsi = &endpoint->ipa->gsi;
1432 bool start_channel;
1433 int ret;
1434
1435 if (!(endpoint->ipa->enabled & BIT(endpoint->endpoint_id)))
1436 return;
1437
1438 /* IPA v3.5.1 doesn't use channel start for resume */
1439 start_channel = endpoint->ipa->version != IPA_VERSION_3_5_1;
1440 if (!endpoint->toward_ipa && !start_channel)
Alex Elder4fa95242020-05-04 18:37:12 -05001441 (void)ipa_endpoint_program_suspend(endpoint, false);
Alex Elder84f9bd12020-03-05 22:28:24 -06001442
1443 ret = gsi_channel_resume(gsi, endpoint->channel_id, start_channel);
1444 if (ret)
1445 dev_err(dev, "error %d resuming channel %u\n", ret,
1446 endpoint->channel_id);
1447 else if (!endpoint->toward_ipa)
1448 ipa_endpoint_replenish_enable(endpoint);
1449}
1450
1451void ipa_endpoint_suspend(struct ipa *ipa)
1452{
1453 if (ipa->modem_netdev)
1454 ipa_modem_suspend(ipa->modem_netdev);
1455
1456 ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_LAN_RX]);
1457 ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]);
1458}
1459
1460void ipa_endpoint_resume(struct ipa *ipa)
1461{
1462 ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_COMMAND_TX]);
1463 ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_LAN_RX]);
1464
1465 if (ipa->modem_netdev)
1466 ipa_modem_resume(ipa->modem_netdev);
1467}
1468
1469static void ipa_endpoint_setup_one(struct ipa_endpoint *endpoint)
1470{
1471 struct gsi *gsi = &endpoint->ipa->gsi;
1472 u32 channel_id = endpoint->channel_id;
1473
1474 /* Only AP endpoints get set up */
1475 if (endpoint->ee_id != GSI_EE_AP)
1476 return;
1477
1478 endpoint->trans_tre_max = gsi_channel_trans_tre_max(gsi, channel_id);
1479 if (!endpoint->toward_ipa) {
1480 /* RX transactions require a single TRE, so the maximum
1481 * backlog is the same as the maximum outstanding TREs.
1482 */
1483 endpoint->replenish_enabled = false;
1484 atomic_set(&endpoint->replenish_saved,
1485 gsi_channel_tre_max(gsi, endpoint->channel_id));
1486 atomic_set(&endpoint->replenish_backlog, 0);
1487 INIT_DELAYED_WORK(&endpoint->replenish_work,
1488 ipa_endpoint_replenish_work);
1489 }
1490
1491 ipa_endpoint_program(endpoint);
1492
1493 endpoint->ipa->set_up |= BIT(endpoint->endpoint_id);
1494}
1495
1496static void ipa_endpoint_teardown_one(struct ipa_endpoint *endpoint)
1497{
1498 endpoint->ipa->set_up &= ~BIT(endpoint->endpoint_id);
1499
1500 if (!endpoint->toward_ipa)
1501 cancel_delayed_work_sync(&endpoint->replenish_work);
1502
1503 ipa_endpoint_reset(endpoint);
1504}
1505
1506void ipa_endpoint_setup(struct ipa *ipa)
1507{
1508 u32 initialized = ipa->initialized;
1509
1510 ipa->set_up = 0;
1511 while (initialized) {
1512 u32 endpoint_id = __ffs(initialized);
1513
1514 initialized ^= BIT(endpoint_id);
1515
1516 ipa_endpoint_setup_one(&ipa->endpoint[endpoint_id]);
1517 }
1518}
1519
1520void ipa_endpoint_teardown(struct ipa *ipa)
1521{
1522 u32 set_up = ipa->set_up;
1523
1524 while (set_up) {
1525 u32 endpoint_id = __fls(set_up);
1526
1527 set_up ^= BIT(endpoint_id);
1528
1529 ipa_endpoint_teardown_one(&ipa->endpoint[endpoint_id]);
1530 }
1531 ipa->set_up = 0;
1532}
1533
1534int ipa_endpoint_config(struct ipa *ipa)
1535{
1536 struct device *dev = &ipa->pdev->dev;
1537 u32 initialized;
1538 u32 rx_base;
1539 u32 rx_mask;
1540 u32 tx_mask;
1541 int ret = 0;
1542 u32 max;
1543 u32 val;
1544
1545 /* Find out about the endpoints supplied by the hardware, and ensure
1546 * the highest one doesn't exceed the number we support.
1547 */
1548 val = ioread32(ipa->reg_virt + IPA_REG_FLAVOR_0_OFFSET);
1549
1550 /* Our RX is an IPA producer */
1551 rx_base = u32_get_bits(val, BAM_PROD_LOWEST_FMASK);
1552 max = rx_base + u32_get_bits(val, BAM_MAX_PROD_PIPES_FMASK);
1553 if (max > IPA_ENDPOINT_MAX) {
1554 dev_err(dev, "too many endpoints (%u > %u)\n",
1555 max, IPA_ENDPOINT_MAX);
1556 return -EINVAL;
1557 }
1558 rx_mask = GENMASK(max - 1, rx_base);
1559
1560 /* Our TX is an IPA consumer */
1561 max = u32_get_bits(val, BAM_MAX_CONS_PIPES_FMASK);
1562 tx_mask = GENMASK(max - 1, 0);
1563
1564 ipa->available = rx_mask | tx_mask;
1565
1566 /* Check for initialized endpoints not supported by the hardware */
1567 if (ipa->initialized & ~ipa->available) {
1568 dev_err(dev, "unavailable endpoint id(s) 0x%08x\n",
1569 ipa->initialized & ~ipa->available);
1570 ret = -EINVAL; /* Report other errors too */
1571 }
1572
1573 initialized = ipa->initialized;
1574 while (initialized) {
1575 u32 endpoint_id = __ffs(initialized);
1576 struct ipa_endpoint *endpoint;
1577
1578 initialized ^= BIT(endpoint_id);
1579
1580 /* Make sure it's pointing in the right direction */
1581 endpoint = &ipa->endpoint[endpoint_id];
1582 if ((endpoint_id < rx_base) != !!endpoint->toward_ipa) {
1583 dev_err(dev, "endpoint id %u wrong direction\n",
1584 endpoint_id);
1585 ret = -EINVAL;
1586 }
1587 }
1588
1589 return ret;
1590}
1591
1592void ipa_endpoint_deconfig(struct ipa *ipa)
1593{
1594 ipa->available = 0; /* Nothing more to do */
1595}
1596
1597static void ipa_endpoint_init_one(struct ipa *ipa, enum ipa_endpoint_name name,
1598 const struct ipa_gsi_endpoint_data *data)
1599{
1600 struct ipa_endpoint *endpoint;
1601
1602 endpoint = &ipa->endpoint[data->endpoint_id];
1603
1604 if (data->ee_id == GSI_EE_AP)
1605 ipa->channel_map[data->channel_id] = endpoint;
1606 ipa->name_map[name] = endpoint;
1607
1608 endpoint->ipa = ipa;
1609 endpoint->ee_id = data->ee_id;
1610 endpoint->seq_type = data->endpoint.seq_type;
1611 endpoint->channel_id = data->channel_id;
1612 endpoint->endpoint_id = data->endpoint_id;
1613 endpoint->toward_ipa = data->toward_ipa;
1614 endpoint->data = &data->endpoint.config;
1615
1616 ipa->initialized |= BIT(endpoint->endpoint_id);
1617}
1618
1619void ipa_endpoint_exit_one(struct ipa_endpoint *endpoint)
1620{
1621 endpoint->ipa->initialized &= ~BIT(endpoint->endpoint_id);
1622
1623 memset(endpoint, 0, sizeof(*endpoint));
1624}
1625
1626void ipa_endpoint_exit(struct ipa *ipa)
1627{
1628 u32 initialized = ipa->initialized;
1629
1630 while (initialized) {
1631 u32 endpoint_id = __fls(initialized);
1632
1633 initialized ^= BIT(endpoint_id);
1634
1635 ipa_endpoint_exit_one(&ipa->endpoint[endpoint_id]);
1636 }
1637 memset(ipa->name_map, 0, sizeof(ipa->name_map));
1638 memset(ipa->channel_map, 0, sizeof(ipa->channel_map));
1639}
1640
1641/* Returns a bitmask of endpoints that support filtering, or 0 on error */
1642u32 ipa_endpoint_init(struct ipa *ipa, u32 count,
1643 const struct ipa_gsi_endpoint_data *data)
1644{
1645 enum ipa_endpoint_name name;
1646 u32 filter_map;
1647
1648 if (!ipa_endpoint_data_valid(ipa, count, data))
1649 return 0; /* Error */
1650
1651 ipa->initialized = 0;
1652
1653 filter_map = 0;
1654 for (name = 0; name < count; name++, data++) {
1655 if (ipa_gsi_endpoint_data_empty(data))
1656 continue; /* Skip over empty slots */
1657
1658 ipa_endpoint_init_one(ipa, name, data);
1659
1660 if (data->endpoint.filter_support)
1661 filter_map |= BIT(data->endpoint_id);
1662 }
1663
1664 if (!ipa_filter_map_valid(ipa, filter_map))
1665 goto err_endpoint_exit;
1666
1667 return filter_map; /* Non-zero bitmask */
1668
1669err_endpoint_exit:
1670 ipa_endpoint_exit(ipa);
1671
1672 return 0; /* Error */
1673}