1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3 1 2 /* 3 * Copyright 2014-2016 Freescale Semiconductor 4 * Copyright 2016 NXP 5 * 6 */ 7 #ifndef __FSL_DPAA2_FD_H 8 #define __FSL_DPAA2_FD_H 9 10 #include <linux/byteorder/generic.h> 11 #include <linux/types.h> 12 13 /** 14 * DOC: DPAA2 FD - Frame Descriptor APIs for D 15 * 16 * Frame Descriptors (FDs) are used to describ 17 * Frames can be enqueued and dequeued to Fram 18 * by the various DPAA accelerators (WRIOP, SE 19 * 20 * There are three types of frames: single, sc 21 * 22 * The set of APIs in this file must be used t 23 * query Frame Descriptors. 24 */ 25 26 /** 27 * struct dpaa2_fd - Struct describing FDs 28 * @words: for easier/faster copying t 29 * @addr: address in the FD 30 * @len: length in the FD 31 * @bpid: buffer pool ID 32 * @format_offset: format, offset, and short-l 33 * @frc: frame context 34 * @ctrl: control bits...including dd 35 * @flc: flow context address 36 * 37 * This structure represents the basic Frame D 38 */ 39 struct dpaa2_fd { 40 union { 41 u32 words[8]; 42 struct dpaa2_fd_simple { 43 __le64 addr; 44 __le32 len; 45 __le16 bpid; 46 __le16 format_offset; 47 __le32 frc; 48 __le32 ctrl; 49 __le64 flc; 50 } simple; 51 }; 52 }; 53 54 #define FD_SHORT_LEN_FLAG_MASK 0x1 55 #define FD_SHORT_LEN_FLAG_SHIFT 14 56 #define FD_SHORT_LEN_MASK 0x3FFFF 57 #define FD_OFFSET_MASK 0x0FFF 58 #define FD_FORMAT_MASK 0x3 59 #define FD_FORMAT_SHIFT 12 60 #define FD_BPID_MASK 0x3FFF 61 #define SG_SHORT_LEN_FLAG_MASK 0x1 62 #define SG_SHORT_LEN_FLAG_SHIFT 14 63 #define SG_SHORT_LEN_MASK 0x1FFFF 64 #define SG_OFFSET_MASK 0x0FFF 65 #define SG_FORMAT_MASK 0x3 66 #define SG_FORMAT_SHIFT 12 67 #define SG_BPID_MASK 0x3FFF 68 #define SG_FINAL_FLAG_MASK 0x1 69 #define SG_FINAL_FLAG_SHIFT 15 70 #define FL_SHORT_LEN_FLAG_MASK 0x1 71 #define FL_SHORT_LEN_FLAG_SHIFT 14 72 #define FL_SHORT_LEN_MASK 0x3FFFF 73 #define FL_OFFSET_MASK 0x0FFF 74 #define FL_FORMAT_MASK 0x3 75 #define FL_FORMAT_SHIFT 12 76 #define FL_BPID_MASK 0x3FFF 77 #define FL_FINAL_FLAG_MASK 0x1 78 #define FL_FINAL_FLAG_SHIFT 15 79 80 /* Error bits in FD CTRL */ 81 #define FD_CTRL_ERR_MASK 0x000000FF 82 #define FD_CTRL_UFD 0x00000004 83 #define FD_CTRL_SBE 0x00000008 84 #define FD_CTRL_FLC 0x00000010 85 #define FD_CTRL_FSE 0x00000020 86 #define FD_CTRL_FAERR 0x00000040 87 88 /* Annotation bits in FD CTRL */ 89 #define FD_CTRL_PTA 0x00800000 90 #define FD_CTRL_PTV1 0x00400000 91 92 enum dpaa2_fd_format { 93 dpaa2_fd_single = 0, 94 dpaa2_fd_list, 95 dpaa2_fd_sg 96 }; 97 98 /** 99 * dpaa2_fd_get_addr() - get the addr field of 100 * @fd: the given frame descriptor 101 * 102 * Return the address in the frame descriptor. 103 */ 104 static inline dma_addr_t dpaa2_fd_get_addr(con 105 { 106 return (dma_addr_t)le64_to_cpu(fd->sim 107 } 108 109 /** 110 * dpaa2_fd_set_addr() - Set the addr field of 111 * @fd: the given frame descriptor 112 * @addr: the address needs to be set in frame 113 */ 114 static inline void dpaa2_fd_set_addr(struct dp 115 { 116 fd->simple.addr = cpu_to_le64(addr); 117 } 118 119 /** 120 * dpaa2_fd_get_frc() - Get the frame context 121 * @fd: the given frame descriptor 122 * 123 * Return the frame context field in the frame 124 */ 125 static inline u32 dpaa2_fd_get_frc(const struc 126 { 127 return le32_to_cpu(fd->simple.frc); 128 } 129 130 /** 131 * dpaa2_fd_set_frc() - Set the frame context 132 * @fd: the given frame descriptor 133 * @frc: the frame context needs to be set in 134 */ 135 static inline void dpaa2_fd_set_frc(struct dpa 136 { 137 fd->simple.frc = cpu_to_le32(frc); 138 } 139 140 /** 141 * dpaa2_fd_get_ctrl() - Get the control bits 142 * @fd: the given frame descriptor 143 * 144 * Return the control bits field in the frame 145 */ 146 static inline u32 dpaa2_fd_get_ctrl(const stru 147 { 148 return le32_to_cpu(fd->simple.ctrl); 149 } 150 151 /** 152 * dpaa2_fd_set_ctrl() - Set the control bits 153 * @fd: the given frame descriptor 154 * @ctrl: the control bits to be set in the fr 155 */ 156 static inline void dpaa2_fd_set_ctrl(struct dp 157 { 158 fd->simple.ctrl = cpu_to_le32(ctrl); 159 } 160 161 /** 162 * dpaa2_fd_get_flc() - Get the flow context i 163 * @fd: the given frame descriptor 164 * 165 * Return the flow context in the frame descri 166 */ 167 static inline dma_addr_t dpaa2_fd_get_flc(cons 168 { 169 return (dma_addr_t)le64_to_cpu(fd->sim 170 } 171 172 /** 173 * dpaa2_fd_set_flc() - Set the flow context f 174 * @fd: the given frame descriptor 175 * @flc_addr: the flow context needs to be set 176 */ 177 static inline void dpaa2_fd_set_flc(struct dpa 178 { 179 fd->simple.flc = cpu_to_le64(flc_addr) 180 } 181 182 static inline bool dpaa2_fd_short_len(const st 183 { 184 return !!((le16_to_cpu(fd->simple.form 185 FD_SHORT_LEN_FLAG_SHIFT) & F 186 } 187 188 /** 189 * dpaa2_fd_get_len() - Get the length in the 190 * @fd: the given frame descriptor 191 * 192 * Return the length field in the frame descri 193 */ 194 static inline u32 dpaa2_fd_get_len(const struc 195 { 196 if (dpaa2_fd_short_len(fd)) 197 return le32_to_cpu(fd->simple. 198 199 return le32_to_cpu(fd->simple.len); 200 } 201 202 /** 203 * dpaa2_fd_set_len() - Set the length field o 204 * @fd: the given frame descriptor 205 * @len: the length needs to be set in frame d 206 */ 207 static inline void dpaa2_fd_set_len(struct dpa 208 { 209 fd->simple.len = cpu_to_le32(len); 210 } 211 212 /** 213 * dpaa2_fd_get_offset() - Get the offset fiel 214 * @fd: the given frame descriptor 215 * 216 * Return the offset. 217 */ 218 static inline uint16_t dpaa2_fd_get_offset(con 219 { 220 return le16_to_cpu(fd->simple.format_o 221 } 222 223 /** 224 * dpaa2_fd_set_offset() - Set the offset fiel 225 * @fd: the given frame descriptor 226 * @offset: the offset needs to be set in fram 227 */ 228 static inline void dpaa2_fd_set_offset(struct 229 { 230 fd->simple.format_offset &= cpu_to_le1 231 fd->simple.format_offset |= cpu_to_le1 232 } 233 234 /** 235 * dpaa2_fd_get_format() - Get the format fiel 236 * @fd: the given frame descriptor 237 * 238 * Return the format. 239 */ 240 static inline enum dpaa2_fd_format dpaa2_fd_ge 241 242 { 243 return (enum dpaa2_fd_format)((le16_to 244 >> FD_FO 245 } 246 247 /** 248 * dpaa2_fd_set_format() - Set the format fiel 249 * @fd: the given frame descriptor 250 * @format: the format needs to be set in fram 251 */ 252 static inline void dpaa2_fd_set_format(struct 253 enum dp 254 { 255 fd->simple.format_offset &= 256 cpu_to_le16(~(FD_FORMAT_MASK < 257 fd->simple.format_offset |= cpu_to_le1 258 } 259 260 /** 261 * dpaa2_fd_get_bpid() - Get the bpid field in 262 * @fd: the given frame descriptor 263 * 264 * Return the buffer pool id. 265 */ 266 static inline uint16_t dpaa2_fd_get_bpid(const 267 { 268 return le16_to_cpu(fd->simple.bpid) & 269 } 270 271 /** 272 * dpaa2_fd_set_bpid() - Set the bpid field of 273 * @fd: the given frame descriptor 274 * @bpid: buffer pool id to be set 275 */ 276 static inline void dpaa2_fd_set_bpid(struct dp 277 { 278 fd->simple.bpid &= cpu_to_le16(~(FD_BP 279 fd->simple.bpid |= cpu_to_le16(bpid); 280 } 281 282 /** 283 * struct dpaa2_sg_entry - the scatter-gatheri 284 * @addr: address of the sg entry 285 * @len: length in this sg entry 286 * @bpid: buffer pool id 287 * @format_offset: format and offset fields 288 */ 289 struct dpaa2_sg_entry { 290 __le64 addr; 291 __le32 len; 292 __le16 bpid; 293 __le16 format_offset; 294 }; 295 296 enum dpaa2_sg_format { 297 dpaa2_sg_single = 0, 298 dpaa2_sg_frame_data, 299 dpaa2_sg_sgt_ext 300 }; 301 302 /* Accessors for SG entry fields */ 303 304 /** 305 * dpaa2_sg_get_addr() - Get the address from 306 * @sg: the given scatter-gathering object 307 * 308 * Return the address. 309 */ 310 static inline dma_addr_t dpaa2_sg_get_addr(con 311 { 312 return (dma_addr_t)le64_to_cpu(sg->add 313 } 314 315 /** 316 * dpaa2_sg_set_addr() - Set the address in SG 317 * @sg: the given scatter-gathering object 318 * @addr: the address to be set 319 */ 320 static inline void dpaa2_sg_set_addr(struct dp 321 { 322 sg->addr = cpu_to_le64(addr); 323 } 324 325 static inline bool dpaa2_sg_short_len(const st 326 { 327 return !!((le16_to_cpu(sg->format_offs 328 & SG_SHORT_LEN_FLAG_MASK); 329 } 330 331 /** 332 * dpaa2_sg_get_len() - Get the length in SG e 333 * @sg: the given scatter-gathering object 334 * 335 * Return the length. 336 */ 337 static inline u32 dpaa2_sg_get_len(const struc 338 { 339 if (dpaa2_sg_short_len(sg)) 340 return le32_to_cpu(sg->len) & 341 342 return le32_to_cpu(sg->len); 343 } 344 345 /** 346 * dpaa2_sg_set_len() - Set the length in SG e 347 * @sg: the given scatter-gathering object 348 * @len: the length to be set 349 */ 350 static inline void dpaa2_sg_set_len(struct dpa 351 { 352 sg->len = cpu_to_le32(len); 353 } 354 355 /** 356 * dpaa2_sg_get_offset() - Get the offset in S 357 * @sg: the given scatter-gathering object 358 * 359 * Return the offset. 360 */ 361 static inline u16 dpaa2_sg_get_offset(const st 362 { 363 return le16_to_cpu(sg->format_offset) 364 } 365 366 /** 367 * dpaa2_sg_set_offset() - Set the offset in S 368 * @sg: the given scatter-gathering object 369 * @offset: the offset to be set 370 */ 371 static inline void dpaa2_sg_set_offset(struct 372 u16 off 373 { 374 sg->format_offset &= cpu_to_le16(~SG_O 375 sg->format_offset |= cpu_to_le16(offse 376 } 377 378 /** 379 * dpaa2_sg_get_format() - Get the SG format i 380 * @sg: the given scatter-gathering object 381 * 382 * Return the format. 383 */ 384 static inline enum dpaa2_sg_format 385 dpaa2_sg_get_format(const struct dpaa2 386 { 387 return (enum dpaa2_sg_format)((le16_to 388 >> SG_F 389 } 390 391 /** 392 * dpaa2_sg_set_format() - Set the SG format i 393 * @sg: the given scatter-gathering object 394 * @format: the format to be set 395 */ 396 static inline void dpaa2_sg_set_format(struct 397 enum dp 398 { 399 sg->format_offset &= cpu_to_le16(~(SG_ 400 sg->format_offset |= cpu_to_le16(forma 401 } 402 403 /** 404 * dpaa2_sg_get_bpid() - Get the buffer pool i 405 * @sg: the given scatter-gathering object 406 * 407 * Return the bpid. 408 */ 409 static inline u16 dpaa2_sg_get_bpid(const stru 410 { 411 return le16_to_cpu(sg->bpid) & SG_BPID 412 } 413 414 /** 415 * dpaa2_sg_set_bpid() - Set the buffer pool i 416 * @sg: the given scatter-gathering object 417 * @bpid: the bpid to be set 418 */ 419 static inline void dpaa2_sg_set_bpid(struct dp 420 { 421 sg->bpid &= cpu_to_le16(~(SG_BPID_MASK 422 sg->bpid |= cpu_to_le16(bpid); 423 } 424 425 /** 426 * dpaa2_sg_is_final() - Check final bit in SG 427 * @sg: the given scatter-gathering object 428 * 429 * Return bool. 430 */ 431 static inline bool dpaa2_sg_is_final(const str 432 { 433 return !!(le16_to_cpu(sg->format_offse 434 } 435 436 /** 437 * dpaa2_sg_set_final() - Set the final bit in 438 * @sg: the given scatter-gathering object 439 * @final: the final boolean to be set 440 */ 441 static inline void dpaa2_sg_set_final(struct d 442 { 443 sg->format_offset &= cpu_to_le16((~(SG 444 << SG 445 sg->format_offset |= cpu_to_le16(final 446 } 447 448 /** 449 * struct dpaa2_fl_entry - structure for frame 450 * @addr: address in the FLE 451 * @len: length in the FLE 452 * @bpid: buffer pool ID 453 * @format_offset: format, offset, and short-l 454 * @frc: frame context 455 * @ctrl: control bits...including pt 456 * @flc: flow context address 457 */ 458 struct dpaa2_fl_entry { 459 __le64 addr; 460 __le32 len; 461 __le16 bpid; 462 __le16 format_offset; 463 __le32 frc; 464 __le32 ctrl; 465 __le64 flc; 466 }; 467 468 enum dpaa2_fl_format { 469 dpaa2_fl_single = 0, 470 dpaa2_fl_res, 471 dpaa2_fl_sg 472 }; 473 474 /** 475 * dpaa2_fl_get_addr() - get the addr field of 476 * @fle: the given frame list entry 477 * 478 * Return the address in the frame list entry. 479 */ 480 static inline dma_addr_t dpaa2_fl_get_addr(con 481 { 482 return (dma_addr_t)le64_to_cpu(fle->ad 483 } 484 485 /** 486 * dpaa2_fl_set_addr() - Set the addr field of 487 * @fle: the given frame list entry 488 * @addr: the address needs to be set in frame 489 */ 490 static inline void dpaa2_fl_set_addr(struct dp 491 dma_addr_ 492 { 493 fle->addr = cpu_to_le64(addr); 494 } 495 496 /** 497 * dpaa2_fl_get_frc() - Get the frame context 498 * @fle: the given frame list entry 499 * 500 * Return the frame context field in the frame 501 */ 502 static inline u32 dpaa2_fl_get_frc(const struc 503 { 504 return le32_to_cpu(fle->frc); 505 } 506 507 /** 508 * dpaa2_fl_set_frc() - Set the frame context 509 * @fle: the given frame list entry 510 * @frc: the frame context needs to be set in 511 */ 512 static inline void dpaa2_fl_set_frc(struct dpa 513 { 514 fle->frc = cpu_to_le32(frc); 515 } 516 517 /** 518 * dpaa2_fl_get_ctrl() - Get the control bits 519 * @fle: the given frame list entry 520 * 521 * Return the control bits field in the frame 522 */ 523 static inline u32 dpaa2_fl_get_ctrl(const stru 524 { 525 return le32_to_cpu(fle->ctrl); 526 } 527 528 /** 529 * dpaa2_fl_set_ctrl() - Set the control bits 530 * @fle: the given frame list entry 531 * @ctrl: the control bits to be set in the fr 532 */ 533 static inline void dpaa2_fl_set_ctrl(struct dp 534 { 535 fle->ctrl = cpu_to_le32(ctrl); 536 } 537 538 /** 539 * dpaa2_fl_get_flc() - Get the flow context i 540 * @fle: the given frame list entry 541 * 542 * Return the flow context in the frame list e 543 */ 544 static inline dma_addr_t dpaa2_fl_get_flc(cons 545 { 546 return (dma_addr_t)le64_to_cpu(fle->fl 547 } 548 549 /** 550 * dpaa2_fl_set_flc() - Set the flow context f 551 * @fle: the given frame list entry 552 * @flc_addr: the flow context needs to be set 553 */ 554 static inline void dpaa2_fl_set_flc(struct dpa 555 dma_addr_t 556 { 557 fle->flc = cpu_to_le64(flc_addr); 558 } 559 560 static inline bool dpaa2_fl_short_len(const st 561 { 562 return !!((le16_to_cpu(fle->format_off 563 FL_SHORT_LEN_FLAG_SHIFT) & F 564 } 565 566 /** 567 * dpaa2_fl_get_len() - Get the length in the 568 * @fle: the given frame list entry 569 * 570 * Return the length field in the frame list e 571 */ 572 static inline u32 dpaa2_fl_get_len(const struc 573 { 574 if (dpaa2_fl_short_len(fle)) 575 return le32_to_cpu(fle->len) & 576 577 return le32_to_cpu(fle->len); 578 } 579 580 /** 581 * dpaa2_fl_set_len() - Set the length field o 582 * @fle: the given frame list entry 583 * @len: the length needs to be set in frame l 584 */ 585 static inline void dpaa2_fl_set_len(struct dpa 586 { 587 fle->len = cpu_to_le32(len); 588 } 589 590 /** 591 * dpaa2_fl_get_offset() - Get the offset fiel 592 * @fle: the given frame list entry 593 * 594 * Return the offset. 595 */ 596 static inline u16 dpaa2_fl_get_offset(const st 597 { 598 return le16_to_cpu(fle->format_offset) 599 } 600 601 /** 602 * dpaa2_fl_set_offset() - Set the offset fiel 603 * @fle: the given frame list entry 604 * @offset: the offset needs to be set in fram 605 */ 606 static inline void dpaa2_fl_set_offset(struct 607 { 608 fle->format_offset &= cpu_to_le16(~FL_ 609 fle->format_offset |= cpu_to_le16(offs 610 } 611 612 /** 613 * dpaa2_fl_get_format() - Get the format fiel 614 * @fle: the given frame list entry 615 * 616 * Return the format. 617 */ 618 static inline enum dpaa2_fl_format dpaa2_fl_ge 619 { 620 return (enum dpaa2_fl_format)((le16_to 621 FL_FORM 622 } 623 624 /** 625 * dpaa2_fl_set_format() - Set the format fiel 626 * @fle: the given frame list entry 627 * @format: the format needs to be set in fram 628 */ 629 static inline void dpaa2_fl_set_format(struct 630 enum dp 631 { 632 fle->format_offset &= cpu_to_le16(~(FL 633 fle->format_offset |= cpu_to_le16(form 634 } 635 636 /** 637 * dpaa2_fl_get_bpid() - Get the bpid field in 638 * @fle: the given frame list entry 639 * 640 * Return the buffer pool id. 641 */ 642 static inline u16 dpaa2_fl_get_bpid(const stru 643 { 644 return le16_to_cpu(fle->bpid) & FL_BPI 645 } 646 647 /** 648 * dpaa2_fl_set_bpid() - Set the bpid field of 649 * @fle: the given frame list entry 650 * @bpid: buffer pool id to be set 651 */ 652 static inline void dpaa2_fl_set_bpid(struct dp 653 { 654 fle->bpid &= cpu_to_le16(~(FL_BPID_MAS 655 fle->bpid |= cpu_to_le16(bpid); 656 } 657 658 /** 659 * dpaa2_fl_is_final() - Check final bit in FL 660 * @fle: the given frame list entry 661 * 662 * Return bool. 663 */ 664 static inline bool dpaa2_fl_is_final(const str 665 { 666 return !!(le16_to_cpu(fle->format_offs 667 } 668 669 /** 670 * dpaa2_fl_set_final() - Set the final bit in 671 * @fle: the given frame list entry 672 * @final: the final boolean to be set 673 */ 674 static inline void dpaa2_fl_set_final(struct d 675 { 676 fle->format_offset &= cpu_to_le16((~(F 677 F 678 fle->format_offset |= cpu_to_le16(fina 679 } 680 681 #endif /* __FSL_DPAA2_FD_H */ 682
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.