modem_prj.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #ifndef __MODEM_PRJ_H__
  15. #define __MODEM_PRJ_H__
  16. #include <linux/wait.h>
  17. #include <linux/miscdevice.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/wakelock.h>
  20. #include <linux/rbtree.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/cdev.h>
  23. #if 0 //#if defined(CONFIG_LINK_DEVICE_SPI)
  24. #define CONFIG_LINK_DEVICE_SPI_DEBUG
  25. #define CONFIG_LINK_DEVICE_SPI_RFS_DEBUG
  26. #endif
  27. #define MAX_CPINFO_SIZE 512
  28. #define MAX_LINK_DEVTYPE 3
  29. #define MAX_FMT_DEVS 10
  30. #define MAX_RAW_DEVS 32
  31. #define MAX_RFS_DEVS 10
  32. #define MAX_NUM_IO_DEV (MAX_FMT_DEVS + MAX_RAW_DEVS + MAX_RFS_DEVS)
  33. #define IOCTL_MODEM_ON _IO('o', 0x19)
  34. #define IOCTL_MODEM_OFF _IO('o', 0x20)
  35. #define IOCTL_MODEM_RESET _IO('o', 0x21)
  36. #define IOCTL_MODEM_BOOT_ON _IO('o', 0x22)
  37. #define IOCTL_MODEM_BOOT_OFF _IO('o', 0x23)
  38. #define IOCTL_MODEM_BOOT_DONE _IO('o', 0x24)
  39. #define IOCTL_MODEM_PROTOCOL_SUSPEND _IO('o', 0x25)
  40. #define IOCTL_MODEM_PROTOCOL_RESUME _IO('o', 0x26)
  41. #define IOCTL_MODEM_STATUS _IO('o', 0x27)
  42. #define IOCTL_MODEM_DL_START _IO('o', 0x28)
  43. #define IOCTL_MODEM_FW_UPDATE _IO('o', 0x29)
  44. #define IOCTL_MODEM_NET_SUSPEND _IO('o', 0x30)
  45. #define IOCTL_MODEM_NET_RESUME _IO('o', 0x31)
  46. #define IOCTL_MODEM_DUMP_START _IO('o', 0x32)
  47. #define IOCTL_MODEM_DUMP_UPDATE _IO('o', 0x33)
  48. #define IOCTL_MODEM_FORCE_CRASH_EXIT _IO('o', 0x34)
  49. #define IOCTL_MODEM_CP_UPLOAD _IO('o', 0x35)
  50. #define IOCTL_MODEM_DUMP_RESET _IO('o', 0x36)
  51. #if defined(CONFIG_SEC_DUAL_MODEM_MODE)
  52. #define IOCTL_MODEM_SWITCH_MODEM _IO('o', 0x37)
  53. #endif
  54. #define IOCTL_DPRAM_SEND_BOOT _IO('o', 0x40)
  55. #define IOCTL_DPRAM_INIT_STATUS _IO('o', 0x43)
  56. #define IOCTL_DPRAM_CHECK_CP_BIN _IO('o', 0xd4)
  57. #define IOCTL_DPRAM_UPDATED_CP_BIN _IO('o', 0xd5)
  58. /*
  59. * MAX_RXDATA_SIZE is used at making skb, when it called with page size
  60. * it need more bytes to allocate itself (Ex, cache byte, shared info,
  61. * padding...)
  62. * So, give restriction to allocation size below 1 page to prevent
  63. * big pages broken.
  64. */
  65. #define MAX_RXDATA_SIZE 0x0E00 /* 4 * 1024 - 512 */
  66. #define MAX_IPC_TX_SIZE 1024
  67. #define MAX_MTU_TX_DATA_SIZE 1550
  68. #define HDLC_HEADER_MAX_SIZE 6 /* fmt 3, raw 6, rfs 6 or sipc5 */
  69. #define MAX_LINK_PADDING_SIZE 3
  70. #define PSD_DATA_CHID_BEGIN 0x2A
  71. #define PSD_DATA_CHID_END 0x38
  72. #define IP6VERSION 6
  73. #define SOURCE_MAC_ADDR {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}
  74. #define FMT_WAKE_TIME (HZ/2)
  75. #define RFS_WAKE_TIME (HZ*3)
  76. #define RAW_WAKE_TIME (HZ*6)
  77. #define CP_LOOPBACK_CHANNEL 30
  78. /* Does modem ctl structure will use state ? or status defined below ?*/
  79. /* Be careful!! below sequence shouldn't be changed*/
  80. enum modem_state {
  81. STATE_OFFLINE,
  82. STATE_CRASH_RESET, /* silent reset */
  83. STATE_CRASH_EXIT, /* cp ramdump */
  84. STATE_BOOTING,
  85. STATE_ONLINE,
  86. STATE_NV_REBUILDING, /* <= rebuilding start */
  87. STATE_LOADER_DONE,
  88. STATE_SIM_ATTACH,
  89. STATE_SIM_DETACH,
  90. #if defined(CONFIG_SEC_DUAL_MODEM_MODE)
  91. STATE_MODEM_SWITCH,
  92. #endif
  93. };
  94. enum com_state {
  95. COM_NONE,
  96. COM_ONLINE,
  97. COM_HANDSHAKE,
  98. COM_BOOT,
  99. COM_CRASH,
  100. COM_BOOT_EBL,
  101. };
  102. enum link_mode {
  103. LINK_MODE_OFFLINE = 0,
  104. LINK_MODE_BOOT,
  105. LINK_MODE_IPC,
  106. LINK_MODE_DLOAD,
  107. LINK_MODE_ULOAD,
  108. };
  109. struct sim_state {
  110. bool online; /* SIM is online? */
  111. bool changed; /* online is changed? */
  112. };
  113. struct header_data {
  114. char hdr[HDLC_HEADER_MAX_SIZE];
  115. unsigned len;
  116. unsigned frag_len;
  117. char start; /* hdlc start header 0x7F or 0b11111000 */
  118. };
  119. struct fmt_hdr {
  120. u16 len;
  121. u8 control;
  122. } __packed;
  123. struct raw_hdr {
  124. u32 len;
  125. u8 channel;
  126. u8 control;
  127. } __packed;
  128. struct rfs_hdr {
  129. u32 len;
  130. u8 cmd;
  131. u8 id;
  132. } __packed;
  133. struct sipc_fmt_hdr {
  134. u16 len;
  135. u8 msg_seq;
  136. u8 ack_seq;
  137. u8 main_cmd;
  138. u8 sub_cmd;
  139. u8 cmd_type;
  140. } __packed;
  141. struct vnet {
  142. struct io_device *iod;
  143. };
  144. /* for fragmented data from link devices */
  145. struct fragmented_data {
  146. struct sk_buff *skb_recv;
  147. struct header_data h_data;
  148. /* page alloc fail retry*/
  149. unsigned realloc_offset;
  150. };
  151. #define fragdata(iod, ld) (&(iod)->fragments[(ld)->link_type])
  152. /** struct skbuff_priv - private data of struct sk_buff
  153. * this is matched to char cb[48] of struct sk_buff
  154. */
  155. struct skbuff_private {
  156. struct io_device *iod;
  157. struct link_device *ld;
  158. struct io_device *real_iod; /* for rx multipdp */
  159. };
  160. static inline struct skbuff_private *skbpriv(struct sk_buff *skb)
  161. {
  162. BUILD_BUG_ON(sizeof(struct skbuff_private) > sizeof(skb->cb));
  163. return (struct skbuff_private *)&skb->cb;
  164. }
  165. struct io_device {
  166. /* rb_tree node for an io device */
  167. struct rb_node node_chan;
  168. struct rb_node node_fmt;
  169. /* Name of the IO device */
  170. char *name;
  171. atomic_t opened;
  172. /* Wait queue for the IO device */
  173. wait_queue_head_t wq;
  174. /* Misc and net device structures for the IO device */
  175. struct miscdevice miscdev;
  176. struct net_device *ndev;
  177. /* ID and Format for channel on the link */
  178. unsigned id;
  179. enum modem_link link_types;
  180. enum dev_format format;
  181. enum modem_io io_typ;
  182. enum modem_network net_typ;
  183. bool use_handover; /* handover 2+ link devices */
  184. /* SIPC version */
  185. enum sipc_ver ipc_version;
  186. /* Rx queue of sk_buff */
  187. struct sk_buff_head sk_rx_q;
  188. struct fragmented_data fragments[LINKDEV_MAX];
  189. /* for multi-frame */
  190. struct sk_buff *skb[128];
  191. /* called from linkdevice when a packet arrives for this iodevice */
  192. int (*recv)(struct io_device *iod, struct link_device *ld,
  193. const char *data, unsigned int len);
  194. /* inform the IO device that the modem is now online or offline or
  195. * crashing or whatever...
  196. */
  197. void (*modem_state_changed)(struct io_device *iod, enum modem_state);
  198. /* inform the IO device that the SIM is not inserting or removing */
  199. void (*sim_state_changed)(struct io_device *iod, bool sim_online);
  200. struct modem_ctl *mc;
  201. struct modem_shared *msd;
  202. struct wake_lock wakelock;
  203. long waketime;
  204. /* DO NOT use __current_link directly
  205. * you MUST use skbpriv(skb)->ld in mc, link, etc..
  206. */
  207. struct link_device *__current_link;
  208. };
  209. #define to_io_device(misc) container_of(misc, struct io_device, miscdev)
  210. /* get_current_link, set_current_link don't need to use locks.
  211. * In ARM, set_current_link and get_current_link are compiled to
  212. * each one instruction (str, ldr) as atomic_set, atomic_read.
  213. * And, the order of set_current_link and get_current_link is not important.
  214. */
  215. #define get_current_link(iod) ((iod)->__current_link)
  216. #define set_current_link(iod, ld) ((iod)->__current_link = (ld))
  217. struct link_device {
  218. struct list_head list;
  219. char *name;
  220. enum modem_link link_type;
  221. unsigned aligned;
  222. /* Modem control */
  223. struct modem_ctl *mc;
  224. /* Modem shared data */
  225. struct modem_shared *msd;
  226. /* Operation mode of the link device */
  227. enum link_mode mode;
  228. struct io_device *fmt_iods[4];
  229. /* TX queue of socket buffers */
  230. struct sk_buff_head sk_fmt_tx_q;
  231. struct sk_buff_head sk_raw_tx_q;
  232. struct sk_buff_head sk_rfs_tx_q;
  233. bool raw_tx_suspended; /* for misc dev */
  234. struct completion raw_tx_resumed_by_cp;
  235. struct workqueue_struct *tx_wq;
  236. struct workqueue_struct *tx_raw_wq;
  237. struct work_struct tx_work;
  238. struct delayed_work tx_delayed_work;
  239. enum com_state com_state;
  240. /* init communication - setting link driver */
  241. int (*init_comm)(struct link_device *ld, struct io_device *iod);
  242. /* terminate communication */
  243. void (*terminate_comm)(struct link_device *ld, struct io_device *iod);
  244. /* called by an io_device when it has a packet to send over link
  245. * - the io device is passed so the link device can look at id and
  246. * format fields to determine how to route/format the packet
  247. */
  248. int (*send)(struct link_device *ld, struct io_device *iod,
  249. struct sk_buff *skb);
  250. //SPI_SETUP
  251. int (*ioctl)(struct link_device *ld, struct io_device *iod,
  252. unsigned cmd, unsigned long _arg);
  253. };
  254. /** rx_alloc_skb - allocate an skbuff and set skb's iod, ld
  255. * @length: length to allocate
  256. * @iod: struct io_device *
  257. * @ld: struct link_device *
  258. *
  259. * %NULL is returned if there is no free memory.
  260. */
  261. static inline struct sk_buff *rx_alloc_skb(unsigned int length,
  262. struct io_device *iod, struct link_device *ld)
  263. {
  264. struct sk_buff *skb;
  265. if (iod->format == IPC_MULTI_RAW || iod->format == IPC_RAW)
  266. skb = dev_alloc_skb(length);
  267. else
  268. skb = alloc_skb(length, GFP_KERNEL);
  269. if (likely(skb)) {
  270. skbpriv(skb)->iod = iod;
  271. skbpriv(skb)->ld = ld;
  272. }
  273. return skb;
  274. }
  275. struct modemctl_ops {
  276. int (*modem_on) (struct modem_ctl *);
  277. int (*modem_off) (struct modem_ctl *);
  278. int (*modem_reset) (struct modem_ctl *);
  279. int (*modem_boot_on) (struct modem_ctl *);
  280. int (*modem_boot_off) (struct modem_ctl *);
  281. int (*modem_force_crash_exit) (struct modem_ctl *);
  282. int (*modem_dump_reset) (struct modem_ctl *);
  283. };
  284. /* for IPC Logger */
  285. struct mif_storage {
  286. char *addr;
  287. unsigned int cnt;
  288. };
  289. /* modem_shared - shared data for all io/link devices and a modem ctl
  290. * msd : mc : iod : ld = 1 : 1 : M : N
  291. */
  292. struct modem_shared {
  293. /* list of link devices */
  294. struct list_head link_dev_list;
  295. /* rb_tree root of io devices. */
  296. struct rb_root iodevs_tree_chan; /* group by channel */
  297. struct rb_root iodevs_tree_fmt; /* group by dev_format */
  298. /* for IPC Logger */
  299. struct mif_storage storage;
  300. spinlock_t lock;
  301. };
  302. struct modem_ctl {
  303. struct device *dev;
  304. char *name;
  305. struct modem_data *mdm_data;
  306. struct modem_shared *msd;
  307. enum modem_state phone_state;
  308. struct sim_state sim_state;
  309. unsigned gpio_cp_on;
  310. unsigned gpio_cp_off;
  311. //temp disable bringup DKLee unsigned gpio_reset_req_n;
  312. unsigned gpio_pda_active;
  313. unsigned gpio_phone_active;
  314. unsigned gpio_cp_dump_int;
  315. unsigned gpio_ap_dump_int;
  316. unsigned gpio_sim_detect;
  317. unsigned gpio_cp_pwr_check;
  318. unsigned gpio_dynamic_switching;
  319. #ifdef CONFIG_GSM_MODEM_SPRD6500
  320. unsigned gpio_ap_cp_int1;
  321. unsigned gpio_ap_cp_int2;
  322. unsigned gpio_uart_sel;
  323. #endif
  324. #ifdef CONFIG_SEC_DUAL_MODEM_MODE
  325. unsigned gpio_sim_sel;
  326. //temp disable bringup DKLee unsigned gpio_cp_ctrl1;
  327. #endif
  328. int irq_phone_active;
  329. int irq_cp_dump_int;
  330. int irq_sim_detect;
  331. struct modemctl_ops ops;
  332. struct io_device *iod;
  333. struct io_device *bootd;
  334. };
  335. int sipc4_init_io_device(struct io_device *iod);
  336. int sipc5_init_io_device(struct io_device *iod);
  337. #if defined(CONFIG_GSM_MODEM_SPRD6500)
  338. extern int spi_sema_init(void);
  339. extern int sprd_boot_done;
  340. extern void if_spi_thread_restart(void);
  341. #endif
  342. #endif