ipa_i.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _IPA_I_H_
  13. #define _IPA_I_H_
  14. #include <linux/bitops.h>
  15. #include <linux/cdev.h>
  16. #include <linux/export.h>
  17. #include <linux/list.h>
  18. #include <linux/mutex.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/slab.h>
  21. #include <mach/ipa.h>
  22. #include <mach/sps.h>
  23. #include "ipa_hw_defs.h"
  24. #include "ipa_ram_mmap.h"
  25. #include "ipa_reg.h"
  26. #define DRV_NAME "ipa"
  27. #define IPA_COOKIE 0xfacefeed
  28. #define IPA_RT_RULE_COOKIE 0xfacefeef
  29. #define IPA_RT_TBL_COOKIE 0xfacefef0
  30. #define IPA_FLT_COOKIE 0xfacefef1
  31. #define IPA_HDR_COOKIE 0xfacefef2
  32. #define IPA_PROC_HDR_COOKIE 0xfacefef3
  33. #define IPA_NUM_PIPES 0x14
  34. #define IPA_SYS_DESC_FIFO_SZ 0x800
  35. #define IPA_SYS_TX_DATA_DESC_FIFO_SZ 0x1000
  36. #ifdef IPA_DEBUG
  37. #define IPADBG(fmt, args...) \
  38. pr_err(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args)
  39. /* pr_debug(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args) */
  40. #else
  41. #define IPADBG(fmt, args...)
  42. #endif
  43. #define WLAN_AMPDU_TX_EP 15
  44. #define WLAN_PROD_TX_EP 19
  45. #define MAX_NUM_EXCP 8
  46. #define MAX_NUM_IMM_CMD 17
  47. #define IPA_STATS
  48. #ifdef IPA_STATS
  49. #define IPA_STATS_INC_CNT(val) do { \
  50. ++val; \
  51. } while (0)
  52. #define IPA_STATS_INC_CNT_SAFE(val) do { \
  53. atomic_inc(&val); \
  54. } while (0)
  55. #define IPA_STATS_EXCP_CNT(flags, base) do { \
  56. int i; \
  57. for (i = 0; i < MAX_NUM_EXCP; i++) \
  58. if (flags & BIT(i)) \
  59. ++base[i]; \
  60. } while (0)
  61. #define IPA_STATS_INC_TX_CNT(ep, sw, hw) do { \
  62. if (ep == WLAN_AMPDU_TX_EP) \
  63. ++hw; \
  64. else \
  65. ++sw; \
  66. } while (0)
  67. #define IPA_STATS_INC_IC_CNT(num, base, stat_base) do { \
  68. int i; \
  69. for (i = 0; i < num; i++) \
  70. ++stat_base[base[i].opcode]; \
  71. } while (0)
  72. #define IPA_STATS_INC_BRIDGE_CNT(type, dir, base) do { \
  73. ++base[type][dir]; \
  74. } while (0)
  75. #else
  76. #define IPA_STATS_INC_CNT(x) do { } while (0)
  77. #define IPA_STATS_INC_CNT_SAFE(x) do { } while (0)
  78. #define IPA_STATS_EXCP_CNT(flags, base) do { } while (0)
  79. #define IPA_STATS_INC_TX_CNT(ep, sw, hw) do { } while (0)
  80. #define IPA_STATS_INC_IC_CNT(num, base, stat_base) do { } while (0)
  81. #define IPA_STATS_INC_BRIDGE_CNT(type, dir, base) do { } while (0)
  82. #endif
  83. #define IPAERR(fmt, args...) \
  84. pr_err(DRV_NAME " %s:%d " fmt, __func__, __LINE__, ## args)
  85. #define IPA_TOS_EQ BIT(0)
  86. #define IPA_PROTOCOL_EQ BIT(1)
  87. #define IPA_OFFSET_MEQ32_0 BIT(2)
  88. #define IPA_OFFSET_MEQ32_1 BIT(3)
  89. #define IPA_IHL_OFFSET_RANGE16_0 BIT(4)
  90. #define IPA_IHL_OFFSET_RANGE16_1 BIT(5)
  91. #define IPA_IHL_OFFSET_EQ_16 BIT(6)
  92. #define IPA_IHL_OFFSET_EQ_32 BIT(7)
  93. #define IPA_IHL_OFFSET_MEQ32_0 BIT(8)
  94. #define IPA_OFFSET_MEQ128_0 BIT(9)
  95. #define IPA_OFFSET_MEQ128_1 BIT(10)
  96. #define IPA_TC_EQ BIT(11)
  97. #define IPA_FL_EQ BIT(12)
  98. #define IPA_IHL_OFFSET_MEQ32_1 BIT(13)
  99. #define IPA_METADATA_COMPARE BIT(14)
  100. #define IPA_IPV4_IS_FRAG BIT(15)
  101. #define IPA_HDR_BIN0 0
  102. #define IPA_HDR_BIN1 1
  103. #define IPA_HDR_BIN2 2
  104. #define IPA_HDR_BIN3 3
  105. #define IPA_HDR_BIN_MAX 4
  106. #define IPA_EVENT_THRESHOLD 0x10
  107. #define IPA_RX_POOL_CEIL 32
  108. #define IPA_RX_SKB_SIZE 2048
  109. #define IPA_DFLT_HDR_NAME "ipa_excp_hdr"
  110. #define IPA_INVALID_L4_PROTOCOL 0xFF
  111. #define IPA_CLIENT_IS_PROD(x) (x >= IPA_CLIENT_PROD && x < IPA_CLIENT_CONS)
  112. #define IPA_CLIENT_IS_CONS(x) (x >= IPA_CLIENT_CONS && x < IPA_CLIENT_MAX)
  113. #define IPA_SETFIELD(val, shift, mask) (((val) << (shift)) & (mask))
  114. #define IPA_HW_TABLE_ALIGNMENT(start_ofst) \
  115. (((start_ofst) + 127) & ~127)
  116. #define IPA_RT_FLT_HW_RULE_BUF_SIZE (256)
  117. /**
  118. * enum ipa_sys_pipe - 5 A5-IPA pipes
  119. *
  120. * 5 A5-IPA pipes (all system mode)
  121. */
  122. enum ipa_sys_pipe {
  123. IPA_A5_UNUSED,
  124. IPA_A5_CMD,
  125. IPA_A5_LAN_WAN_OUT,
  126. IPA_A5_LAN_WAN_IN,
  127. IPA_A5_WLAN_AMPDU_OUT,
  128. IPA_A5_SYS_MAX
  129. };
  130. /**
  131. * enum ipa_operating_mode - IPA operating mode
  132. *
  133. * IPA operating mode
  134. */
  135. enum ipa_operating_mode {
  136. IPA_MODE_USB_DONGLE,
  137. IPA_MODE_MSM,
  138. IPA_MODE_EXT_APPS,
  139. IPA_MODE_MOBILE_AP_WAN,
  140. IPA_MODE_MOBILE_AP_WLAN,
  141. IPA_MODE_MOBILE_AP_ETH,
  142. IPA_MODE_MAX
  143. };
  144. /**
  145. * struct ipa_mem_buffer - IPA memory buffer
  146. * @base: base
  147. * @phys_base: physical base address
  148. * @size: size of memory buffer
  149. */
  150. struct ipa_mem_buffer {
  151. void *base;
  152. dma_addr_t phys_base;
  153. u32 size;
  154. };
  155. /**
  156. * struct ipa_flt_entry - IPA filtering table entry
  157. * @link: entry's link in global filtering enrties list
  158. * @rule: filter rule
  159. * @cookie: cookie used for validity check
  160. * @tbl: filter table
  161. * @rt_tbl: routing table
  162. * @hw_len: entry's size
  163. */
  164. struct ipa_flt_entry {
  165. struct list_head link;
  166. u32 cookie;
  167. struct ipa_flt_rule rule;
  168. struct ipa_flt_tbl *tbl;
  169. struct ipa_rt_tbl *rt_tbl;
  170. u32 hw_len;
  171. };
  172. /**
  173. * struct ipa_rt_tbl - IPA routing table
  174. * @link: table's link in global routing tables list
  175. * @head_rt_rule_list: head of routing rules list
  176. * @name: routing table name
  177. * @idx: routing table index
  178. * @rule_cnt: number of rules in routing table
  179. * @ref_cnt: reference counter of raouting table
  180. * @set: collection of routing tables
  181. * @cookie: cookie used for validity check
  182. * @in_sys: flag indicating if the table is located in system memory
  183. * @sz: the size of the routing table
  184. * @curr_mem: current routing tables block in sys memory
  185. * @prev_mem: previous routing table block in sys memory
  186. */
  187. struct ipa_rt_tbl {
  188. struct list_head link;
  189. u32 cookie;
  190. struct list_head head_rt_rule_list;
  191. char name[IPA_RESOURCE_NAME_MAX];
  192. u32 idx;
  193. u32 rule_cnt;
  194. u32 ref_cnt;
  195. struct ipa_rt_tbl_set *set;
  196. bool in_sys;
  197. u32 sz;
  198. struct ipa_mem_buffer curr_mem;
  199. struct ipa_mem_buffer prev_mem;
  200. };
  201. /**
  202. * struct ipa_hdr_entry - IPA header table entry
  203. * @link: entry's link in global header table entries list
  204. * @hdr: the header
  205. * @hdr_len: header length
  206. * @name: name of header table entry
  207. * @is_partial: flag indicating if header table entry is partial
  208. * @offset_entry: entry's offset
  209. * @cookie: cookie used for validity check
  210. * @ref_cnt: reference counter of raouting table
  211. * @user_deleted: is the header deleted by the user?
  212. */
  213. struct ipa_hdr_entry {
  214. struct list_head link;
  215. u32 cookie;
  216. u8 hdr[IPA_HDR_MAX_SIZE];
  217. u32 hdr_len;
  218. char name[IPA_RESOURCE_NAME_MAX];
  219. u8 is_partial;
  220. struct ipa_hdr_offset_entry *offset_entry;
  221. u32 ref_cnt;
  222. bool user_deleted;
  223. };
  224. /**
  225. * struct ipa_hdr_offset_entry - IPA header offset entry
  226. * @link: entry's link in global header offset entries list
  227. * @offset: the offset
  228. * @bin: bin
  229. */
  230. struct ipa_hdr_offset_entry {
  231. struct list_head link;
  232. u32 offset;
  233. u32 bin;
  234. };
  235. /**
  236. * struct ipa_hdr_tbl - IPA header table
  237. * @head_hdr_entry_list: header entries list
  238. * @head_offset_list: header offset list
  239. * @head_free_offset_list: header free offset list
  240. * @hdr_cnt: number of headers
  241. * @end: the last header index
  242. */
  243. struct ipa_hdr_tbl {
  244. struct list_head head_hdr_entry_list;
  245. struct list_head head_offset_list[IPA_HDR_BIN_MAX];
  246. struct list_head head_free_offset_list[IPA_HDR_BIN_MAX];
  247. u32 hdr_cnt;
  248. u32 end;
  249. };
  250. /**
  251. * struct ipa_flt_tbl - IPA filter table
  252. * @head_flt_rule_list: filter rules list
  253. * @rule_cnt: number of filter rules
  254. * @in_sys: flag indicating if filter table is located in system memory
  255. * @sz: the size of the filter table
  256. * @end: the last header index
  257. * @curr_mem: current filter tables block in sys memory
  258. * @prev_mem: previous filter table block in sys memory
  259. */
  260. struct ipa_flt_tbl {
  261. struct list_head head_flt_rule_list;
  262. u32 rule_cnt;
  263. bool in_sys;
  264. u32 sz;
  265. struct ipa_mem_buffer curr_mem;
  266. struct ipa_mem_buffer prev_mem;
  267. };
  268. /**
  269. * struct ipa_rt_entry - IPA routing table entry
  270. * @link: entry's link in global routing table entries list
  271. * @rule: routing rule
  272. * @cookie: cookie used for validity check
  273. * @tbl: routing table
  274. * @hdr: header table
  275. * @hw_len: the length of the table
  276. */
  277. struct ipa_rt_entry {
  278. struct list_head link;
  279. u32 cookie;
  280. struct ipa_rt_rule rule;
  281. struct ipa_rt_tbl *tbl;
  282. struct ipa_hdr_entry *hdr;
  283. u32 hw_len;
  284. };
  285. /**
  286. * struct ipa_rt_tbl_set - collection of routing tables
  287. * @head_rt_tbl_list: collection of routing tables
  288. * @tbl_cnt: number of routing tables
  289. */
  290. struct ipa_rt_tbl_set {
  291. struct list_head head_rt_tbl_list;
  292. u32 tbl_cnt;
  293. };
  294. /**
  295. * struct ipa_tree_node - handle database entry
  296. * @node: RB node
  297. * @hdl: handle
  298. */
  299. struct ipa_tree_node {
  300. struct rb_node node;
  301. u32 hdl;
  302. };
  303. /**
  304. * struct ipa_ep_context - IPA end point context
  305. * @valid: flag indicating id EP context is valid
  306. * @client: EP client type
  307. * @ep_hdl: EP's client SPS handle
  308. * @cfg: EP cionfiguration
  309. * @dst_pipe_index: destination pipe index
  310. * @rt_tbl_idx: routing table index
  311. * @connect: SPS connect
  312. * @priv: user provided information which will forwarded once the user is
  313. * notified for new data avail
  314. * @client_notify: user provided CB for EP events notification, the event is
  315. * data revived.
  316. * @desc_fifo_in_pipe_mem: flag indicating if descriptors FIFO uses pipe memory
  317. * @data_fifo_in_pipe_mem: flag indicating if data FIFO uses pipe memory
  318. * @desc_fifo_pipe_mem_ofst: descriptors FIFO pipe memory offset
  319. * @data_fifo_pipe_mem_ofst: data FIFO pipe memory offset
  320. * @desc_fifo_client_allocated: if descriptors FIFO was allocated by a client
  321. * @data_fifo_client_allocated: if data FIFO was allocated by a client
  322. * @suspended: valid for B2B pipes, whether IPA EP is suspended
  323. */
  324. struct ipa_ep_context {
  325. int valid;
  326. enum ipa_client_type client;
  327. struct sps_pipe *ep_hdl;
  328. struct ipa_ep_cfg cfg;
  329. struct ipa_ep_cfg_holb holb;
  330. u32 dst_pipe_index;
  331. u32 rt_tbl_idx;
  332. struct sps_connect connect;
  333. void *priv;
  334. void (*client_notify)(void *priv, enum ipa_dp_evt_type evt,
  335. unsigned long data);
  336. bool desc_fifo_in_pipe_mem;
  337. bool data_fifo_in_pipe_mem;
  338. u32 desc_fifo_pipe_mem_ofst;
  339. u32 data_fifo_pipe_mem_ofst;
  340. bool desc_fifo_client_allocated;
  341. bool data_fifo_client_allocated;
  342. bool suspended;
  343. };
  344. /**
  345. * struct ipa_sys_context - IPA endpoint context for system to BAM pipes
  346. * @head_desc_list: header descriptors list
  347. * @len: the size of the above list
  348. * @spinlock: protects the list and its size
  349. * @event: used to request CALLBACK mode from SPS driver
  350. * @ep: IPA EP context
  351. *
  352. * IPA context specific to the system-bam pipes a.k.a LAN IN/OUT and WAN
  353. */
  354. struct ipa_sys_context {
  355. struct list_head head_desc_list;
  356. u32 len;
  357. spinlock_t spinlock;
  358. struct sps_register_event event;
  359. struct ipa_ep_context *ep;
  360. atomic_t curr_polling_state;
  361. struct delayed_work switch_to_intr_work;
  362. };
  363. /**
  364. * enum ipa_desc_type - IPA decriptors type
  365. *
  366. * IPA decriptors type, IPA supports DD and ICD but no CD
  367. */
  368. enum ipa_desc_type {
  369. IPA_DATA_DESC,
  370. IPA_DATA_DESC_SKB,
  371. IPA_IMM_CMD_DESC
  372. };
  373. /**
  374. * struct ipa_tx_pkt_wrapper - IPA Tx packet wrapper
  375. * @type: specify if this packet is for the skb or immediate command
  376. * @mem: memory buffer used by this Tx packet
  377. * @work: work struct for current Tx packet
  378. * @link: linked to the wrappers on that pipe
  379. * @callback: IPA client provided callback
  380. * @user1: cookie1 for above callback
  381. * @user2: cookie2 for above callback
  382. * @sys: corresponding IPA sys context
  383. * @mult: valid only for first of a "multiple" transfer,
  384. * holds info for the "sps_transfer" buffer
  385. * @cnt: 1 for single transfers,
  386. * >1 and <0xFFFF for first of a "multiple" tranfer,
  387. * 0xFFFF for last desc, 0 for rest of "multiple' transfer
  388. * @bounce: va of bounce buffer
  389. *
  390. * This struct can wrap both data packet and immediate command packet.
  391. */
  392. struct ipa_tx_pkt_wrapper {
  393. enum ipa_desc_type type;
  394. struct ipa_mem_buffer mem;
  395. struct work_struct work;
  396. struct list_head link;
  397. void (*callback)(void *user1, void *user2);
  398. void *user1;
  399. void *user2;
  400. struct ipa_sys_context *sys;
  401. struct ipa_mem_buffer mult;
  402. u32 cnt;
  403. void *bounce;
  404. };
  405. /**
  406. * struct ipa_desc - IPA descriptor
  407. * @type: skb or immediate command or plain old data
  408. * @pyld: points to skb
  409. * or kmalloc'ed immediate command parameters/plain old data
  410. * @len: length of the pyld
  411. * @opcode: for immediate commands
  412. * @callback: IPA client provided completion callback
  413. * @user1: cookie1 for above callback
  414. * @user2: cookie2 for above callback
  415. * @xfer_done: completion object for sync completion
  416. */
  417. struct ipa_desc {
  418. enum ipa_desc_type type;
  419. void *pyld;
  420. u16 len;
  421. u16 opcode;
  422. void (*callback)(void *user1, void *user2);
  423. void *user1;
  424. void *user2;
  425. struct completion xfer_done;
  426. };
  427. /**
  428. * struct ipa_rx_pkt_wrapper - IPA Rx packet wrapper
  429. * @skb: skb
  430. * @dma_address: DMA address of this Rx packet
  431. * @link: linked to the Rx packets on that pipe
  432. * @len: how many bytes are copied into skb's flat buffer
  433. */
  434. struct ipa_rx_pkt_wrapper {
  435. struct sk_buff *skb;
  436. dma_addr_t dma_address;
  437. struct list_head link;
  438. u32 len;
  439. };
  440. /**
  441. * struct ipa_nat_mem - IPA NAT memory description
  442. * @class: pointer to the struct class
  443. * @dev: the dev_t of the device
  444. * @cdev: cdev of the device
  445. * @dev_num: device number
  446. * @vaddr: virtual address
  447. * @dma_handle: DMA handle
  448. * @size: NAT memory size
  449. * @is_mapped: flag indicating if NAT memory is mapped
  450. * @is_sys_mem: flag indicating if NAT memory is sys memory
  451. * @is_dev_init: flag indicating if NAT device is initialized
  452. * @lock: NAT memory mutex
  453. * @nat_base_address: nat table virutal address
  454. * @ipv4_rules_addr: base nat table address
  455. * @ipv4_expansion_rules_addr: expansion table address
  456. * @index_table_addr: index table address
  457. * @index_table_expansion_addr: index expansion table address
  458. * @size_base_tables: base table size
  459. * @size_expansion_tables: expansion table size
  460. * @public_ip_addr: ip address of nat table
  461. */
  462. struct ipa_nat_mem {
  463. struct class *class;
  464. struct device *dev;
  465. struct cdev cdev;
  466. dev_t dev_num;
  467. void *vaddr;
  468. dma_addr_t dma_handle;
  469. size_t size;
  470. bool is_mapped;
  471. bool is_sys_mem;
  472. bool is_dev_init;
  473. struct mutex lock;
  474. void *nat_base_address;
  475. char *ipv4_rules_addr;
  476. char *ipv4_expansion_rules_addr;
  477. char *index_table_addr;
  478. char *index_table_expansion_addr;
  479. u32 size_base_tables;
  480. u32 size_expansion_tables;
  481. u32 public_ip_addr;
  482. };
  483. /**
  484. * enum ipa_hw_type - IPA hardware version type
  485. * @IPA_HW_None: IPA hardware version not defined
  486. * @IPA_HW_v1_0: IPA hardware version 1.0, corresponding to ELAN 1.0
  487. * @IPA_HW_v1_1: IPA hardware version 1.1, corresponding to ELAN 2.0
  488. * @IPA_HW_v2_0: IPA hardware version 2.0
  489. */
  490. enum ipa_hw_type {
  491. IPA_HW_None = 0,
  492. IPA_HW_v1_0 = 1,
  493. IPA_HW_v1_1 = 2,
  494. IPA_HW_v2_0 = 3
  495. };
  496. /**
  497. * enum ipa_hw_mode - IPA hardware mode
  498. * @IPA_HW_Normal: Regular IPA hardware
  499. * @IPA_HW_Virtual: IPA hardware supporting virtual memory allocation
  500. * @IPA_HW_PCIE: IPA hardware supporting memory allocation over PCIE Bridge
  501. */
  502. enum ipa_hw_mode {
  503. IPA_HW_MODE_NORMAL = 0,
  504. IPA_HW_MODE_VIRTUAL = 1,
  505. IPA_HW_MODE_PCIE = 2
  506. };
  507. struct ipa_stats {
  508. u32 imm_cmds[MAX_NUM_IMM_CMD];
  509. u32 tx_sw_pkts;
  510. u32 tx_hw_pkts;
  511. u32 rx_pkts;
  512. u32 rx_excp_pkts[MAX_NUM_EXCP];
  513. u32 bridged_pkts[IPA_BRIDGE_TYPE_MAX][IPA_BRIDGE_DIR_MAX];
  514. u32 rx_repl_repost;
  515. u32 x_intr_repost;
  516. u32 x_intr_repost_tx;
  517. u32 rx_q_len;
  518. u32 msg_w[IPA_EVENT_MAX];
  519. u32 msg_r[IPA_EVENT_MAX];
  520. u32 a2_power_on_reqs_in;
  521. u32 a2_power_on_reqs_out;
  522. u32 a2_power_off_reqs_in;
  523. u32 a2_power_off_reqs_out;
  524. u32 a2_power_modem_acks;
  525. u32 a2_power_apps_acks;
  526. };
  527. /**
  528. * struct ipa_context - IPA context
  529. * @class: pointer to the struct class
  530. * @dev_num: device number
  531. * @dev: the dev_t of the device
  532. * @cdev: cdev of the device
  533. * @bam_handle: IPA driver's BAM handle
  534. * @ep: list of all end points
  535. * @flt_tbl: list of all IPA filter tables
  536. * @mode: IPA operating mode
  537. * @mmio: iomem
  538. * @ipa_wrapper_base: IPA wrapper base address
  539. * @glob_flt_tbl: global filter table
  540. * @hdr_tbl: IPA header table
  541. * @rt_tbl_set: list of routing tables each of which is a list of rules
  542. * @reap_rt_tbl_set: list of sys mem routing tables waiting to be reaped
  543. * @flt_rule_cache: filter rule cache
  544. * @rt_rule_cache: routing rule cache
  545. * @hdr_cache: header cache
  546. * @hdr_offset_cache: header offset cache
  547. * @rt_tbl_cache: routing table cache
  548. * @tx_pkt_wrapper_cache: Tx packets cache
  549. * @rx_pkt_wrapper_cache: Rx packets cache
  550. * @tree_node_cache: tree nodes cache
  551. * @rt_idx_bitmap: routing table index bitmap
  552. * @lock: this does NOT protect the linked lists within ipa_sys_context
  553. * @sys: IPA sys context for system-bam pipes
  554. * @rx_wq: Rx packets work queue
  555. * @tx_wq: Tx packets work queue
  556. * @smem_sz: shared memory size
  557. * @hdr_hdl_tree: header handles tree
  558. * @rt_rule_hdl_tree: routing rule handles tree
  559. * @rt_tbl_hdl_tree: routing table handles tree
  560. * @flt_rule_hdl_tree: filtering rule handles tree
  561. * @nat_mem: NAT memory
  562. * @excp_hdr_hdl: exception header handle
  563. * @dflt_v4_rt_rule_hdl: default v4 routing rule handle
  564. * @dflt_v6_rt_rule_hdl: default v6 routing rule handle
  565. * @polling_mode: 1 - pure polling mode; 0 - interrupt+polling mode
  566. * @aggregation_type: aggregation type used on USB client endpoint
  567. * @aggregation_byte_limit: aggregation byte limit used on USB client endpoint
  568. * @aggregation_time_limit: aggregation time limit used on USB client endpoint
  569. * @curr_polling_state: current polling state
  570. * @poll_work: polling work
  571. * @hdr_tbl_lcl: where hdr tbl resides 1-local, 0-system
  572. * @hdr_mem: header memory
  573. * @ip4_rt_tbl_lcl: where ip4 rt tables reside 1-local; 0-system
  574. * @ip6_rt_tbl_lcl: where ip6 rt tables reside 1-local; 0-system
  575. * @ip4_flt_tbl_lcl: where ip4 flt tables reside 1-local; 0-system
  576. * @ip6_flt_tbl_lcl: where ip6 flt tables reside 1-local; 0-system
  577. * @empty_rt_tbl_mem: empty routing tables memory
  578. * @pipe_mem_pool: pipe memory pool
  579. * @dma_pool: special purpose DMA pool
  580. * @ipa_hw_type: type of IPA HW type (e.g. IPA 1.0, IPA 1.1 etc')
  581. * @ipa_hw_mode: mode of IPA HW mode (e.g. Normal, Virtual or over PCIe)
  582. *
  583. * IPA context - holds all relevant info about IPA driver and its state
  584. */
  585. struct ipa_context {
  586. struct class *class;
  587. dev_t dev_num;
  588. struct device *dev;
  589. struct cdev cdev;
  590. u32 bam_handle;
  591. struct ipa_ep_context ep[IPA_NUM_PIPES];
  592. struct ipa_flt_tbl flt_tbl[IPA_NUM_PIPES][IPA_IP_MAX];
  593. enum ipa_operating_mode mode;
  594. void __iomem *mmio;
  595. u32 ipa_wrapper_base;
  596. struct ipa_flt_tbl glob_flt_tbl[IPA_IP_MAX];
  597. struct ipa_hdr_tbl hdr_tbl;
  598. struct ipa_rt_tbl_set rt_tbl_set[IPA_IP_MAX];
  599. struct ipa_rt_tbl_set reap_rt_tbl_set[IPA_IP_MAX];
  600. struct kmem_cache *flt_rule_cache;
  601. struct kmem_cache *rt_rule_cache;
  602. struct kmem_cache *hdr_cache;
  603. struct kmem_cache *hdr_offset_cache;
  604. struct kmem_cache *rt_tbl_cache;
  605. struct kmem_cache *tx_pkt_wrapper_cache;
  606. struct kmem_cache *rx_pkt_wrapper_cache;
  607. struct kmem_cache *tree_node_cache;
  608. unsigned long rt_idx_bitmap[IPA_IP_MAX];
  609. struct mutex lock;
  610. struct ipa_sys_context sys[IPA_A5_SYS_MAX];
  611. struct workqueue_struct *rx_wq;
  612. struct workqueue_struct *tx_wq;
  613. u16 smem_sz;
  614. struct rb_root hdr_hdl_tree;
  615. struct rb_root rt_rule_hdl_tree;
  616. struct rb_root rt_tbl_hdl_tree;
  617. struct rb_root flt_rule_hdl_tree;
  618. struct ipa_nat_mem nat_mem;
  619. u32 excp_hdr_hdl;
  620. u32 dflt_v4_rt_rule_hdl;
  621. u32 dflt_v6_rt_rule_hdl;
  622. bool polling_mode;
  623. uint aggregation_type;
  624. uint aggregation_byte_limit;
  625. uint aggregation_time_limit;
  626. struct delayed_work poll_work;
  627. bool hdr_tbl_lcl;
  628. struct ipa_mem_buffer hdr_mem;
  629. bool ip4_rt_tbl_lcl;
  630. bool ip6_rt_tbl_lcl;
  631. bool ip4_flt_tbl_lcl;
  632. bool ip6_flt_tbl_lcl;
  633. struct ipa_mem_buffer empty_rt_tbl_mem;
  634. struct gen_pool *pipe_mem_pool;
  635. struct dma_pool *dma_pool;
  636. struct mutex ipa_active_clients_lock;
  637. int ipa_active_clients;
  638. u32 clnt_hdl_cmd;
  639. u32 clnt_hdl_data_in;
  640. u32 clnt_hdl_data_out;
  641. u8 a5_pipe_index;
  642. struct list_head intf_list;
  643. struct list_head msg_list;
  644. struct list_head pull_msg_list;
  645. struct mutex msg_lock;
  646. wait_queue_head_t msg_waitq;
  647. enum ipa_hw_type ipa_hw_type;
  648. enum ipa_hw_mode ipa_hw_mode;
  649. /* featurize if memory footprint becomes a concern */
  650. struct ipa_stats stats;
  651. void *smem_pipe_mem;
  652. };
  653. /**
  654. * struct ipa_route - IPA route
  655. * @route_dis: route disable
  656. * @route_def_pipe: route default pipe
  657. * @route_def_hdr_table: route default header table
  658. * @route_def_hdr_ofst: route default header offset table
  659. */
  660. struct ipa_route {
  661. u32 route_dis;
  662. u32 route_def_pipe;
  663. u32 route_def_hdr_table;
  664. u32 route_def_hdr_ofst;
  665. };
  666. /**
  667. * enum ipa_pipe_mem_type - IPA pipe memory type
  668. * @IPA_SPS_PIPE_MEM: Default, SPS dedicated pipe memory
  669. * @IPA_PRIVATE_MEM: IPA's private memory
  670. * @IPA_SYSTEM_MEM: System RAM, requires allocation
  671. */
  672. enum ipa_pipe_mem_type {
  673. IPA_SPS_PIPE_MEM = 0,
  674. IPA_PRIVATE_MEM = 1,
  675. IPA_SYSTEM_MEM = 2,
  676. };
  677. /**
  678. * enum a2_mux_pipe_direction - IPA-A2 pipe direction
  679. */
  680. enum a2_mux_pipe_direction {
  681. A2_TO_IPA = 0,
  682. IPA_TO_A2 = 1
  683. };
  684. /**
  685. * struct a2_mux_pipe_connection - A2 MUX pipe connection
  686. * @src_phy_addr: source physical address
  687. * @src_pipe_index: source pipe index
  688. * @dst_phy_addr: destination physical address
  689. * @dst_pipe_index: destination pipe index
  690. * @mem_type: pipe memory type
  691. * @data_fifo_base_offset: data FIFO base offset
  692. * @data_fifo_size: data FIFO size
  693. * @desc_fifo_base_offset: descriptors FIFO base offset
  694. * @desc_fifo_size: descriptors FIFO size
  695. */
  696. struct a2_mux_pipe_connection {
  697. int src_phy_addr;
  698. int src_pipe_index;
  699. int dst_phy_addr;
  700. int dst_pipe_index;
  701. enum ipa_pipe_mem_type mem_type;
  702. int data_fifo_base_offset;
  703. int data_fifo_size;
  704. int desc_fifo_base_offset;
  705. int desc_fifo_size;
  706. };
  707. struct ipa_plat_drv_res {
  708. u32 ipa_mem_base;
  709. u32 ipa_mem_size;
  710. u32 bam_mem_base;
  711. u32 bam_mem_size;
  712. u32 a2_bam_mem_base;
  713. u32 a2_bam_mem_size;
  714. u32 ipa_irq;
  715. u32 bam_irq;
  716. u32 a2_bam_irq;
  717. u32 ipa_pipe_mem_start_ofst;
  718. u32 ipa_pipe_mem_size;
  719. enum ipa_hw_type ipa_hw_type;
  720. enum ipa_hw_mode ipa_hw_mode;
  721. struct a2_mux_pipe_connection a2_to_ipa_pipe;
  722. struct a2_mux_pipe_connection ipa_to_a2_pipe;
  723. };
  724. extern struct ipa_context *ipa_ctx;
  725. int ipa_get_a2_mux_pipe_info(enum a2_mux_pipe_direction pipe_dir,
  726. struct a2_mux_pipe_connection *pipe_connect);
  727. int ipa_get_a2_mux_bam_info(u32 *a2_bam_mem_base, u32 *a2_bam_mem_size,
  728. u32 *a2_bam_irq);
  729. void teth_bridge_get_client_handles(u32 *producer_handle,
  730. u32 *consumer_handle);
  731. int ipa_send_one(struct ipa_sys_context *sys, struct ipa_desc *desc,
  732. bool in_atomic);
  733. int ipa_send(struct ipa_sys_context *sys, u32 num_desc, struct ipa_desc *desc,
  734. bool in_atomic);
  735. int ipa_get_ep_mapping(enum ipa_operating_mode mode,
  736. enum ipa_client_type client);
  737. int ipa_get_client_mapping(enum ipa_operating_mode mode, int pipe_idx);
  738. int ipa_generate_hw_rule(enum ipa_ip_type ip,
  739. const struct ipa_rule_attrib *attrib,
  740. u8 **buf,
  741. u16 *en_rule);
  742. u8 *ipa_write_32(u32 w, u8 *dest);
  743. u8 *ipa_write_16(u16 hw, u8 *dest);
  744. u8 *ipa_write_8(u8 b, u8 *dest);
  745. u8 *ipa_pad_to_32(u8 *dest);
  746. int ipa_init_hw(void);
  747. struct ipa_rt_tbl *__ipa_find_rt_tbl(enum ipa_ip_type ip, const char *name);
  748. void ipa_dump(void);
  749. int ipa_generate_hdr_hw_tbl(struct ipa_mem_buffer *mem);
  750. int ipa_generate_rt_hw_tbl(enum ipa_ip_type ip, struct ipa_mem_buffer *mem);
  751. int ipa_generate_flt_hw_tbl(enum ipa_ip_type ip, struct ipa_mem_buffer *mem);
  752. int ipa_set_single_ndp_per_mbim(bool);
  753. int ipa_set_hw_timer_fix_for_mbim_aggr(bool);
  754. void ipa_debugfs_init(void);
  755. void ipa_debugfs_remove(void);
  756. int ipa_insert(struct rb_root *root, struct ipa_tree_node *data);
  757. struct ipa_tree_node *ipa_search(struct rb_root *root, u32 hdl);
  758. void ipa_dump_buff_internal(void *base, dma_addr_t phy_base, u32 size);
  759. #ifdef IPA_DEBUG
  760. #define IPA_DUMP_BUFF(base, phy_base, size) \
  761. ipa_dump_buff_internal(base, phy_base, size)
  762. #else
  763. #define IPA_DUMP_BUFF(base, phy_base, size)
  764. #endif
  765. int ipa_cfg_route(struct ipa_route *route);
  766. int ipa_send_cmd(u16 num_desc, struct ipa_desc *descr);
  767. void ipa_replenish_rx_cache(void);
  768. void ipa_cleanup_rx(void);
  769. int ipa_cfg_filter(u32 disable);
  770. void ipa_wq_write_done(struct work_struct *work);
  771. int ipa_handle_rx_core(struct ipa_sys_context *sys, bool process_all,
  772. bool in_poll_state);
  773. int ipa_handle_tx_core(struct ipa_sys_context *sys, bool process_all,
  774. bool in_poll_state);
  775. int ipa_pipe_mem_init(u32 start_ofst, u32 size);
  776. int ipa_pipe_mem_alloc(u32 *ofst, u32 size);
  777. int ipa_pipe_mem_free(u32 ofst, u32 size);
  778. int ipa_straddle_boundary(u32 start, u32 end, u32 boundary);
  779. struct ipa_context *ipa_get_ctx(void);
  780. void ipa_enable_clks(void);
  781. void ipa_disable_clks(void);
  782. void ipa_inc_client_enable_clks(void);
  783. void ipa_dec_client_disable_clks(void);
  784. int ipa_del_hdr_by_user(struct ipa_ioc_del_hdr *hdls, bool by_user);
  785. int __ipa_del_rt_rule(u32 rule_hdl);
  786. int __ipa_del_hdr(u32 hdr_hdl, bool by_user);
  787. int __ipa_release_hdr(u32 hdr_hdl);
  788. static inline u32 ipa_read_reg(void *base, u32 offset)
  789. {
  790. u32 val = ioread32(base + offset);
  791. IPADBG("0x%x(va) read reg 0x%x r_val 0x%x.\n",
  792. (u32)base, offset, val);
  793. return val;
  794. }
  795. static inline void ipa_write_reg(void *base, u32 offset, u32 val)
  796. {
  797. iowrite32(val, base + offset);
  798. IPADBG("0x%x(va) write reg 0x%x w_val 0x%x.\n",
  799. (u32)base, offset, val);
  800. }
  801. int ipa_bridge_init(void);
  802. void ipa_bridge_cleanup(void);
  803. ssize_t ipa_read(struct file *filp, char __user *buf, size_t count,
  804. loff_t *f_pos);
  805. int ipa_pull_msg(struct ipa_msg_meta *meta, char *buff, size_t count);
  806. int ipa_query_intf(struct ipa_ioc_query_intf *lookup);
  807. int ipa_query_intf_tx_props(struct ipa_ioc_query_intf_tx_props *tx);
  808. int ipa_query_intf_rx_props(struct ipa_ioc_query_intf_rx_props *rx);
  809. int a2_mux_init(void);
  810. int a2_mux_exit(void);
  811. void wwan_cleanup(void);
  812. int teth_bridge_driver_init(void);
  813. #endif /* _IPA_I_H_ */