0001
0002
0003
0004 #ifndef _MLXSW_PCI_HW_H
0005 #define _MLXSW_PCI_HW_H
0006
0007 #include <linux/bitops.h>
0008
0009 #include "item.h"
0010
0011 #define MLXSW_PCI_BAR0_SIZE (1024 * 1024)
0012 #define MLXSW_PCI_PAGE_SIZE 4096
0013
0014 #define MLXSW_PCI_CIR_BASE 0x71000
0015 #define MLXSW_PCI_CIR_IN_PARAM_HI MLXSW_PCI_CIR_BASE
0016 #define MLXSW_PCI_CIR_IN_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x04)
0017 #define MLXSW_PCI_CIR_IN_MODIFIER (MLXSW_PCI_CIR_BASE + 0x08)
0018 #define MLXSW_PCI_CIR_OUT_PARAM_HI (MLXSW_PCI_CIR_BASE + 0x0C)
0019 #define MLXSW_PCI_CIR_OUT_PARAM_LO (MLXSW_PCI_CIR_BASE + 0x10)
0020 #define MLXSW_PCI_CIR_TOKEN (MLXSW_PCI_CIR_BASE + 0x14)
0021 #define MLXSW_PCI_CIR_CTRL (MLXSW_PCI_CIR_BASE + 0x18)
0022 #define MLXSW_PCI_CIR_CTRL_GO_BIT BIT(23)
0023 #define MLXSW_PCI_CIR_CTRL_EVREQ_BIT BIT(22)
0024 #define MLXSW_PCI_CIR_CTRL_OPCODE_MOD_SHIFT 12
0025 #define MLXSW_PCI_CIR_CTRL_STATUS_SHIFT 24
0026 #define MLXSW_PCI_CIR_TIMEOUT_MSECS 1000
0027
0028 #define MLXSW_PCI_SW_RESET_TIMEOUT_MSECS 900000
0029 #define MLXSW_PCI_SW_RESET_WAIT_MSECS 200
0030 #define MLXSW_PCI_FW_READY 0xA1844
0031 #define MLXSW_PCI_FW_READY_MASK 0xFFFF
0032 #define MLXSW_PCI_FW_READY_MAGIC 0x5E
0033
0034 #define MLXSW_PCI_DOORBELL_SDQ_OFFSET 0x000
0035 #define MLXSW_PCI_DOORBELL_RDQ_OFFSET 0x200
0036 #define MLXSW_PCI_DOORBELL_CQ_OFFSET 0x400
0037 #define MLXSW_PCI_DOORBELL_EQ_OFFSET 0x600
0038 #define MLXSW_PCI_DOORBELL_ARM_CQ_OFFSET 0x800
0039 #define MLXSW_PCI_DOORBELL_ARM_EQ_OFFSET 0xA00
0040
0041 #define MLXSW_PCI_DOORBELL(offset, type_offset, num) \
0042 ((offset) + (type_offset) + (num) * 4)
0043
0044 #define MLXSW_PCI_CQS_MAX 96
0045 #define MLXSW_PCI_EQS_COUNT 2
0046 #define MLXSW_PCI_EQ_ASYNC_NUM 0
0047 #define MLXSW_PCI_EQ_COMP_NUM 1
0048
0049 #define MLXSW_PCI_SDQS_MIN 2
0050 #define MLXSW_PCI_SDQ_EMAD_INDEX 0
0051 #define MLXSW_PCI_SDQ_EMAD_TC 0
0052 #define MLXSW_PCI_SDQ_CTL_TC 3
0053
0054 #define MLXSW_PCI_AQ_PAGES 8
0055 #define MLXSW_PCI_AQ_SIZE (MLXSW_PCI_PAGE_SIZE * MLXSW_PCI_AQ_PAGES)
0056 #define MLXSW_PCI_WQE_SIZE 32
0057 #define MLXSW_PCI_CQE01_SIZE 16
0058 #define MLXSW_PCI_CQE2_SIZE 32
0059 #define MLXSW_PCI_CQE_SIZE_MAX MLXSW_PCI_CQE2_SIZE
0060 #define MLXSW_PCI_EQE_SIZE 16
0061 #define MLXSW_PCI_WQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_WQE_SIZE)
0062 #define MLXSW_PCI_CQE01_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE01_SIZE)
0063 #define MLXSW_PCI_CQE2_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE2_SIZE)
0064 #define MLXSW_PCI_EQE_COUNT (MLXSW_PCI_AQ_SIZE / MLXSW_PCI_EQE_SIZE)
0065 #define MLXSW_PCI_EQE_UPDATE_COUNT 0x80
0066
0067 #define MLXSW_PCI_WQE_SG_ENTRIES 3
0068 #define MLXSW_PCI_WQE_TYPE_ETHERNET 0xA
0069
0070
0071
0072
0073
0074 MLXSW_ITEM32(pci, wqe, c, 0x00, 31, 1);
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 MLXSW_ITEM32(pci, wqe, lp, 0x00, 30, 1);
0087
0088
0089
0090
0091 MLXSW_ITEM32(pci, wqe, type, 0x00, 23, 4);
0092
0093
0094
0095
0096 MLXSW_ITEM16_INDEXED(pci, wqe, byte_count, 0x02, 0, 14, 0x02, 0x00, false);
0097
0098
0099
0100
0101
0102 MLXSW_ITEM64_INDEXED(pci, wqe, address, 0x08, 0, 64, 0x8, 0x0, false);
0103
0104 enum mlxsw_pci_cqe_v {
0105 MLXSW_PCI_CQE_V0,
0106 MLXSW_PCI_CQE_V1,
0107 MLXSW_PCI_CQE_V2,
0108 };
0109
0110 #define mlxsw_pci_cqe_item_helpers(name, v0, v1, v2) \
0111 static inline u32 mlxsw_pci_cqe_##name##_get(enum mlxsw_pci_cqe_v v, char *cqe) \
0112 { \
0113 switch (v) { \
0114 default: \
0115 case MLXSW_PCI_CQE_V0: \
0116 return mlxsw_pci_cqe##v0##_##name##_get(cqe); \
0117 case MLXSW_PCI_CQE_V1: \
0118 return mlxsw_pci_cqe##v1##_##name##_get(cqe); \
0119 case MLXSW_PCI_CQE_V2: \
0120 return mlxsw_pci_cqe##v2##_##name##_get(cqe); \
0121 } \
0122 } \
0123 static inline void mlxsw_pci_cqe_##name##_set(enum mlxsw_pci_cqe_v v, \
0124 char *cqe, u32 val) \
0125 { \
0126 switch (v) { \
0127 default: \
0128 case MLXSW_PCI_CQE_V0: \
0129 mlxsw_pci_cqe##v0##_##name##_set(cqe, val); \
0130 break; \
0131 case MLXSW_PCI_CQE_V1: \
0132 mlxsw_pci_cqe##v1##_##name##_set(cqe, val); \
0133 break; \
0134 case MLXSW_PCI_CQE_V2: \
0135 mlxsw_pci_cqe##v2##_##name##_set(cqe, val); \
0136 break; \
0137 } \
0138 }
0139
0140
0141
0142
0143 MLXSW_ITEM32(pci, cqe0, lag, 0x00, 23, 1);
0144 MLXSW_ITEM32(pci, cqe12, lag, 0x00, 24, 1);
0145 mlxsw_pci_cqe_item_helpers(lag, 0, 12, 12);
0146
0147
0148
0149
0150
0151
0152
0153 MLXSW_ITEM32(pci, cqe, system_port, 0x00, 0, 16);
0154 MLXSW_ITEM32(pci, cqe0, lag_id, 0x00, 4, 12);
0155 MLXSW_ITEM32(pci, cqe12, lag_id, 0x00, 0, 16);
0156 mlxsw_pci_cqe_item_helpers(lag_id, 0, 12, 12);
0157 MLXSW_ITEM32(pci, cqe0, lag_subport, 0x00, 0, 4);
0158 MLXSW_ITEM32(pci, cqe12, lag_subport, 0x00, 16, 8);
0159 mlxsw_pci_cqe_item_helpers(lag_subport, 0, 12, 12);
0160
0161
0162
0163
0164 MLXSW_ITEM32(pci, cqe, wqe_counter, 0x04, 16, 16);
0165
0166
0167
0168
0169
0170
0171 MLXSW_ITEM32(pci, cqe, byte_count, 0x04, 0, 14);
0172
0173 #define MLXSW_PCI_CQE2_MIRROR_CONG_INVALID 0xFFFF
0174
0175
0176
0177
0178
0179
0180 MLXSW_ITEM32(pci, cqe2, mirror_cong_high, 0x08, 16, 4);
0181
0182
0183
0184
0185 MLXSW_ITEM32(pci, cqe, trap_id, 0x08, 0, 10);
0186
0187
0188
0189
0190
0191 MLXSW_ITEM32(pci, cqe0, crc, 0x0C, 8, 1);
0192 MLXSW_ITEM32(pci, cqe12, crc, 0x0C, 9, 1);
0193 mlxsw_pci_cqe_item_helpers(crc, 0, 12, 12);
0194
0195
0196
0197
0198 MLXSW_ITEM32(pci, cqe0, e, 0x0C, 7, 1);
0199 MLXSW_ITEM32(pci, cqe12, e, 0x00, 27, 1);
0200 mlxsw_pci_cqe_item_helpers(e, 0, 12, 12);
0201
0202
0203
0204
0205
0206 MLXSW_ITEM32(pci, cqe0, sr, 0x0C, 6, 1);
0207 MLXSW_ITEM32(pci, cqe12, sr, 0x00, 26, 1);
0208 mlxsw_pci_cqe_item_helpers(sr, 0, 12, 12);
0209
0210
0211
0212
0213 MLXSW_ITEM32(pci, cqe0, dqn, 0x0C, 1, 5);
0214 MLXSW_ITEM32(pci, cqe12, dqn, 0x0C, 1, 6);
0215 mlxsw_pci_cqe_item_helpers(dqn, 0, 12, 12);
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234 MLXSW_ITEM32(pci, cqe2, time_stamp_low, 0x0C, 16, 16);
0235
0236 #define MLXSW_PCI_CQE2_MIRROR_TCLASS_INVALID 0x1F
0237
0238
0239
0240
0241
0242 MLXSW_ITEM32(pci, cqe2, mirror_tclass, 0x10, 27, 5);
0243
0244
0245
0246
0247 MLXSW_ITEM32(pci, cqe2, tx_lag, 0x10, 24, 1);
0248
0249
0250
0251
0252
0253 MLXSW_ITEM32(pci, cqe2, tx_lag_subport, 0x10, 16, 8);
0254
0255 #define MLXSW_PCI_CQE2_TX_PORT_MULTI_PORT 0xFFFE
0256 #define MLXSW_PCI_CQE2_TX_PORT_INVALID 0xFFFF
0257
0258
0259
0260
0261
0262
0263 MLXSW_ITEM32(pci, cqe2, tx_lag_id, 0x10, 0, 16);
0264
0265
0266
0267
0268
0269
0270 MLXSW_ITEM32(pci, cqe2, tx_system_port, 0x10, 0, 16);
0271
0272
0273
0274
0275
0276
0277 MLXSW_ITEM32(pci, cqe2, mirror_cong_low, 0x14, 20, 12);
0278
0279 #define MLXSW_PCI_CQE2_MIRROR_CONG_SHIFT 13
0280
0281 static inline u16 mlxsw_pci_cqe2_mirror_cong_get(const char *cqe)
0282 {
0283 u16 cong_high = mlxsw_pci_cqe2_mirror_cong_high_get(cqe);
0284 u16 cong_low = mlxsw_pci_cqe2_mirror_cong_low_get(cqe);
0285
0286 return cong_high << 12 | cong_low;
0287 }
0288
0289
0290
0291
0292 MLXSW_ITEM32(pci, cqe2, user_def_val_orig_pkt_len, 0x14, 0, 20);
0293
0294
0295
0296
0297 MLXSW_ITEM32(pci, cqe2, mirror_reason, 0x18, 24, 8);
0298
0299 enum mlxsw_pci_cqe_time_stamp_type {
0300 MLXSW_PCI_CQE_TIME_STAMP_TYPE_USEC,
0301 MLXSW_PCI_CQE_TIME_STAMP_TYPE_FRC,
0302 MLXSW_PCI_CQE_TIME_STAMP_TYPE_UTC,
0303 MLXSW_PCI_CQE_TIME_STAMP_TYPE_MIRROR_UTC,
0304 };
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 MLXSW_ITEM32(pci, cqe2, time_stamp_type, 0x18, 22, 2);
0316
0317 #define MLXSW_PCI_CQE2_MIRROR_LATENCY_INVALID 0xFFFFFF
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 MLXSW_ITEM32(pci, cqe2, time_stamp_high, 0x18, 0, 22);
0337
0338 static inline u64 mlxsw_pci_cqe2_time_stamp_get(const char *cqe)
0339 {
0340 u64 ts_high = mlxsw_pci_cqe2_time_stamp_high_get(cqe);
0341 u64 ts_low = mlxsw_pci_cqe2_time_stamp_low_get(cqe);
0342
0343 return ts_high << 16 | ts_low;
0344 }
0345
0346 static inline u8 mlxsw_pci_cqe2_time_stamp_sec_get(const char *cqe)
0347 {
0348 u64 full_ts = mlxsw_pci_cqe2_time_stamp_get(cqe);
0349
0350 return full_ts >> 30 & 0xFF;
0351 }
0352
0353 static inline u32 mlxsw_pci_cqe2_time_stamp_nsec_get(const char *cqe)
0354 {
0355 u64 full_ts = mlxsw_pci_cqe2_time_stamp_get(cqe);
0356
0357 return full_ts & 0x3FFFFFFF;
0358 }
0359
0360
0361
0362
0363
0364
0365 MLXSW_ITEM32(pci, cqe2, mirror_latency, 0x1C, 8, 24);
0366
0367
0368
0369
0370 MLXSW_ITEM32(pci, cqe01, owner, 0x0C, 0, 1);
0371 MLXSW_ITEM32(pci, cqe2, owner, 0x1C, 0, 1);
0372 mlxsw_pci_cqe_item_helpers(owner, 01, 01, 2);
0373
0374
0375
0376
0377 MLXSW_ITEM32(pci, eqe, event_type, 0x0C, 24, 8);
0378 #define MLXSW_PCI_EQE_EVENT_TYPE_COMP 0x00
0379 #define MLXSW_PCI_EQE_EVENT_TYPE_CMD 0x0A
0380
0381
0382
0383
0384 MLXSW_ITEM32(pci, eqe, event_sub_type, 0x0C, 16, 8);
0385
0386
0387
0388
0389 MLXSW_ITEM32(pci, eqe, cqn, 0x0C, 8, 7);
0390
0391
0392
0393
0394 MLXSW_ITEM32(pci, eqe, owner, 0x0C, 0, 1);
0395
0396
0397
0398
0399 MLXSW_ITEM32(pci, eqe, cmd_token, 0x00, 16, 16);
0400
0401
0402
0403
0404 MLXSW_ITEM32(pci, eqe, cmd_status, 0x00, 0, 8);
0405
0406
0407
0408
0409 MLXSW_ITEM32(pci, eqe, cmd_out_param_h, 0x04, 0, 32);
0410
0411
0412
0413
0414 MLXSW_ITEM32(pci, eqe, cmd_out_param_l, 0x08, 0, 32);
0415
0416 #endif