qdf_nbuf.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. /*
  2. * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /**
  27. * DOC: cdf_nbuf_public network buffer API
  28. * This file defines the network buffer abstraction.
  29. */
  30. #ifndef _CDF_NBUF_H
  31. #define _CDF_NBUF_H
  32. #include <cdf_util.h>
  33. #include <cdf_types.h>
  34. #include <cdf_net_types.h>
  35. #include <cdf_lock.h>
  36. #include <i_cdf_nbuf.h>
  37. #include <asm/cacheflush.h>
  38. #define IPA_NBUF_OWNER_ID 0xaa55aa55
  39. #define NBUF_PKT_TRAC_TYPE_EAPOL 0x02
  40. #define NBUF_PKT_TRAC_TYPE_DHCP 0x04
  41. #define NBUF_PKT_TRAC_TYPE_MGMT_ACTION 0x08
  42. #define NBUF_PKT_TRAC_MAX_STRING 12
  43. #define NBUF_PKT_TRAC_PROTO_STRING 4
  44. #define NBUF_PKT_ERROR 1
  45. /* Tracked Packet types */
  46. #define NBUF_TX_PKT_INVALID 0
  47. #define NBUF_TX_PKT_DATA_TRACK 1
  48. #define NBUF_TX_PKT_MGMT_TRACK 2
  49. /* Different Packet states */
  50. #define NBUF_TX_PKT_HDD 1
  51. #define NBUF_TX_PKT_TXRX_ENQUEUE 2
  52. #define NBUF_TX_PKT_TXRX_DEQUEUE 3
  53. #define NBUF_TX_PKT_TXRX 4
  54. #define NBUF_TX_PKT_HTT 5
  55. #define NBUF_TX_PKT_HTC 6
  56. #define NBUF_TX_PKT_HIF 7
  57. #define NBUF_TX_PKT_CE 8
  58. #define NBUF_TX_PKT_FREE 9
  59. #define NBUF_TX_PKT_STATE_MAX 10
  60. /**
  61. * @cdf_nbuf_t - Platform indepedent packet abstraction
  62. */
  63. typedef __cdf_nbuf_t cdf_nbuf_t;
  64. /**
  65. * @cdf_dma_map_cb_t - Dma map callback prototype
  66. */
  67. typedef void (*cdf_dma_map_cb_t)(void *arg, cdf_nbuf_t buf,
  68. cdf_dma_map_t dmap);
  69. /**
  70. * @__CDF_NBUF_NULL - invalid handle
  71. */
  72. #define CDF_NBUF_NULL __CDF_NBUF_NULL
  73. /**
  74. * @cdf_nbuf_queue_t - Platform independent packet queue abstraction
  75. */
  76. typedef __cdf_nbuf_queue_t cdf_nbuf_queue_t;
  77. /* BUS/DMA mapping routines */
  78. /**
  79. * cdf_nbuf_map() - map a buffer to local bus address space
  80. * @osdev: OS device
  81. * @buf: Buf to be mapped (mapping info is stored in the buf's meta-data area)
  82. * @dir: DMA direction
  83. *
  84. * Return: Status of the operation
  85. */
  86. static inline CDF_STATUS
  87. cdf_nbuf_map(cdf_device_t osdev, cdf_nbuf_t buf, cdf_dma_dir_t dir)
  88. {
  89. return __cdf_nbuf_map(osdev, buf, dir);
  90. }
  91. /**
  92. * cdf_nbuf_unmap() - unmap a previously mapped buf
  93. * @osdev: OS device
  94. * @buf: Buf to be unmapped (mapping info is stored in the buf's meta-data area)
  95. * @dir: DMA direction
  96. *
  97. * Return: none
  98. */
  99. static inline void
  100. cdf_nbuf_unmap(cdf_device_t osdev, cdf_nbuf_t buf, cdf_dma_dir_t dir)
  101. {
  102. __cdf_nbuf_unmap(osdev, buf, dir);
  103. }
  104. /**
  105. * cdf_nbuf_map_single() - map a single buffer to local bus address space
  106. * @osdev: OS device
  107. * @buf: Buf to be mapped (mapping info is stored in the buf's meta-data area)
  108. * @dir: DMA direction
  109. *
  110. * Return: Status of the operation
  111. */
  112. static inline CDF_STATUS
  113. cdf_nbuf_map_single(cdf_device_t osdev, cdf_nbuf_t buf, cdf_dma_dir_t dir)
  114. {
  115. return __cdf_nbuf_map_single(osdev, buf, dir);
  116. }
  117. /**
  118. * cdf_nbuf_unmap_single() - unmap a previously mapped buf
  119. * @osdev: OS device
  120. * @buf: Buf to be unmapped (mapping info is stored in the buf's meta-data area)
  121. * @dir: DMA direction
  122. *
  123. * Return: none
  124. */
  125. static inline void
  126. cdf_nbuf_unmap_single(cdf_device_t osdev, cdf_nbuf_t buf, cdf_dma_dir_t dir)
  127. {
  128. __cdf_nbuf_unmap_single(osdev, buf, dir);
  129. }
  130. /**
  131. * cdf_nbuf_get_num_frags() - get number of fragments
  132. * @buf: Network buffer
  133. *
  134. * Return: Number of fragments
  135. */
  136. static inline int cdf_nbuf_get_num_frags(cdf_nbuf_t buf)
  137. {
  138. return __cdf_nbuf_get_num_frags(buf);
  139. }
  140. /**
  141. * cdf_nbuf_get_frag_len() - get fragment length
  142. * @buf: Network buffer
  143. * @frag_num: Fragment number
  144. *
  145. * Return: Fragment length
  146. */
  147. static inline int cdf_nbuf_get_frag_len(cdf_nbuf_t buf, int frag_num)
  148. {
  149. return __cdf_nbuf_get_frag_len(buf, frag_num);
  150. }
  151. /**
  152. * cdf_nbuf_get_frag_vaddr() - get fragment virtual address
  153. * @buf: Network buffer
  154. * @frag_num: Fragment number
  155. *
  156. * Return: Fragment virtual address
  157. */
  158. static inline unsigned char *cdf_nbuf_get_frag_vaddr(cdf_nbuf_t buf,
  159. int frag_num)
  160. {
  161. return __cdf_nbuf_get_frag_vaddr(buf, frag_num);
  162. }
  163. /**
  164. * cdf_nbuf_get_frag_paddr_lo() - get fragment physical address low order bytes
  165. * @buf: Network buffer
  166. * @frag_num: Fragment number
  167. *
  168. * Return: Fragment physical address lo
  169. */
  170. static inline uint32_t cdf_nbuf_get_frag_paddr_lo(cdf_nbuf_t buf, int frag_num)
  171. {
  172. return __cdf_nbuf_get_frag_paddr_lo(buf, frag_num);
  173. }
  174. /**
  175. * cdf_nbuf_get_frag_is_wordstream() - is fragment wordstream
  176. * @buf: Network buffer
  177. * @frag_num: Fragment number
  178. *
  179. * Return: Fragment wordstream or not
  180. */
  181. static inline int cdf_nbuf_get_frag_is_wordstream(cdf_nbuf_t buf, int frag_num)
  182. {
  183. return __cdf_nbuf_get_frag_is_wordstream(buf, frag_num);
  184. }
  185. /**
  186. * cdf_nbuf_set_frag_is_wordstream() - set fragment wordstream
  187. * @buf: Network buffer
  188. * @frag_num: Fragment number
  189. * @is_wordstream: Wordstream
  190. *
  191. * Return: none
  192. */
  193. static inline void
  194. cdf_nbuf_set_frag_is_wordstream(cdf_nbuf_t buf, int frag_num, int is_wordstream)
  195. {
  196. __cdf_nbuf_set_frag_is_wordstream(buf, frag_num, is_wordstream);
  197. }
  198. /**
  199. * cdf_nbuf_frag_push_head() - push fragment head
  200. * @buf: Network buffer
  201. * @frag_len: Fragment length
  202. * @frag_vaddr: Fragment virtual address
  203. * @frag_paddr_lo: Fragment physical address lo
  204. * @frag_paddr_hi: Fragment physical address hi
  205. *
  206. * Return: none
  207. */
  208. static inline void
  209. cdf_nbuf_frag_push_head(cdf_nbuf_t buf,
  210. int frag_len,
  211. char *frag_vaddr,
  212. uint32_t frag_paddr_lo, uint32_t frag_paddr_hi)
  213. {
  214. __cdf_nbuf_frag_push_head(buf, frag_len, frag_vaddr, frag_paddr_lo,
  215. frag_paddr_hi);
  216. }
  217. #ifdef MEMORY_DEBUG
  218. void cdf_net_buf_debug_init(void);
  219. void cdf_net_buf_debug_exit(void);
  220. void cdf_net_buf_debug_clean(void);
  221. void cdf_net_buf_debug_add_node(cdf_nbuf_t net_buf, size_t size,
  222. uint8_t *file_name, uint32_t line_num);
  223. void cdf_net_buf_debug_delete_node(cdf_nbuf_t net_buf);
  224. void cdf_net_buf_debug_release_skb(cdf_nbuf_t net_buf);
  225. /* nbuf allocation rouines */
  226. /**
  227. * cdf_nbuf_alloc() - Allocate cdf_nbuf
  228. * @hdl: Platform device object
  229. * @size: Data buffer size for this cdf_nbuf including max header
  230. * size
  231. * @reserve: Headroom to start with.
  232. * @align: Alignment for the start buffer.
  233. * @prio: Indicate if the nbuf is high priority (some OSes e.g darwin
  234. * polls few times if allocation fails and priority is true)
  235. *
  236. * The nbuf created is guarenteed to have only 1 physical segment
  237. *
  238. * Return: The new cdf_nbuf instance or NULL if there's not enough memory.
  239. */
  240. #define cdf_nbuf_alloc(d, s, r, a, p) \
  241. cdf_nbuf_alloc_debug(d, s, r, a, p, __FILE__, __LINE__)
  242. static inline cdf_nbuf_t
  243. cdf_nbuf_alloc_debug(cdf_device_t osdev, cdf_size_t size, int reserve,
  244. int align, int prio, uint8_t *file_name,
  245. uint32_t line_num)
  246. {
  247. cdf_nbuf_t net_buf;
  248. net_buf = __cdf_nbuf_alloc(osdev, size, reserve, align, prio);
  249. /* Store SKB in internal CDF tracking table */
  250. if (cdf_likely(net_buf))
  251. cdf_net_buf_debug_add_node(net_buf, size, file_name, line_num);
  252. return net_buf;
  253. }
  254. /**
  255. * cdf_nbuf_free() - free cdf_nbuf
  256. * @net_buf: Network buffer to free
  257. *
  258. * Return: none
  259. */
  260. static inline void cdf_nbuf_free(cdf_nbuf_t net_buf)
  261. {
  262. /* Remove SKB from internal CDF tracking table */
  263. if (cdf_likely(net_buf))
  264. cdf_net_buf_debug_delete_node(net_buf);
  265. __cdf_nbuf_free(net_buf);
  266. }
  267. #else
  268. static inline void cdf_net_buf_debug_release_skb(cdf_nbuf_t net_buf)
  269. {
  270. return;
  271. }
  272. /* Nbuf allocation rouines */
  273. /**
  274. * cdf_nbuf_alloc() - allocate cdf_nbuf
  275. * @hdl: Platform device object
  276. * @size: Data buffer size for this cdf_nbuf including max header
  277. * size
  278. * @reserve: Headroom to start with.
  279. * @align: Alignment for the start buffer.
  280. * @prio: Indicate if the nbuf is high priority (some OSes e.g darwin
  281. * polls few times if allocation fails and priority is true)
  282. *
  283. * The nbuf created is guarenteed to have only 1 physical segment
  284. *
  285. * Return: new cdf_nbuf instance or NULL if there's not enough memory.
  286. */
  287. static inline cdf_nbuf_t
  288. cdf_nbuf_alloc(cdf_device_t osdev,
  289. cdf_size_t size, int reserve, int align, int prio)
  290. {
  291. return __cdf_nbuf_alloc(osdev, size, reserve, align, prio);
  292. }
  293. /**
  294. * cdf_nbuf_free() - free cdf_nbuf
  295. * @buf: Network buffer to free
  296. *
  297. * Return: none
  298. */
  299. static inline void cdf_nbuf_free(cdf_nbuf_t buf)
  300. {
  301. __cdf_nbuf_free(buf);
  302. }
  303. #endif
  304. /**
  305. * cdf_nbuf_tx_free() - free a list of cdf_nbufs and tell the OS their tx
  306. * status (if req'd)
  307. * @bufs: List of netbufs to free
  308. * @tx_err: Whether the tx frames were transmitted successfully
  309. *
  310. * Return: none
  311. */
  312. static inline void cdf_nbuf_tx_free(cdf_nbuf_t buf_list, int tx_err)
  313. {
  314. __cdf_nbuf_tx_free(buf_list, tx_err);
  315. }
  316. /**
  317. * cdf_nbuf_copy() - copy src buffer into dst.
  318. * @buf: source nbuf to copy from
  319. *
  320. * This API is useful, for example, because most native buffer provide a way to
  321. * copy a chain into a single buffer. Therefore as a side effect, it also
  322. * "linearizes" a buffer (which is perhaps why you'll use it mostly). It
  323. * creates a writeable copy.
  324. *
  325. *
  326. * Return: new nbuf
  327. */
  328. static inline cdf_nbuf_t cdf_nbuf_copy(cdf_nbuf_t buf)
  329. {
  330. return __cdf_nbuf_copy(buf);
  331. }
  332. /**
  333. * cdf_nbuf_cat() - link two nbufs, the new buf is piggybacked into older one
  334. * @dst: Buffer to piggyback into
  335. * @src: Buffer to put
  336. *
  337. * Return: Status of the call - 0 successful
  338. */
  339. static inline CDF_STATUS cdf_nbuf_cat(cdf_nbuf_t dst, cdf_nbuf_t src)
  340. {
  341. return __cdf_nbuf_cat(dst, src);
  342. }
  343. /**
  344. * @cdf_nbuf_copy_bits() - return the length of the copy bits for skb
  345. * @skb: SKB pointer
  346. * @offset: offset
  347. * @len: Length
  348. * @to: To
  349. *
  350. * Return: int32_t
  351. */
  352. static inline int32_t
  353. cdf_nbuf_copy_bits(cdf_nbuf_t nbuf, uint32_t offset, uint32_t len, void *to)
  354. {
  355. return __cdf_nbuf_copy_bits(nbuf, offset, len, to);
  356. }
  357. /**
  358. * cdf_nbuf_clone() - clone the nbuf (copy is readonly)
  359. * @buf: nbuf to clone from
  360. *
  361. * Return: cloned buffer
  362. */
  363. static inline cdf_nbuf_t cdf_nbuf_clone(cdf_nbuf_t buf)
  364. {
  365. return __cdf_nbuf_clone(buf);
  366. }
  367. /* nbuf manipulation routines */
  368. /**
  369. * @cdf_nbuf_head() - return the address of an nbuf's buffer
  370. * @buf: netbuf
  371. *
  372. * Return: head address
  373. */
  374. static inline uint8_t *cdf_nbuf_head(cdf_nbuf_t buf)
  375. {
  376. return __cdf_nbuf_head(buf);
  377. }
  378. /**
  379. * cdf_nbuf_data() - Return the address of the start of data within an nbuf
  380. * @buf: Network buffer
  381. *
  382. * Return: Data address
  383. */
  384. static inline uint8_t *cdf_nbuf_data(cdf_nbuf_t buf)
  385. {
  386. return __cdf_nbuf_data(buf);
  387. }
  388. /**
  389. * cdf_nbuf_headroom() - amount of headroom int the current nbuf
  390. * @buf: Network buffer
  391. *
  392. * Return: Amount of head room
  393. */
  394. static inline uint32_t cdf_nbuf_headroom(cdf_nbuf_t buf)
  395. {
  396. return __cdf_nbuf_headroom(buf);
  397. }
  398. /**
  399. * cdf_nbuf_tailroom() - amount of tail space available
  400. * @buf: Network buffer
  401. *
  402. * Return: amount of tail room
  403. */
  404. static inline uint32_t cdf_nbuf_tailroom(cdf_nbuf_t buf)
  405. {
  406. return __cdf_nbuf_tailroom(buf);
  407. }
  408. /**
  409. * cdf_nbuf_push_head() - push data in the front
  410. * @buf: Network buf instance
  411. * @size: Size to be pushed
  412. *
  413. * Return: New data pointer of this buf after data has been pushed,
  414. * or NULL if there is not enough room in this buf.
  415. */
  416. static inline uint8_t *cdf_nbuf_push_head(cdf_nbuf_t buf, cdf_size_t size)
  417. {
  418. return __cdf_nbuf_push_head(buf, size);
  419. }
  420. /**
  421. * cdf_nbuf_put_tail() - puts data in the end
  422. * @buf: Network buf instance
  423. * @size: Size to be pushed
  424. *
  425. * Return: Data pointer of this buf where new data has to be
  426. * put, or NULL if there is not enough room in this buf.
  427. */
  428. static inline uint8_t *cdf_nbuf_put_tail(cdf_nbuf_t buf, cdf_size_t size)
  429. {
  430. return __cdf_nbuf_put_tail(buf, size);
  431. }
  432. /**
  433. * cdf_nbuf_pull_head() - pull data out from the front
  434. * @buf: Network buf instance
  435. * @size: Size to be popped
  436. *
  437. * Return: New data pointer of this buf after data has been popped,
  438. * or NULL if there is not sufficient data to pull.
  439. */
  440. static inline uint8_t *cdf_nbuf_pull_head(cdf_nbuf_t buf, cdf_size_t size)
  441. {
  442. return __cdf_nbuf_pull_head(buf, size);
  443. }
  444. /**
  445. * cdf_nbuf_trim_tail() - trim data out from the end
  446. * @buf: Network buf instance
  447. * @size: Size to be popped
  448. *
  449. * Return: none
  450. */
  451. static inline void cdf_nbuf_trim_tail(cdf_nbuf_t buf, cdf_size_t size)
  452. {
  453. __cdf_nbuf_trim_tail(buf, size);
  454. }
  455. /**
  456. * cdf_nbuf_len() - get the length of the buf
  457. * @buf: Network buf instance
  458. *
  459. * Return: total length of this buf.
  460. */
  461. static inline cdf_size_t cdf_nbuf_len(cdf_nbuf_t buf)
  462. {
  463. return __cdf_nbuf_len(buf);
  464. }
  465. /**
  466. * cdf_nbuf_set_pktlen() - set the length of the buf
  467. * @buf: Network buf instance
  468. * @size: Size to be set
  469. *
  470. * Return: none
  471. */
  472. static inline void cdf_nbuf_set_pktlen(cdf_nbuf_t buf, uint32_t len)
  473. {
  474. __cdf_nbuf_set_pktlen(buf, len);
  475. }
  476. /**
  477. * cdf_nbuf_reserve() - trim data out from the end
  478. * @buf: Network buf instance
  479. * @size: Size to be popped
  480. *
  481. * Return: none
  482. */
  483. static inline void cdf_nbuf_reserve(cdf_nbuf_t buf, cdf_size_t size)
  484. {
  485. __cdf_nbuf_reserve(buf, size);
  486. }
  487. /**
  488. * cdf_nbuf_peek_header() - return the data pointer & length of the header
  489. * @buf: Network nbuf
  490. * @addr: Data pointer
  491. * @len: Length of the data
  492. *
  493. * Return: none
  494. */
  495. static inline void
  496. cdf_nbuf_peek_header(cdf_nbuf_t buf, uint8_t **addr, uint32_t *len)
  497. {
  498. __cdf_nbuf_peek_header(buf, addr, len);
  499. }
  500. /* nbuf private context routines */
  501. /* nbuf queue routines */
  502. /**
  503. * cdf_nbuf_queue_init() - initialize buf queue
  504. * @head: Network buf queue head
  505. *
  506. * Return: none
  507. */
  508. static inline void cdf_nbuf_queue_init(cdf_nbuf_queue_t *head)
  509. {
  510. __cdf_nbuf_queue_init(head);
  511. }
  512. /**
  513. * cdf_nbuf_queue_add() - append a nbuf to the tail of the buf queue
  514. * @head: Network buf queue head
  515. * @buf: Network buf
  516. *
  517. * Return: none
  518. */
  519. static inline void cdf_nbuf_queue_add(cdf_nbuf_queue_t *head, cdf_nbuf_t buf)
  520. {
  521. __cdf_nbuf_queue_add(head, buf);
  522. }
  523. /**
  524. * cdf_nbuf_queue_insert_head() - insert nbuf at the head of queue
  525. * @head: Network buf queue head
  526. * @buf: Network buf
  527. *
  528. * Return: none
  529. */
  530. static inline void
  531. cdf_nbuf_queue_insert_head(cdf_nbuf_queue_t *head, cdf_nbuf_t buf)
  532. {
  533. __cdf_nbuf_queue_insert_head(head, buf);
  534. }
  535. /**
  536. * cdf_nbuf_queue_remove() - retrieve a buf from the head of the buf queue
  537. * @head: Network buf queue head
  538. *
  539. * Return: The head buf in the buf queue.
  540. */
  541. static inline cdf_nbuf_t cdf_nbuf_queue_remove(cdf_nbuf_queue_t *head)
  542. {
  543. return __cdf_nbuf_queue_remove(head);
  544. }
  545. /**
  546. * cdf_nbuf_queue_len() - get the length of the queue
  547. * @head: Network buf queue head
  548. *
  549. * Return: length of the queue
  550. */
  551. static inline uint32_t cdf_nbuf_queue_len(cdf_nbuf_queue_t *head)
  552. {
  553. return __cdf_nbuf_queue_len(head);
  554. }
  555. /**
  556. * cdf_nbuf_queue_next() - get the next guy/packet of the given buffer
  557. * @buf: Network buffer
  558. *
  559. * Return: next buffer/packet
  560. */
  561. static inline cdf_nbuf_t cdf_nbuf_queue_next(cdf_nbuf_t buf)
  562. {
  563. return __cdf_nbuf_queue_next(buf);
  564. }
  565. /**
  566. * @cdf_nbuf_is_queue_empty() - check if the buf queue is empty
  567. * @nbq: Network buf queue handle
  568. *
  569. * Return: true if queue is empty
  570. * false if queue is not emty
  571. */
  572. static inline bool cdf_nbuf_is_queue_empty(cdf_nbuf_queue_t *nbq)
  573. {
  574. return __cdf_nbuf_is_queue_empty(nbq);
  575. }
  576. /**
  577. * cdf_nbuf_next() - get the next packet in the linked list
  578. * @buf: Network buffer
  579. *
  580. * This function can be used when nbufs are directly linked into a list,
  581. * rather than using a separate network buffer queue object.
  582. *
  583. * Return: next network buffer in the linked list
  584. */
  585. static inline cdf_nbuf_t cdf_nbuf_next(cdf_nbuf_t buf)
  586. {
  587. return __cdf_nbuf_next(buf);
  588. }
  589. /**
  590. * cdf_nbuf_get_protocol() - return the protocol value of the skb
  591. * @skb: Pointer to network buffer
  592. *
  593. * Return: skb protocol
  594. */
  595. static inline uint16_t cdf_nbuf_get_protocol(struct sk_buff *skb)
  596. {
  597. return __cdf_nbuf_get_protocol(skb);
  598. }
  599. /**
  600. * cdf_nbuf_get_ip_summed() - return the ip checksum value of the skb
  601. * @skb: Pointer to network buffer
  602. *
  603. * Return: skb ip_summed
  604. */
  605. static inline uint8_t cdf_nbuf_get_ip_summed(struct sk_buff *skb)
  606. {
  607. return __cdf_nbuf_get_ip_summed(skb);
  608. }
  609. /**
  610. * cdf_nbuf_set_ip_summed() - sets the ip_summed value of the skb
  611. * @skb: Pointer to network buffer
  612. * @ip_summed: ip checksum
  613. *
  614. * Return: none
  615. */
  616. static inline void cdf_nbuf_set_ip_summed(struct sk_buff *skb, uint8_t ip_summed)
  617. {
  618. __cdf_nbuf_set_ip_summed(skb, ip_summed);
  619. }
  620. /**
  621. * cdf_nbuf_set_next() - add a packet to a linked list
  622. * @this_buf: Predecessor buffer
  623. * @next_buf: Successor buffer
  624. *
  625. * This function can be used to directly link nbufs, rather than using
  626. * a separate network buffer queue object.
  627. *
  628. * Return: none
  629. */
  630. static inline void cdf_nbuf_set_next(cdf_nbuf_t this_buf, cdf_nbuf_t next_buf)
  631. {
  632. __cdf_nbuf_set_next(this_buf, next_buf);
  633. }
  634. /* nbuf extension routines */
  635. /**
  636. * cdf_nbuf_set_next_ext() - link extension of this packet contained in a new
  637. * nbuf
  638. * @this_buf: predecessor buffer
  639. * @next_buf: successor buffer
  640. *
  641. * This function is used to link up many nbufs containing a single logical
  642. * packet - not a collection of packets. Do not use for linking the first
  643. * extension to the head
  644. *
  645. * Return: none
  646. */
  647. static inline void
  648. cdf_nbuf_set_next_ext(cdf_nbuf_t this_buf, cdf_nbuf_t next_buf)
  649. {
  650. __cdf_nbuf_set_next_ext(this_buf, next_buf);
  651. }
  652. /**
  653. * cdf_nbuf_next_ext() - get the next packet extension in the linked list
  654. * @buf: Network buffer
  655. *
  656. * Return: Next network buffer in the linked list
  657. */
  658. static inline cdf_nbuf_t cdf_nbuf_next_ext(cdf_nbuf_t buf)
  659. {
  660. return __cdf_nbuf_next_ext(buf);
  661. }
  662. /**
  663. * cdf_nbuf_append_ext_list() - link list of packet extensions to the head
  664. * segment
  665. * @head_buf: Network buf holding head segment (single)
  666. * @ext_list: Network buf list holding linked extensions to the head
  667. * @ext_len: Total length of all buffers in the extension list
  668. *
  669. * This function is used to link up a list of packet extensions (seg1, 2,
  670. * ...) to the nbuf holding the head segment (seg0)
  671. *
  672. * Return: none
  673. */
  674. static inline void
  675. cdf_nbuf_append_ext_list(cdf_nbuf_t head_buf, cdf_nbuf_t ext_list,
  676. cdf_size_t ext_len)
  677. {
  678. __cdf_nbuf_append_ext_list(head_buf, ext_list, ext_len);
  679. }
  680. /**
  681. * cdf_nbuf_get_tx_cksum() - gets the tx checksum offload demand
  682. * @buf: Network buffer
  683. *
  684. * Return: cdf_nbuf_tx_cksum_t checksum offload demand for the frame
  685. */
  686. static inline cdf_nbuf_tx_cksum_t cdf_nbuf_get_tx_cksum(cdf_nbuf_t buf)
  687. {
  688. return __cdf_nbuf_get_tx_cksum(buf);
  689. }
  690. /**
  691. * cdf_nbuf_set_rx_cksum() - drivers that support hw checksumming use this to
  692. * indicate checksum info to the stack.
  693. * @buf: Network buffer
  694. * @cksum: Checksum
  695. *
  696. * Return: none
  697. */
  698. static inline void
  699. cdf_nbuf_set_rx_cksum(cdf_nbuf_t buf, cdf_nbuf_rx_cksum_t *cksum)
  700. {
  701. __cdf_nbuf_set_rx_cksum(buf, cksum);
  702. }
  703. /**
  704. * cdf_nbuf_get_tid() - this function extracts the TID value from nbuf
  705. * @buf: Network buffer
  706. *
  707. * Return: TID value
  708. */
  709. static inline uint8_t cdf_nbuf_get_tid(cdf_nbuf_t buf)
  710. {
  711. return __cdf_nbuf_get_tid(buf);
  712. }
  713. /**
  714. * cdf_nbuf_set_tid() - this function sets the TID value in nbuf
  715. * @buf: Network buffer
  716. * @tid: TID value
  717. *
  718. * Return: none
  719. */
  720. static inline void cdf_nbuf_set_tid(cdf_nbuf_t buf, uint8_t tid)
  721. {
  722. __cdf_nbuf_set_tid(buf, tid);
  723. }
  724. /**
  725. * cdf_nbuf_get_exemption_type() - this function extracts the exemption type
  726. * from nbuf
  727. * @buf: Network buffer
  728. *
  729. * Return: Exemption type
  730. */
  731. static inline uint8_t cdf_nbuf_get_exemption_type(cdf_nbuf_t buf)
  732. {
  733. return __cdf_nbuf_get_exemption_type(buf);
  734. }
  735. /**
  736. * cdf_nbuf_set_protocol() - this function peeks data into the buffer at given
  737. * offset
  738. * @buf: Network buffer
  739. * @proto: Protocol
  740. *
  741. * Return: none
  742. */
  743. static inline void cdf_nbuf_set_protocol(cdf_nbuf_t buf, uint16_t proto)
  744. {
  745. __cdf_nbuf_set_protocol(buf, proto);
  746. }
  747. /**
  748. * cdf_nbuf_trace_get_proto_type() - this function return packet proto type
  749. * @buf: Network buffer
  750. *
  751. * Return: Packet protocol type
  752. */
  753. static inline uint8_t cdf_nbuf_trace_get_proto_type(cdf_nbuf_t buf)
  754. {
  755. return __cdf_nbuf_trace_get_proto_type(buf);
  756. }
  757. #ifdef QCA_PKT_PROTO_TRACE
  758. /**
  759. * cdf_nbuf_trace_set_proto_type() - this function updates packet proto type
  760. * @buf: Network buffer
  761. * @proto_type: Protocol type
  762. *
  763. * Return: none
  764. */
  765. static inline void
  766. cdf_nbuf_trace_set_proto_type(cdf_nbuf_t buf, uint8_t proto_type)
  767. {
  768. __cdf_nbuf_trace_set_proto_type(buf, proto_type);
  769. }
  770. #else
  771. #define cdf_nbuf_trace_set_proto_type(buf, proto_type) /*NO OP*/
  772. #endif
  773. /**
  774. * cdf_nbuf_reg_trace_cb() - this function registers protocol trace callback
  775. * @cb_func_ptr: Callback pointer
  776. *
  777. * Return: none
  778. */
  779. static inline void cdf_nbuf_reg_trace_cb(cdf_nbuf_trace_update_t cb_func_ptr)
  780. {
  781. __cdf_nbuf_reg_trace_cb(cb_func_ptr);
  782. }
  783. /**
  784. * cdf_nbuf_trace_update() - this function updates protocol event
  785. * @buf: Network buffer
  786. * @event_string: Event string pointer
  787. *
  788. * Return: none
  789. */
  790. static inline void cdf_nbuf_trace_update(cdf_nbuf_t buf, char *event_string)
  791. {
  792. __cdf_nbuf_trace_update(buf, event_string);
  793. }
  794. /**
  795. * cdf_nbuf_set_tx_parallel_dnload_frm() - set tx parallel download
  796. * @buf: Network buffer
  797. * @candi: Candidate of parallel download frame
  798. *
  799. * This function stores a flag specifying this TX frame is suitable for
  800. * downloading though a 2nd TX data pipe that is used for short frames for
  801. * protocols that can accept out-of-order delivery.
  802. *
  803. * Return: none
  804. */
  805. static inline void
  806. cdf_nbuf_set_tx_parallel_dnload_frm(cdf_nbuf_t buf, uint8_t candi)
  807. {
  808. __cdf_nbuf_set_tx_htt2_frm(buf, candi);
  809. }
  810. /**
  811. * cdf_nbuf_get_tx_parallel_dnload_frm() - get tx parallel download
  812. * @buf: Network buffer
  813. *
  814. * This function return whether this TX frame is allow to download though a 2nd
  815. * TX data pipe or not.
  816. *
  817. * Return: none
  818. */
  819. static inline uint8_t cdf_nbuf_get_tx_parallel_dnload_frm(cdf_nbuf_t buf)
  820. {
  821. return __cdf_nbuf_get_tx_htt2_frm(buf);
  822. }
  823. /**
  824. * cdf_invalidate_range() - invalidate the virtual address range specified by
  825. * start and end addresses.
  826. * Note: This does not write back the cache entries.
  827. *
  828. * Return: none
  829. */
  830. static inline void cdf_invalidate_range(void *start, void *end)
  831. {
  832. #ifdef MSM_PLATFORM
  833. dmac_inv_range(start, end);
  834. #else
  835. /* TODO figure out how to invalidate cache on x86 and other
  836. non-MSM platform */
  837. CDF_TRACE(CDF_MODULE_ID_CDF, CDF_TRACE_LEVEL_FATAL,
  838. "Cache invalidate not yet implemneted for non-MSM platform");
  839. return;
  840. #endif
  841. }
  842. #if defined(FEATURE_TSO)
  843. /**
  844. * cdf_nbuf_dec_num_frags() - decrement the number of fragments
  845. * @buf: Network buffer
  846. *
  847. * Return: Number of fragments
  848. */
  849. static inline int cdf_nbuf_dec_num_frags(cdf_nbuf_t buf)
  850. {
  851. return __cdf_nbuf_dec_num_frags(buf);
  852. }
  853. /**
  854. * cdf_nbuf_is_tso() - is the network buffer a jumbo packet?
  855. * @buf: Network buffer
  856. *
  857. * Return: 1 - this is a jumbo packet 0 - not a jumbo packet
  858. */
  859. static inline uint8_t cdf_nbuf_is_tso(cdf_nbuf_t nbuf)
  860. {
  861. return __cdf_nbuf_is_tso(nbuf);
  862. }
  863. /**
  864. * cdf_nbuf_get_tso_info() - function to divide a jumbo TSO
  865. * network buffer into segments
  866. * @nbuf: network buffer to be segmented
  867. * @tso_info: This is the output. The information about the
  868. * TSO segments will be populated within this.
  869. *
  870. * This function fragments a TCP jumbo packet into smaller
  871. * segments to be transmitted by the driver. It chains the TSO
  872. * segments created into a list.
  873. *
  874. * Return: number of TSO segments
  875. */
  876. static inline uint32_t cdf_nbuf_get_tso_info(cdf_device_t osdev,
  877. cdf_nbuf_t nbuf, struct cdf_tso_info_t *tso_info)
  878. {
  879. return __cdf_nbuf_get_tso_info(osdev, nbuf, tso_info);
  880. }
  881. /**
  882. * cdf_nbuf_get_tso_num_seg() - function to calculate the number
  883. * of TCP segments within the TSO jumbo packet
  884. * @nbuf: TSO jumbo network buffer to be segmented
  885. *
  886. * This function calculates the number of TCP segments that the
  887. network buffer can be divided into.
  888. *
  889. * Return: number of TCP segments
  890. */
  891. static inline uint32_t cdf_nbuf_get_tso_num_seg(cdf_nbuf_t nbuf)
  892. {
  893. return __cdf_nbuf_get_tso_num_seg(nbuf);
  894. }
  895. /**
  896. * cdf_nbuf_inc_users() - function to increment the number of
  897. * users referencing this network buffer
  898. *
  899. * @nbuf: network buffer
  900. *
  901. * This function increments the number of users referencing this
  902. * network buffer
  903. *
  904. * Return: the network buffer
  905. */
  906. static inline cdf_nbuf_t cdf_nbuf_inc_users(cdf_nbuf_t nbuf)
  907. {
  908. return __cdf_nbuf_inc_users(nbuf);
  909. }
  910. #endif /*TSO*/
  911. /**
  912. * cdf_nbuf_data_attr_get() - Get data_attr field from cvg_nbuf_cb
  913. *
  914. * @nbuf: Network buffer (skb on linux)
  915. *
  916. * This function returns the values of data_attr field
  917. * in struct cvg_nbuf_cb{}, to which skb->cb is typecast.
  918. * This value is actually the value programmed in CE descriptor.
  919. *
  920. * Return: Value of data_attr
  921. */
  922. static inline
  923. uint32_t cdf_nbuf_data_attr_get(cdf_nbuf_t buf)
  924. {
  925. return __cdf_nbuf_data_attr_get(buf);
  926. }
  927. /**
  928. * cdf_nbuf_data_attr_set() - Sets data_attr field in cvg_nbuf_cb
  929. *
  930. * @nbuf: Network buffer (skb on linux)
  931. * @data_attr: Value to be stored cvg_nbuf_cb->data_attr
  932. *
  933. * This function stores the value to be programmed in CE
  934. * descriptor as part skb->cb which is typecast to struct cvg_nbuf_cb{}
  935. *
  936. * Return: void
  937. */
  938. static inline
  939. void cdf_nbuf_data_attr_set(cdf_nbuf_t buf, uint32_t data_attr)
  940. {
  941. __cdf_nbuf_data_attr_set(buf, data_attr);
  942. }
  943. /**
  944. * cdf_nbuf_tx_info_get() - Parse skb and get Tx metadata
  945. *
  946. * @nbuf: Network buffer (skb on linux)
  947. *
  948. * This function parses the payload to figure out relevant
  949. * Tx meta-data e.g. whether to enable tx_classify bit
  950. * in CE.
  951. *
  952. * Return: void
  953. */
  954. #define cdf_nbuf_tx_info_get __cdf_nbuf_tx_info_get
  955. void cdf_nbuf_set_state(cdf_nbuf_t nbuf, uint8_t current_state);
  956. void cdf_nbuf_tx_desc_count_display(void);
  957. void cdf_nbuf_tx_desc_count_clear(void);
  958. #endif