nozomi.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
  4. *
  5. * Written by: Ulf Jakobsson,
  6. * Jan Åkerfeldt,
  7. * Stefan Thomasson,
  8. *
  9. * Maintained by: Paul Hardwick (p.hardwick@option.com)
  10. *
  11. * Patches:
  12. * Locking code changes for Vodafone by Sphere Systems Ltd,
  13. * Andrew Bird (ajb@spheresystems.co.uk )
  14. * & Phil Sanderson
  15. *
  16. * Source has been ported from an implementation made by Filip Aben @ Option
  17. *
  18. * --------------------------------------------------------------------------
  19. *
  20. * Copyright (c) 2005,2006 Option Wireless Sweden AB
  21. * Copyright (c) 2006 Sphere Systems Ltd
  22. * Copyright (c) 2006 Option Wireless n/v
  23. * All rights Reserved.
  24. *
  25. * --------------------------------------------------------------------------
  26. */
  27. /* Enable this to have a lot of debug printouts */
  28. #define DEBUG
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/pci.h>
  32. #include <linux/ioport.h>
  33. #include <linux/tty.h>
  34. #include <linux/tty_driver.h>
  35. #include <linux/tty_flip.h>
  36. #include <linux/sched.h>
  37. #include <linux/serial.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/kmod.h>
  40. #include <linux/init.h>
  41. #include <linux/kfifo.h>
  42. #include <linux/uaccess.h>
  43. #include <linux/slab.h>
  44. #include <asm/byteorder.h>
  45. #include <linux/delay.h>
  46. /* Default debug printout level */
  47. #define NOZOMI_DEBUG_LEVEL 0x00
  48. static int debug = NOZOMI_DEBUG_LEVEL;
  49. module_param(debug, int, S_IRUGO | S_IWUSR);
  50. /* Macros definitions */
  51. #define DBG_(lvl, fmt, args...) \
  52. do { \
  53. if (lvl & debug) \
  54. pr_debug("[%d] %s(): " fmt "\n", \
  55. __LINE__, __func__, ##args); \
  56. } while (0)
  57. #define DBG1(args...) DBG_(0x01, ##args)
  58. #define DBG2(args...) DBG_(0x02, ##args)
  59. #define DBG3(args...) DBG_(0x04, ##args)
  60. #define DBG4(args...) DBG_(0x08, ##args)
  61. #define TMP_BUF_MAX 256
  62. /* Defines */
  63. #define NOZOMI_NAME "nozomi"
  64. #define NOZOMI_NAME_TTY "nozomi_tty"
  65. #define NTTY_TTY_MAXMINORS 256
  66. #define NTTY_FIFO_BUFFER_SIZE 8192
  67. /* Must be power of 2 */
  68. #define FIFO_BUFFER_SIZE_UL 8192
  69. /* Size of tmp send buffer to card */
  70. #define SEND_BUF_MAX 1024
  71. #define RECEIVE_BUF_MAX 4
  72. #define R_IIR 0x0000 /* Interrupt Identity Register */
  73. #define R_FCR 0x0000 /* Flow Control Register */
  74. #define R_IER 0x0004 /* Interrupt Enable Register */
  75. #define NOZOMI_CONFIG_MAGIC 0xEFEFFEFE
  76. #define TOGGLE_VALID 0x0000
  77. /* Definition of interrupt tokens */
  78. #define MDM_DL1 0x0001
  79. #define MDM_UL1 0x0002
  80. #define MDM_DL2 0x0004
  81. #define MDM_UL2 0x0008
  82. #define DIAG_DL1 0x0010
  83. #define DIAG_DL2 0x0020
  84. #define DIAG_UL 0x0040
  85. #define APP1_DL 0x0080
  86. #define APP1_UL 0x0100
  87. #define APP2_DL 0x0200
  88. #define APP2_UL 0x0400
  89. #define CTRL_DL 0x0800
  90. #define CTRL_UL 0x1000
  91. #define RESET 0x8000
  92. #define MDM_DL (MDM_DL1 | MDM_DL2)
  93. #define MDM_UL (MDM_UL1 | MDM_UL2)
  94. #define DIAG_DL (DIAG_DL1 | DIAG_DL2)
  95. /* modem signal definition */
  96. #define CTRL_DSR 0x0001
  97. #define CTRL_DCD 0x0002
  98. #define CTRL_RI 0x0004
  99. #define CTRL_CTS 0x0008
  100. #define CTRL_DTR 0x0001
  101. #define CTRL_RTS 0x0002
  102. #define MAX_PORT 4
  103. #define NOZOMI_MAX_PORTS 5
  104. #define NOZOMI_MAX_CARDS (NTTY_TTY_MAXMINORS / MAX_PORT)
  105. /* Type definitions */
  106. /*
  107. * There are two types of nozomi cards,
  108. * one with 2048 memory and with 8192 memory
  109. */
  110. enum card_type {
  111. F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
  112. F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
  113. };
  114. /* Initialization states a card can be in */
  115. enum card_state {
  116. NOZOMI_STATE_UNKNOWN = 0,
  117. NOZOMI_STATE_ENABLED = 1, /* pci device enabled */
  118. NOZOMI_STATE_ALLOCATED = 2, /* config setup done */
  119. NOZOMI_STATE_READY = 3, /* flowcontrols received */
  120. };
  121. /* Two different toggle channels exist */
  122. enum channel_type {
  123. CH_A = 0,
  124. CH_B = 1,
  125. };
  126. /* Port definition for the card regarding flow control */
  127. enum ctrl_port_type {
  128. CTRL_CMD = 0,
  129. CTRL_MDM = 1,
  130. CTRL_DIAG = 2,
  131. CTRL_APP1 = 3,
  132. CTRL_APP2 = 4,
  133. CTRL_ERROR = -1,
  134. };
  135. /* Ports that the nozomi has */
  136. enum port_type {
  137. PORT_MDM = 0,
  138. PORT_DIAG = 1,
  139. PORT_APP1 = 2,
  140. PORT_APP2 = 3,
  141. PORT_CTRL = 4,
  142. PORT_ERROR = -1,
  143. };
  144. #ifdef __BIG_ENDIAN
  145. /* Big endian */
  146. struct toggles {
  147. unsigned int enabled:5; /*
  148. * Toggle fields are valid if enabled is 0,
  149. * else A-channels must always be used.
  150. */
  151. unsigned int diag_dl:1;
  152. unsigned int mdm_dl:1;
  153. unsigned int mdm_ul:1;
  154. } __attribute__ ((packed));
  155. /* Configuration table to read at startup of card */
  156. /* Is for now only needed during initialization phase */
  157. struct config_table {
  158. u32 signature;
  159. u16 product_information;
  160. u16 version;
  161. u8 pad3[3];
  162. struct toggles toggle;
  163. u8 pad1[4];
  164. u16 dl_mdm_len1; /*
  165. * If this is 64, it can hold
  166. * 60 bytes + 4 that is length field
  167. */
  168. u16 dl_start;
  169. u16 dl_diag_len1;
  170. u16 dl_mdm_len2; /*
  171. * If this is 64, it can hold
  172. * 60 bytes + 4 that is length field
  173. */
  174. u16 dl_app1_len;
  175. u16 dl_diag_len2;
  176. u16 dl_ctrl_len;
  177. u16 dl_app2_len;
  178. u8 pad2[16];
  179. u16 ul_mdm_len1;
  180. u16 ul_start;
  181. u16 ul_diag_len;
  182. u16 ul_mdm_len2;
  183. u16 ul_app1_len;
  184. u16 ul_app2_len;
  185. u16 ul_ctrl_len;
  186. } __attribute__ ((packed));
  187. /* This stores all control downlink flags */
  188. struct ctrl_dl {
  189. u8 port;
  190. unsigned int reserved:4;
  191. unsigned int CTS:1;
  192. unsigned int RI:1;
  193. unsigned int DCD:1;
  194. unsigned int DSR:1;
  195. } __attribute__ ((packed));
  196. /* This stores all control uplink flags */
  197. struct ctrl_ul {
  198. u8 port;
  199. unsigned int reserved:6;
  200. unsigned int RTS:1;
  201. unsigned int DTR:1;
  202. } __attribute__ ((packed));
  203. #else
  204. /* Little endian */
  205. /* This represents the toggle information */
  206. struct toggles {
  207. unsigned int mdm_ul:1;
  208. unsigned int mdm_dl:1;
  209. unsigned int diag_dl:1;
  210. unsigned int enabled:5; /*
  211. * Toggle fields are valid if enabled is 0,
  212. * else A-channels must always be used.
  213. */
  214. } __attribute__ ((packed));
  215. /* Configuration table to read at startup of card */
  216. struct config_table {
  217. u32 signature;
  218. u16 version;
  219. u16 product_information;
  220. struct toggles toggle;
  221. u8 pad1[7];
  222. u16 dl_start;
  223. u16 dl_mdm_len1; /*
  224. * If this is 64, it can hold
  225. * 60 bytes + 4 that is length field
  226. */
  227. u16 dl_mdm_len2;
  228. u16 dl_diag_len1;
  229. u16 dl_diag_len2;
  230. u16 dl_app1_len;
  231. u16 dl_app2_len;
  232. u16 dl_ctrl_len;
  233. u8 pad2[16];
  234. u16 ul_start;
  235. u16 ul_mdm_len2;
  236. u16 ul_mdm_len1;
  237. u16 ul_diag_len;
  238. u16 ul_app1_len;
  239. u16 ul_app2_len;
  240. u16 ul_ctrl_len;
  241. } __attribute__ ((packed));
  242. /* This stores all control downlink flags */
  243. struct ctrl_dl {
  244. unsigned int DSR:1;
  245. unsigned int DCD:1;
  246. unsigned int RI:1;
  247. unsigned int CTS:1;
  248. unsigned int reserved:4;
  249. u8 port;
  250. } __attribute__ ((packed));
  251. /* This stores all control uplink flags */
  252. struct ctrl_ul {
  253. unsigned int DTR:1;
  254. unsigned int RTS:1;
  255. unsigned int reserved:6;
  256. u8 port;
  257. } __attribute__ ((packed));
  258. #endif
  259. /* This holds all information that is needed regarding a port */
  260. struct port {
  261. struct tty_port port;
  262. u8 update_flow_control;
  263. struct ctrl_ul ctrl_ul;
  264. struct ctrl_dl ctrl_dl;
  265. struct kfifo fifo_ul;
  266. void __iomem *dl_addr[2];
  267. u32 dl_size[2];
  268. u8 toggle_dl;
  269. void __iomem *ul_addr[2];
  270. u32 ul_size[2];
  271. u8 toggle_ul;
  272. u16 token_dl;
  273. wait_queue_head_t tty_wait;
  274. struct async_icount tty_icount;
  275. struct nozomi *dc;
  276. };
  277. /* Private data one for each card in the system */
  278. struct nozomi {
  279. void __iomem *base_addr;
  280. unsigned long flip;
  281. /* Pointers to registers */
  282. void __iomem *reg_iir;
  283. void __iomem *reg_fcr;
  284. void __iomem *reg_ier;
  285. u16 last_ier;
  286. enum card_type card_type;
  287. struct config_table config_table; /* Configuration table */
  288. struct pci_dev *pdev;
  289. struct port port[NOZOMI_MAX_PORTS];
  290. u8 *send_buf;
  291. spinlock_t spin_mutex; /* secures access to registers and tty */
  292. unsigned int index_start;
  293. enum card_state state;
  294. u32 open_ttys;
  295. };
  296. /* Global variables */
  297. static const struct pci_device_id nozomi_pci_tbl[] = {
  298. {PCI_DEVICE(0x1931, 0x000c)}, /* Nozomi HSDPA */
  299. {},
  300. };
  301. MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
  302. static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
  303. static struct tty_driver *ntty_driver;
  304. static const struct tty_port_operations noz_tty_port_ops;
  305. /*
  306. * find card by tty_index
  307. */
  308. static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
  309. {
  310. return tty ? ndevs[tty->index / MAX_PORT] : NULL;
  311. }
  312. static inline struct port *get_port_by_tty(const struct tty_struct *tty)
  313. {
  314. struct nozomi *ndev = get_dc_by_tty(tty);
  315. return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL;
  316. }
  317. /*
  318. * TODO:
  319. * -Optimize
  320. * -Rewrite cleaner
  321. */
  322. static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
  323. u32 size_bytes)
  324. {
  325. u32 i = 0;
  326. const u32 __iomem *ptr = mem_addr_start;
  327. u16 *buf16;
  328. if (unlikely(!ptr || !buf))
  329. goto out;
  330. /* shortcut for extremely often used cases */
  331. switch (size_bytes) {
  332. case 2: /* 2 bytes */
  333. buf16 = (u16 *) buf;
  334. *buf16 = __le16_to_cpu(readw(ptr));
  335. goto out;
  336. case 4: /* 4 bytes */
  337. *(buf) = __le32_to_cpu(readl(ptr));
  338. goto out;
  339. }
  340. while (i < size_bytes) {
  341. if (size_bytes - i == 2) {
  342. /* Handle 2 bytes in the end */
  343. buf16 = (u16 *) buf;
  344. *(buf16) = __le16_to_cpu(readw(ptr));
  345. i += 2;
  346. } else {
  347. /* Read 4 bytes */
  348. *(buf) = __le32_to_cpu(readl(ptr));
  349. i += 4;
  350. }
  351. buf++;
  352. ptr++;
  353. }
  354. out:
  355. return;
  356. }
  357. /*
  358. * TODO:
  359. * -Optimize
  360. * -Rewrite cleaner
  361. */
  362. static u32 write_mem32(void __iomem *mem_addr_start, const u32 *buf,
  363. u32 size_bytes)
  364. {
  365. u32 i = 0;
  366. u32 __iomem *ptr = mem_addr_start;
  367. const u16 *buf16;
  368. if (unlikely(!ptr || !buf))
  369. return 0;
  370. /* shortcut for extremely often used cases */
  371. switch (size_bytes) {
  372. case 2: /* 2 bytes */
  373. buf16 = (const u16 *)buf;
  374. writew(__cpu_to_le16(*buf16), ptr);
  375. return 2;
  376. case 1: /*
  377. * also needs to write 4 bytes in this case
  378. * so falling through..
  379. */
  380. fallthrough;
  381. case 4: /* 4 bytes */
  382. writel(__cpu_to_le32(*buf), ptr);
  383. return 4;
  384. }
  385. while (i < size_bytes) {
  386. if (size_bytes - i == 2) {
  387. /* 2 bytes */
  388. buf16 = (const u16 *)buf;
  389. writew(__cpu_to_le16(*buf16), ptr);
  390. i += 2;
  391. } else {
  392. /* 4 bytes */
  393. writel(__cpu_to_le32(*buf), ptr);
  394. i += 4;
  395. }
  396. buf++;
  397. ptr++;
  398. }
  399. return i;
  400. }
  401. /* Setup pointers to different channels and also setup buffer sizes. */
  402. static void nozomi_setup_memory(struct nozomi *dc)
  403. {
  404. void __iomem *offset = dc->base_addr + dc->config_table.dl_start;
  405. /* The length reported is including the length field of 4 bytes,
  406. * hence subtract with 4.
  407. */
  408. const u16 buff_offset = 4;
  409. /* Modem port dl configuration */
  410. dc->port[PORT_MDM].dl_addr[CH_A] = offset;
  411. dc->port[PORT_MDM].dl_addr[CH_B] =
  412. (offset += dc->config_table.dl_mdm_len1);
  413. dc->port[PORT_MDM].dl_size[CH_A] =
  414. dc->config_table.dl_mdm_len1 - buff_offset;
  415. dc->port[PORT_MDM].dl_size[CH_B] =
  416. dc->config_table.dl_mdm_len2 - buff_offset;
  417. /* Diag port dl configuration */
  418. dc->port[PORT_DIAG].dl_addr[CH_A] =
  419. (offset += dc->config_table.dl_mdm_len2);
  420. dc->port[PORT_DIAG].dl_size[CH_A] =
  421. dc->config_table.dl_diag_len1 - buff_offset;
  422. dc->port[PORT_DIAG].dl_addr[CH_B] =
  423. (offset += dc->config_table.dl_diag_len1);
  424. dc->port[PORT_DIAG].dl_size[CH_B] =
  425. dc->config_table.dl_diag_len2 - buff_offset;
  426. /* App1 port dl configuration */
  427. dc->port[PORT_APP1].dl_addr[CH_A] =
  428. (offset += dc->config_table.dl_diag_len2);
  429. dc->port[PORT_APP1].dl_size[CH_A] =
  430. dc->config_table.dl_app1_len - buff_offset;
  431. /* App2 port dl configuration */
  432. dc->port[PORT_APP2].dl_addr[CH_A] =
  433. (offset += dc->config_table.dl_app1_len);
  434. dc->port[PORT_APP2].dl_size[CH_A] =
  435. dc->config_table.dl_app2_len - buff_offset;
  436. /* Ctrl dl configuration */
  437. dc->port[PORT_CTRL].dl_addr[CH_A] =
  438. (offset += dc->config_table.dl_app2_len);
  439. dc->port[PORT_CTRL].dl_size[CH_A] =
  440. dc->config_table.dl_ctrl_len - buff_offset;
  441. offset = dc->base_addr + dc->config_table.ul_start;
  442. /* Modem Port ul configuration */
  443. dc->port[PORT_MDM].ul_addr[CH_A] = offset;
  444. dc->port[PORT_MDM].ul_size[CH_A] =
  445. dc->config_table.ul_mdm_len1 - buff_offset;
  446. dc->port[PORT_MDM].ul_addr[CH_B] =
  447. (offset += dc->config_table.ul_mdm_len1);
  448. dc->port[PORT_MDM].ul_size[CH_B] =
  449. dc->config_table.ul_mdm_len2 - buff_offset;
  450. /* Diag port ul configuration */
  451. dc->port[PORT_DIAG].ul_addr[CH_A] =
  452. (offset += dc->config_table.ul_mdm_len2);
  453. dc->port[PORT_DIAG].ul_size[CH_A] =
  454. dc->config_table.ul_diag_len - buff_offset;
  455. /* App1 port ul configuration */
  456. dc->port[PORT_APP1].ul_addr[CH_A] =
  457. (offset += dc->config_table.ul_diag_len);
  458. dc->port[PORT_APP1].ul_size[CH_A] =
  459. dc->config_table.ul_app1_len - buff_offset;
  460. /* App2 port ul configuration */
  461. dc->port[PORT_APP2].ul_addr[CH_A] =
  462. (offset += dc->config_table.ul_app1_len);
  463. dc->port[PORT_APP2].ul_size[CH_A] =
  464. dc->config_table.ul_app2_len - buff_offset;
  465. /* Ctrl ul configuration */
  466. dc->port[PORT_CTRL].ul_addr[CH_A] =
  467. (offset += dc->config_table.ul_app2_len);
  468. dc->port[PORT_CTRL].ul_size[CH_A] =
  469. dc->config_table.ul_ctrl_len - buff_offset;
  470. }
  471. /* Dump config table under initalization phase */
  472. #ifdef DEBUG
  473. static void dump_table(const struct nozomi *dc)
  474. {
  475. DBG3("signature: 0x%08X", dc->config_table.signature);
  476. DBG3("version: 0x%04X", dc->config_table.version);
  477. DBG3("product_information: 0x%04X", \
  478. dc->config_table.product_information);
  479. DBG3("toggle enabled: %d", dc->config_table.toggle.enabled);
  480. DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul);
  481. DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl);
  482. DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl);
  483. DBG3("dl_start: 0x%04X", dc->config_table.dl_start);
  484. DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1,
  485. dc->config_table.dl_mdm_len1);
  486. DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2,
  487. dc->config_table.dl_mdm_len2);
  488. DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1,
  489. dc->config_table.dl_diag_len1);
  490. DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2,
  491. dc->config_table.dl_diag_len2);
  492. DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len,
  493. dc->config_table.dl_app1_len);
  494. DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len,
  495. dc->config_table.dl_app2_len);
  496. DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len,
  497. dc->config_table.dl_ctrl_len);
  498. DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start,
  499. dc->config_table.ul_start);
  500. DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1,
  501. dc->config_table.ul_mdm_len1);
  502. DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2,
  503. dc->config_table.ul_mdm_len2);
  504. DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len,
  505. dc->config_table.ul_diag_len);
  506. DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len,
  507. dc->config_table.ul_app1_len);
  508. DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len,
  509. dc->config_table.ul_app2_len);
  510. DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len,
  511. dc->config_table.ul_ctrl_len);
  512. }
  513. #else
  514. static inline void dump_table(const struct nozomi *dc) { }
  515. #endif
  516. /*
  517. * Read configuration table from card under intalization phase
  518. * Returns 1 if ok, else 0
  519. */
  520. static int nozomi_read_config_table(struct nozomi *dc)
  521. {
  522. read_mem32((u32 *) &dc->config_table, dc->base_addr + 0,
  523. sizeof(struct config_table));
  524. if (dc->config_table.signature != NOZOMI_CONFIG_MAGIC) {
  525. dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n",
  526. dc->config_table.signature, NOZOMI_CONFIG_MAGIC);
  527. return 0;
  528. }
  529. if ((dc->config_table.version == 0)
  530. || (dc->config_table.toggle.enabled == TOGGLE_VALID)) {
  531. int i;
  532. DBG1("Second phase, configuring card");
  533. nozomi_setup_memory(dc);
  534. dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul;
  535. dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl;
  536. dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl;
  537. DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
  538. dc->port[PORT_MDM].toggle_ul,
  539. dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl);
  540. dump_table(dc);
  541. for (i = PORT_MDM; i < MAX_PORT; i++) {
  542. memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
  543. memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
  544. }
  545. /* Enable control channel */
  546. dc->last_ier = dc->last_ier | CTRL_DL;
  547. writew(dc->last_ier, dc->reg_ier);
  548. dc->state = NOZOMI_STATE_ALLOCATED;
  549. dev_info(&dc->pdev->dev, "Initialization OK!\n");
  550. return 1;
  551. }
  552. if ((dc->config_table.version > 0)
  553. && (dc->config_table.toggle.enabled != TOGGLE_VALID)) {
  554. u32 offset = 0;
  555. DBG1("First phase: pushing upload buffers, clearing download");
  556. dev_info(&dc->pdev->dev, "Version of card: %d\n",
  557. dc->config_table.version);
  558. /* Here we should disable all I/O over F32. */
  559. nozomi_setup_memory(dc);
  560. /*
  561. * We should send ALL channel pair tokens back along
  562. * with reset token
  563. */
  564. /* push upload modem buffers */
  565. write_mem32(dc->port[PORT_MDM].ul_addr[CH_A],
  566. (u32 *) &offset, 4);
  567. write_mem32(dc->port[PORT_MDM].ul_addr[CH_B],
  568. (u32 *) &offset, 4);
  569. writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr);
  570. DBG1("First phase done");
  571. }
  572. return 1;
  573. }
  574. /* Enable uplink interrupts */
  575. static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
  576. {
  577. static const u16 mask[] = {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
  578. if (port < NOZOMI_MAX_PORTS) {
  579. dc->last_ier |= mask[port];
  580. writew(dc->last_ier, dc->reg_ier);
  581. } else {
  582. dev_err(&dc->pdev->dev, "Called with wrong port?\n");
  583. }
  584. }
  585. /* Disable uplink interrupts */
  586. static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
  587. {
  588. static const u16 mask[] =
  589. {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
  590. if (port < NOZOMI_MAX_PORTS) {
  591. dc->last_ier &= mask[port];
  592. writew(dc->last_ier, dc->reg_ier);
  593. } else {
  594. dev_err(&dc->pdev->dev, "Called with wrong port?\n");
  595. }
  596. }
  597. /* Enable downlink interrupts */
  598. static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
  599. {
  600. static const u16 mask[] = {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
  601. if (port < NOZOMI_MAX_PORTS) {
  602. dc->last_ier |= mask[port];
  603. writew(dc->last_ier, dc->reg_ier);
  604. } else {
  605. dev_err(&dc->pdev->dev, "Called with wrong port?\n");
  606. }
  607. }
  608. /* Disable downlink interrupts */
  609. static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
  610. {
  611. static const u16 mask[] =
  612. {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
  613. if (port < NOZOMI_MAX_PORTS) {
  614. dc->last_ier &= mask[port];
  615. writew(dc->last_ier, dc->reg_ier);
  616. } else {
  617. dev_err(&dc->pdev->dev, "Called with wrong port?\n");
  618. }
  619. }
  620. /*
  621. * Return 1 - send buffer to card and ack.
  622. * Return 0 - don't ack, don't send buffer to card.
  623. */
  624. static int send_data(enum port_type index, struct nozomi *dc)
  625. {
  626. u32 size = 0;
  627. struct port *port = &dc->port[index];
  628. const u8 toggle = port->toggle_ul;
  629. void __iomem *addr = port->ul_addr[toggle];
  630. const u32 ul_size = port->ul_size[toggle];
  631. /* Get data from tty and place in buf for now */
  632. size = kfifo_out(&port->fifo_ul, dc->send_buf,
  633. ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
  634. if (size == 0) {
  635. DBG4("No more data to send, disable link:");
  636. return 0;
  637. }
  638. /* Write length + data */
  639. write_mem32(addr, (u32 *) &size, 4);
  640. write_mem32(addr + 4, (u32 *) dc->send_buf, size);
  641. tty_port_tty_wakeup(&port->port);
  642. return 1;
  643. }
  644. /* If all data has been read, return 1, else 0 */
  645. static int receive_data(enum port_type index, struct nozomi *dc)
  646. {
  647. u8 buf[RECEIVE_BUF_MAX] = { 0 };
  648. int size;
  649. u32 offset = 4;
  650. struct port *port = &dc->port[index];
  651. void __iomem *addr = port->dl_addr[port->toggle_dl];
  652. struct tty_struct *tty = tty_port_tty_get(&port->port);
  653. int i, ret;
  654. size = __le32_to_cpu(readl(addr));
  655. if (tty && tty_throttled(tty)) {
  656. DBG1("No room in tty, don't read data, don't ack interrupt, "
  657. "disable interrupt");
  658. /* disable interrupt in downlink... */
  659. disable_transmit_dl(index, dc);
  660. ret = 0;
  661. goto put;
  662. }
  663. if (unlikely(size == 0)) {
  664. dev_err(&dc->pdev->dev, "size == 0?\n");
  665. ret = 1;
  666. goto put;
  667. }
  668. while (size > 0) {
  669. read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
  670. if (size == 1) {
  671. tty_insert_flip_char(&port->port, buf[0], TTY_NORMAL);
  672. size = 0;
  673. } else if (size < RECEIVE_BUF_MAX) {
  674. size -= tty_insert_flip_string(&port->port, buf, size);
  675. } else {
  676. i = tty_insert_flip_string(&port->port, buf,
  677. RECEIVE_BUF_MAX);
  678. size -= i;
  679. offset += i;
  680. }
  681. }
  682. set_bit(index, &dc->flip);
  683. ret = 1;
  684. put:
  685. tty_kref_put(tty);
  686. return ret;
  687. }
  688. /* Debug for interrupts */
  689. #ifdef DEBUG
  690. static char *interrupt2str(u16 interrupt)
  691. {
  692. static char buf[TMP_BUF_MAX];
  693. char *p = buf;
  694. if (interrupt & MDM_DL1)
  695. p += scnprintf(p, TMP_BUF_MAX, "MDM_DL1 ");
  696. if (interrupt & MDM_DL2)
  697. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_DL2 ");
  698. if (interrupt & MDM_UL1)
  699. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL1 ");
  700. if (interrupt & MDM_UL2)
  701. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL2 ");
  702. if (interrupt & DIAG_DL1)
  703. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL1 ");
  704. if (interrupt & DIAG_DL2)
  705. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL2 ");
  706. if (interrupt & DIAG_UL)
  707. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_UL ");
  708. if (interrupt & APP1_DL)
  709. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_DL ");
  710. if (interrupt & APP2_DL)
  711. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_DL ");
  712. if (interrupt & APP1_UL)
  713. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_UL ");
  714. if (interrupt & APP2_UL)
  715. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_UL ");
  716. if (interrupt & CTRL_DL)
  717. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_DL ");
  718. if (interrupt & CTRL_UL)
  719. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_UL ");
  720. if (interrupt & RESET)
  721. p += scnprintf(p, TMP_BUF_MAX - (p - buf), "RESET ");
  722. return buf;
  723. }
  724. #endif
  725. /*
  726. * Receive flow control
  727. * Return 1 - If ok, else 0
  728. */
  729. static int receive_flow_control(struct nozomi *dc)
  730. {
  731. enum port_type port = PORT_MDM;
  732. struct ctrl_dl ctrl_dl;
  733. struct ctrl_dl old_ctrl;
  734. u16 enable_ier = 0;
  735. read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2);
  736. switch (ctrl_dl.port) {
  737. case CTRL_CMD:
  738. DBG1("The Base Band sends this value as a response to a "
  739. "request for IMSI detach sent over the control "
  740. "channel uplink (see section 7.6.1).");
  741. break;
  742. case CTRL_MDM:
  743. port = PORT_MDM;
  744. enable_ier = MDM_DL;
  745. break;
  746. case CTRL_DIAG:
  747. port = PORT_DIAG;
  748. enable_ier = DIAG_DL;
  749. break;
  750. case CTRL_APP1:
  751. port = PORT_APP1;
  752. enable_ier = APP1_DL;
  753. break;
  754. case CTRL_APP2:
  755. port = PORT_APP2;
  756. enable_ier = APP2_DL;
  757. if (dc->state == NOZOMI_STATE_ALLOCATED) {
  758. /*
  759. * After card initialization the flow control
  760. * received for APP2 is always the last
  761. */
  762. dc->state = NOZOMI_STATE_READY;
  763. dev_info(&dc->pdev->dev, "Device READY!\n");
  764. }
  765. break;
  766. default:
  767. dev_err(&dc->pdev->dev,
  768. "ERROR: flow control received for non-existing port\n");
  769. return 0;
  770. }
  771. DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl),
  772. *((u16 *)&ctrl_dl));
  773. old_ctrl = dc->port[port].ctrl_dl;
  774. dc->port[port].ctrl_dl = ctrl_dl;
  775. if (old_ctrl.CTS == 1 && ctrl_dl.CTS == 0) {
  776. DBG1("Disable interrupt (0x%04X) on port: %d",
  777. enable_ier, port);
  778. disable_transmit_ul(port, dc);
  779. } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
  780. if (kfifo_len(&dc->port[port].fifo_ul)) {
  781. DBG1("Enable interrupt (0x%04X) on port: %d",
  782. enable_ier, port);
  783. DBG1("Data in buffer [%d], enable transmit! ",
  784. kfifo_len(&dc->port[port].fifo_ul));
  785. enable_transmit_ul(port, dc);
  786. } else {
  787. DBG1("No data in buffer...");
  788. }
  789. }
  790. if (*(u16 *)&old_ctrl == *(u16 *)&ctrl_dl) {
  791. DBG1(" No change in mctrl");
  792. return 1;
  793. }
  794. /* Update statistics */
  795. if (old_ctrl.CTS != ctrl_dl.CTS)
  796. dc->port[port].tty_icount.cts++;
  797. if (old_ctrl.DSR != ctrl_dl.DSR)
  798. dc->port[port].tty_icount.dsr++;
  799. if (old_ctrl.RI != ctrl_dl.RI)
  800. dc->port[port].tty_icount.rng++;
  801. if (old_ctrl.DCD != ctrl_dl.DCD)
  802. dc->port[port].tty_icount.dcd++;
  803. wake_up_interruptible(&dc->port[port].tty_wait);
  804. DBG1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
  805. port,
  806. dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts,
  807. dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr);
  808. return 1;
  809. }
  810. static enum ctrl_port_type port2ctrl(enum port_type port,
  811. const struct nozomi *dc)
  812. {
  813. switch (port) {
  814. case PORT_MDM:
  815. return CTRL_MDM;
  816. case PORT_DIAG:
  817. return CTRL_DIAG;
  818. case PORT_APP1:
  819. return CTRL_APP1;
  820. case PORT_APP2:
  821. return CTRL_APP2;
  822. default:
  823. dev_err(&dc->pdev->dev,
  824. "ERROR: send flow control " \
  825. "received for non-existing port\n");
  826. }
  827. return CTRL_ERROR;
  828. }
  829. /*
  830. * Send flow control, can only update one channel at a time
  831. * Return 0 - If we have updated all flow control
  832. * Return 1 - If we need to update more flow control, ack current enable more
  833. */
  834. static int send_flow_control(struct nozomi *dc)
  835. {
  836. u32 i, more_flow_control_to_be_updated = 0;
  837. u16 *ctrl;
  838. for (i = PORT_MDM; i < MAX_PORT; i++) {
  839. if (dc->port[i].update_flow_control) {
  840. if (more_flow_control_to_be_updated) {
  841. /* We have more flow control to be updated */
  842. return 1;
  843. }
  844. dc->port[i].ctrl_ul.port = port2ctrl(i, dc);
  845. ctrl = (u16 *)&dc->port[i].ctrl_ul;
  846. write_mem32(dc->port[PORT_CTRL].ul_addr[0], \
  847. (u32 *) ctrl, 2);
  848. dc->port[i].update_flow_control = 0;
  849. more_flow_control_to_be_updated = 1;
  850. }
  851. }
  852. return 0;
  853. }
  854. /*
  855. * Handle downlink data, ports that are handled are modem and diagnostics
  856. * Return 1 - ok
  857. * Return 0 - toggle fields are out of sync
  858. */
  859. static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
  860. u16 read_iir, u16 mask1, u16 mask2)
  861. {
  862. if (*toggle == 0 && read_iir & mask1) {
  863. if (receive_data(port, dc)) {
  864. writew(mask1, dc->reg_fcr);
  865. *toggle = !(*toggle);
  866. }
  867. if (read_iir & mask2) {
  868. if (receive_data(port, dc)) {
  869. writew(mask2, dc->reg_fcr);
  870. *toggle = !(*toggle);
  871. }
  872. }
  873. } else if (*toggle == 1 && read_iir & mask2) {
  874. if (receive_data(port, dc)) {
  875. writew(mask2, dc->reg_fcr);
  876. *toggle = !(*toggle);
  877. }
  878. if (read_iir & mask1) {
  879. if (receive_data(port, dc)) {
  880. writew(mask1, dc->reg_fcr);
  881. *toggle = !(*toggle);
  882. }
  883. }
  884. } else {
  885. dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n",
  886. *toggle);
  887. return 0;
  888. }
  889. return 1;
  890. }
  891. /*
  892. * Handle uplink data, this is currently for the modem port
  893. * Return 1 - ok
  894. * Return 0 - toggle field are out of sync
  895. */
  896. static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
  897. {
  898. u8 *toggle = &(dc->port[port].toggle_ul);
  899. if (*toggle == 0 && read_iir & MDM_UL1) {
  900. dc->last_ier &= ~MDM_UL;
  901. writew(dc->last_ier, dc->reg_ier);
  902. if (send_data(port, dc)) {
  903. writew(MDM_UL1, dc->reg_fcr);
  904. dc->last_ier = dc->last_ier | MDM_UL;
  905. writew(dc->last_ier, dc->reg_ier);
  906. *toggle = !*toggle;
  907. }
  908. if (read_iir & MDM_UL2) {
  909. dc->last_ier &= ~MDM_UL;
  910. writew(dc->last_ier, dc->reg_ier);
  911. if (send_data(port, dc)) {
  912. writew(MDM_UL2, dc->reg_fcr);
  913. dc->last_ier = dc->last_ier | MDM_UL;
  914. writew(dc->last_ier, dc->reg_ier);
  915. *toggle = !*toggle;
  916. }
  917. }
  918. } else if (*toggle == 1 && read_iir & MDM_UL2) {
  919. dc->last_ier &= ~MDM_UL;
  920. writew(dc->last_ier, dc->reg_ier);
  921. if (send_data(port, dc)) {
  922. writew(MDM_UL2, dc->reg_fcr);
  923. dc->last_ier = dc->last_ier | MDM_UL;
  924. writew(dc->last_ier, dc->reg_ier);
  925. *toggle = !*toggle;
  926. }
  927. if (read_iir & MDM_UL1) {
  928. dc->last_ier &= ~MDM_UL;
  929. writew(dc->last_ier, dc->reg_ier);
  930. if (send_data(port, dc)) {
  931. writew(MDM_UL1, dc->reg_fcr);
  932. dc->last_ier = dc->last_ier | MDM_UL;
  933. writew(dc->last_ier, dc->reg_ier);
  934. *toggle = !*toggle;
  935. }
  936. }
  937. } else {
  938. writew(read_iir & MDM_UL, dc->reg_fcr);
  939. dev_err(&dc->pdev->dev, "port out of sync!\n");
  940. return 0;
  941. }
  942. return 1;
  943. }
  944. static irqreturn_t interrupt_handler(int irq, void *dev_id)
  945. {
  946. struct nozomi *dc = dev_id;
  947. unsigned int a;
  948. u16 read_iir;
  949. if (!dc)
  950. return IRQ_NONE;
  951. spin_lock(&dc->spin_mutex);
  952. read_iir = readw(dc->reg_iir);
  953. /* Card removed */
  954. if (read_iir == (u16)-1)
  955. goto none;
  956. /*
  957. * Just handle interrupt enabled in IER
  958. * (by masking with dc->last_ier)
  959. */
  960. read_iir &= dc->last_ier;
  961. if (read_iir == 0)
  962. goto none;
  963. DBG4("%s irq:0x%04X, prev:0x%04X", interrupt2str(read_iir), read_iir,
  964. dc->last_ier);
  965. if (read_iir & RESET) {
  966. if (unlikely(!nozomi_read_config_table(dc))) {
  967. dc->last_ier = 0x0;
  968. writew(dc->last_ier, dc->reg_ier);
  969. dev_err(&dc->pdev->dev, "Could not read status from "
  970. "card, we should disable interface\n");
  971. } else {
  972. writew(RESET, dc->reg_fcr);
  973. }
  974. /* No more useful info if this was the reset interrupt. */
  975. goto exit_handler;
  976. }
  977. if (read_iir & CTRL_UL) {
  978. DBG1("CTRL_UL");
  979. dc->last_ier &= ~CTRL_UL;
  980. writew(dc->last_ier, dc->reg_ier);
  981. if (send_flow_control(dc)) {
  982. writew(CTRL_UL, dc->reg_fcr);
  983. dc->last_ier = dc->last_ier | CTRL_UL;
  984. writew(dc->last_ier, dc->reg_ier);
  985. }
  986. }
  987. if (read_iir & CTRL_DL) {
  988. receive_flow_control(dc);
  989. writew(CTRL_DL, dc->reg_fcr);
  990. }
  991. if (read_iir & MDM_DL) {
  992. if (!handle_data_dl(dc, PORT_MDM,
  993. &(dc->port[PORT_MDM].toggle_dl), read_iir,
  994. MDM_DL1, MDM_DL2)) {
  995. dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n");
  996. goto exit_handler;
  997. }
  998. }
  999. if (read_iir & MDM_UL) {
  1000. if (!handle_data_ul(dc, PORT_MDM, read_iir)) {
  1001. dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n");
  1002. goto exit_handler;
  1003. }
  1004. }
  1005. if (read_iir & DIAG_DL) {
  1006. if (!handle_data_dl(dc, PORT_DIAG,
  1007. &(dc->port[PORT_DIAG].toggle_dl), read_iir,
  1008. DIAG_DL1, DIAG_DL2)) {
  1009. dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n");
  1010. goto exit_handler;
  1011. }
  1012. }
  1013. if (read_iir & DIAG_UL) {
  1014. dc->last_ier &= ~DIAG_UL;
  1015. writew(dc->last_ier, dc->reg_ier);
  1016. if (send_data(PORT_DIAG, dc)) {
  1017. writew(DIAG_UL, dc->reg_fcr);
  1018. dc->last_ier = dc->last_ier | DIAG_UL;
  1019. writew(dc->last_ier, dc->reg_ier);
  1020. }
  1021. }
  1022. if (read_iir & APP1_DL) {
  1023. if (receive_data(PORT_APP1, dc))
  1024. writew(APP1_DL, dc->reg_fcr);
  1025. }
  1026. if (read_iir & APP1_UL) {
  1027. dc->last_ier &= ~APP1_UL;
  1028. writew(dc->last_ier, dc->reg_ier);
  1029. if (send_data(PORT_APP1, dc)) {
  1030. writew(APP1_UL, dc->reg_fcr);
  1031. dc->last_ier = dc->last_ier | APP1_UL;
  1032. writew(dc->last_ier, dc->reg_ier);
  1033. }
  1034. }
  1035. if (read_iir & APP2_DL) {
  1036. if (receive_data(PORT_APP2, dc))
  1037. writew(APP2_DL, dc->reg_fcr);
  1038. }
  1039. if (read_iir & APP2_UL) {
  1040. dc->last_ier &= ~APP2_UL;
  1041. writew(dc->last_ier, dc->reg_ier);
  1042. if (send_data(PORT_APP2, dc)) {
  1043. writew(APP2_UL, dc->reg_fcr);
  1044. dc->last_ier = dc->last_ier | APP2_UL;
  1045. writew(dc->last_ier, dc->reg_ier);
  1046. }
  1047. }
  1048. exit_handler:
  1049. spin_unlock(&dc->spin_mutex);
  1050. for (a = 0; a < NOZOMI_MAX_PORTS; a++)
  1051. if (test_and_clear_bit(a, &dc->flip))
  1052. tty_flip_buffer_push(&dc->port[a].port);
  1053. return IRQ_HANDLED;
  1054. none:
  1055. spin_unlock(&dc->spin_mutex);
  1056. return IRQ_NONE;
  1057. }
  1058. static void nozomi_get_card_type(struct nozomi *dc)
  1059. {
  1060. int i;
  1061. u32 size = 0;
  1062. for (i = 0; i < 6; i++)
  1063. size += pci_resource_len(dc->pdev, i);
  1064. /* Assume card type F32_8 if no match */
  1065. dc->card_type = size == 2048 ? F32_2 : F32_8;
  1066. dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type);
  1067. }
  1068. static void nozomi_setup_private_data(struct nozomi *dc)
  1069. {
  1070. void __iomem *offset = dc->base_addr + dc->card_type / 2;
  1071. unsigned int i;
  1072. dc->reg_fcr = (void __iomem *)(offset + R_FCR);
  1073. dc->reg_iir = (void __iomem *)(offset + R_IIR);
  1074. dc->reg_ier = (void __iomem *)(offset + R_IER);
  1075. dc->last_ier = 0;
  1076. dc->flip = 0;
  1077. dc->port[PORT_MDM].token_dl = MDM_DL;
  1078. dc->port[PORT_DIAG].token_dl = DIAG_DL;
  1079. dc->port[PORT_APP1].token_dl = APP1_DL;
  1080. dc->port[PORT_APP2].token_dl = APP2_DL;
  1081. for (i = 0; i < MAX_PORT; i++)
  1082. init_waitqueue_head(&dc->port[i].tty_wait);
  1083. }
  1084. static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
  1085. char *buf)
  1086. {
  1087. const struct nozomi *dc = dev_get_drvdata(dev);
  1088. return sprintf(buf, "%d\n", dc->card_type);
  1089. }
  1090. static DEVICE_ATTR_RO(card_type);
  1091. static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
  1092. char *buf)
  1093. {
  1094. const struct nozomi *dc = dev_get_drvdata(dev);
  1095. return sprintf(buf, "%u\n", dc->open_ttys);
  1096. }
  1097. static DEVICE_ATTR_RO(open_ttys);
  1098. static void make_sysfs_files(struct nozomi *dc)
  1099. {
  1100. if (device_create_file(&dc->pdev->dev, &dev_attr_card_type))
  1101. dev_err(&dc->pdev->dev,
  1102. "Could not create sysfs file for card_type\n");
  1103. if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys))
  1104. dev_err(&dc->pdev->dev,
  1105. "Could not create sysfs file for open_ttys\n");
  1106. }
  1107. static void remove_sysfs_files(struct nozomi *dc)
  1108. {
  1109. device_remove_file(&dc->pdev->dev, &dev_attr_card_type);
  1110. device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys);
  1111. }
  1112. /* Allocate memory for one device */
  1113. static int nozomi_card_init(struct pci_dev *pdev,
  1114. const struct pci_device_id *ent)
  1115. {
  1116. int ret;
  1117. struct nozomi *dc = NULL;
  1118. int ndev_idx;
  1119. int i;
  1120. for (ndev_idx = 0; ndev_idx < ARRAY_SIZE(ndevs); ndev_idx++)
  1121. if (!ndevs[ndev_idx])
  1122. break;
  1123. if (ndev_idx >= ARRAY_SIZE(ndevs)) {
  1124. dev_err(&pdev->dev, "no free tty range for this card left\n");
  1125. ret = -EIO;
  1126. goto err;
  1127. }
  1128. dc = kzalloc_obj(struct nozomi);
  1129. if (unlikely(!dc)) {
  1130. dev_err(&pdev->dev, "Could not allocate memory\n");
  1131. ret = -ENOMEM;
  1132. goto err_free;
  1133. }
  1134. dc->pdev = pdev;
  1135. ret = pci_enable_device(dc->pdev);
  1136. if (ret) {
  1137. dev_err(&pdev->dev, "Failed to enable PCI Device\n");
  1138. goto err_free;
  1139. }
  1140. ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
  1141. if (ret) {
  1142. dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
  1143. (int) /* nozomi_private.io_addr */ 0);
  1144. goto err_disable_device;
  1145. }
  1146. /* Find out what card type it is */
  1147. nozomi_get_card_type(dc);
  1148. dc->base_addr = pci_iomap(dc->pdev, 0, dc->card_type);
  1149. if (!dc->base_addr) {
  1150. dev_err(&pdev->dev, "Unable to map card MMIO\n");
  1151. ret = -ENODEV;
  1152. goto err_rel_regs;
  1153. }
  1154. dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
  1155. if (!dc->send_buf) {
  1156. dev_err(&pdev->dev, "Could not allocate send buffer?\n");
  1157. ret = -ENOMEM;
  1158. goto err_free_sbuf;
  1159. }
  1160. for (i = PORT_MDM; i < MAX_PORT; i++) {
  1161. if (kfifo_alloc(&dc->port[i].fifo_ul, FIFO_BUFFER_SIZE_UL,
  1162. GFP_KERNEL)) {
  1163. dev_err(&pdev->dev,
  1164. "Could not allocate kfifo buffer\n");
  1165. ret = -ENOMEM;
  1166. goto err_free_kfifo;
  1167. }
  1168. }
  1169. spin_lock_init(&dc->spin_mutex);
  1170. nozomi_setup_private_data(dc);
  1171. /* Disable all interrupts */
  1172. dc->last_ier = 0;
  1173. writew(dc->last_ier, dc->reg_ier);
  1174. ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED,
  1175. NOZOMI_NAME, dc);
  1176. if (unlikely(ret)) {
  1177. dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
  1178. goto err_free_all_kfifo;
  1179. }
  1180. DBG1("base_addr: %p", dc->base_addr);
  1181. make_sysfs_files(dc);
  1182. dc->index_start = ndev_idx * MAX_PORT;
  1183. ndevs[ndev_idx] = dc;
  1184. pci_set_drvdata(pdev, dc);
  1185. /* Enable RESET interrupt */
  1186. dc->last_ier = RESET;
  1187. iowrite16(dc->last_ier, dc->reg_ier);
  1188. dc->state = NOZOMI_STATE_ENABLED;
  1189. for (i = 0; i < MAX_PORT; i++) {
  1190. struct device *tty_dev;
  1191. struct port *port = &dc->port[i];
  1192. port->dc = dc;
  1193. tty_port_init(&port->port);
  1194. port->port.ops = &noz_tty_port_ops;
  1195. tty_dev = tty_port_register_device(&port->port, ntty_driver,
  1196. dc->index_start + i, &pdev->dev);
  1197. if (IS_ERR(tty_dev)) {
  1198. ret = PTR_ERR(tty_dev);
  1199. dev_err(&pdev->dev, "Could not allocate tty?\n");
  1200. tty_port_destroy(&port->port);
  1201. goto err_free_tty;
  1202. }
  1203. }
  1204. return 0;
  1205. err_free_tty:
  1206. for (i--; i >= 0; i--) {
  1207. tty_unregister_device(ntty_driver, dc->index_start + i);
  1208. tty_port_destroy(&dc->port[i].port);
  1209. }
  1210. free_irq(pdev->irq, dc);
  1211. err_free_all_kfifo:
  1212. i = MAX_PORT;
  1213. err_free_kfifo:
  1214. for (i--; i >= PORT_MDM; i--)
  1215. kfifo_free(&dc->port[i].fifo_ul);
  1216. err_free_sbuf:
  1217. kfree(dc->send_buf);
  1218. iounmap(dc->base_addr);
  1219. err_rel_regs:
  1220. pci_release_regions(pdev);
  1221. err_disable_device:
  1222. pci_disable_device(pdev);
  1223. err_free:
  1224. kfree(dc);
  1225. err:
  1226. return ret;
  1227. }
  1228. static void tty_exit(struct nozomi *dc)
  1229. {
  1230. unsigned int i;
  1231. for (i = 0; i < MAX_PORT; ++i)
  1232. tty_port_tty_hangup(&dc->port[i].port, false);
  1233. /* Racy below - surely should wait for scheduled work to be done or
  1234. complete off a hangup method ? */
  1235. while (dc->open_ttys)
  1236. msleep(1);
  1237. for (i = 0; i < MAX_PORT; ++i) {
  1238. tty_unregister_device(ntty_driver, dc->index_start + i);
  1239. tty_port_destroy(&dc->port[i].port);
  1240. }
  1241. }
  1242. /* Deallocate memory for one device */
  1243. static void nozomi_card_exit(struct pci_dev *pdev)
  1244. {
  1245. int i;
  1246. struct ctrl_ul ctrl;
  1247. struct nozomi *dc = pci_get_drvdata(pdev);
  1248. /* Disable all interrupts */
  1249. dc->last_ier = 0;
  1250. writew(dc->last_ier, dc->reg_ier);
  1251. tty_exit(dc);
  1252. /* Send 0x0001, command card to resend the reset token. */
  1253. /* This is to get the reset when the module is reloaded. */
  1254. ctrl.port = 0x00;
  1255. ctrl.reserved = 0;
  1256. ctrl.RTS = 0;
  1257. ctrl.DTR = 1;
  1258. DBG1("sending flow control 0x%04X", *((u16 *)&ctrl));
  1259. /* Setup dc->reg addresses to we can use defines here */
  1260. write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2);
  1261. writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */
  1262. remove_sysfs_files(dc);
  1263. free_irq(pdev->irq, dc);
  1264. for (i = 0; i < MAX_PORT; i++)
  1265. kfifo_free(&dc->port[i].fifo_ul);
  1266. kfree(dc->send_buf);
  1267. iounmap(dc->base_addr);
  1268. pci_release_regions(pdev);
  1269. pci_disable_device(pdev);
  1270. ndevs[dc->index_start / MAX_PORT] = NULL;
  1271. kfree(dc);
  1272. }
  1273. static void set_rts(const struct tty_struct *tty, int rts)
  1274. {
  1275. struct port *port = get_port_by_tty(tty);
  1276. port->ctrl_ul.RTS = rts;
  1277. port->update_flow_control = 1;
  1278. enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
  1279. }
  1280. static void set_dtr(const struct tty_struct *tty, int dtr)
  1281. {
  1282. struct port *port = get_port_by_tty(tty);
  1283. DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr);
  1284. port->ctrl_ul.DTR = dtr;
  1285. port->update_flow_control = 1;
  1286. enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
  1287. }
  1288. /*
  1289. * ----------------------------------------------------------------------------
  1290. * TTY code
  1291. * ----------------------------------------------------------------------------
  1292. */
  1293. static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
  1294. {
  1295. struct port *port = get_port_by_tty(tty);
  1296. struct nozomi *dc = get_dc_by_tty(tty);
  1297. int ret;
  1298. if (!port || !dc || dc->state != NOZOMI_STATE_READY)
  1299. return -ENODEV;
  1300. ret = tty_standard_install(driver, tty);
  1301. if (ret == 0)
  1302. tty->driver_data = port;
  1303. return ret;
  1304. }
  1305. static void ntty_cleanup(struct tty_struct *tty)
  1306. {
  1307. tty->driver_data = NULL;
  1308. }
  1309. static int ntty_activate(struct tty_port *tport, struct tty_struct *tty)
  1310. {
  1311. struct port *port = container_of(tport, struct port, port);
  1312. struct nozomi *dc = port->dc;
  1313. unsigned long flags;
  1314. DBG1("open: %d", port->token_dl);
  1315. spin_lock_irqsave(&dc->spin_mutex, flags);
  1316. dc->last_ier = dc->last_ier | port->token_dl;
  1317. writew(dc->last_ier, dc->reg_ier);
  1318. dc->open_ttys++;
  1319. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1320. printk("noz: activated %d: %p\n", tty->index, tport);
  1321. return 0;
  1322. }
  1323. static int ntty_open(struct tty_struct *tty, struct file *filp)
  1324. {
  1325. struct port *port = tty->driver_data;
  1326. return tty_port_open(&port->port, tty, filp);
  1327. }
  1328. static void ntty_shutdown(struct tty_port *tport)
  1329. {
  1330. struct port *port = container_of(tport, struct port, port);
  1331. struct nozomi *dc = port->dc;
  1332. unsigned long flags;
  1333. DBG1("close: %d", port->token_dl);
  1334. spin_lock_irqsave(&dc->spin_mutex, flags);
  1335. dc->last_ier &= ~(port->token_dl);
  1336. writew(dc->last_ier, dc->reg_ier);
  1337. dc->open_ttys--;
  1338. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1339. printk("noz: shutdown %p\n", tport);
  1340. }
  1341. static void ntty_close(struct tty_struct *tty, struct file *filp)
  1342. {
  1343. struct port *port = tty->driver_data;
  1344. if (port)
  1345. tty_port_close(&port->port, tty, filp);
  1346. }
  1347. static void ntty_hangup(struct tty_struct *tty)
  1348. {
  1349. struct port *port = tty->driver_data;
  1350. tty_port_hangup(&port->port);
  1351. }
  1352. /*
  1353. * called when the userspace process writes to the tty (/dev/noz*).
  1354. * Data is inserted into a fifo, which is then read and transferred to the modem.
  1355. */
  1356. static ssize_t ntty_write(struct tty_struct *tty, const u8 *buffer,
  1357. size_t count)
  1358. {
  1359. struct nozomi *dc = get_dc_by_tty(tty);
  1360. struct port *port = tty->driver_data;
  1361. unsigned long flags;
  1362. size_t rval;
  1363. if (!dc || !port)
  1364. return -ENODEV;
  1365. rval = kfifo_in(&port->fifo_ul, buffer, count);
  1366. spin_lock_irqsave(&dc->spin_mutex, flags);
  1367. /* CTS is only valid on the modem channel */
  1368. if (port == &(dc->port[PORT_MDM])) {
  1369. if (port->ctrl_dl.CTS) {
  1370. DBG4("Enable interrupt");
  1371. enable_transmit_ul(tty->index % MAX_PORT, dc);
  1372. } else {
  1373. dev_err(&dc->pdev->dev,
  1374. "CTS not active on modem port?\n");
  1375. }
  1376. } else {
  1377. enable_transmit_ul(tty->index % MAX_PORT, dc);
  1378. }
  1379. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1380. return rval;
  1381. }
  1382. /*
  1383. * Calculate how much is left in device
  1384. * This method is called by the upper tty layer.
  1385. * #according to sources N_TTY.c it expects a value >= 0 and
  1386. * does not check for negative values.
  1387. *
  1388. * If the port is unplugged report lots of room and let the bits
  1389. * dribble away so we don't block anything.
  1390. */
  1391. static unsigned int ntty_write_room(struct tty_struct *tty)
  1392. {
  1393. struct port *port = tty->driver_data;
  1394. unsigned int room = 4096;
  1395. const struct nozomi *dc = get_dc_by_tty(tty);
  1396. if (dc)
  1397. room = kfifo_avail(&port->fifo_ul);
  1398. return room;
  1399. }
  1400. /* Gets io control parameters */
  1401. static int ntty_tiocmget(struct tty_struct *tty)
  1402. {
  1403. const struct port *port = tty->driver_data;
  1404. const struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
  1405. const struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
  1406. /* Note: these could change under us but it is not clear this
  1407. matters if so */
  1408. return (ctrl_ul->RTS ? TIOCM_RTS : 0)
  1409. | (ctrl_ul->DTR ? TIOCM_DTR : 0)
  1410. | (ctrl_dl->DCD ? TIOCM_CAR : 0)
  1411. | (ctrl_dl->RI ? TIOCM_RNG : 0)
  1412. | (ctrl_dl->DSR ? TIOCM_DSR : 0)
  1413. | (ctrl_dl->CTS ? TIOCM_CTS : 0);
  1414. }
  1415. /* Sets io controls parameters */
  1416. static int ntty_tiocmset(struct tty_struct *tty,
  1417. unsigned int set, unsigned int clear)
  1418. {
  1419. struct nozomi *dc = get_dc_by_tty(tty);
  1420. unsigned long flags;
  1421. spin_lock_irqsave(&dc->spin_mutex, flags);
  1422. if (set & TIOCM_RTS)
  1423. set_rts(tty, 1);
  1424. else if (clear & TIOCM_RTS)
  1425. set_rts(tty, 0);
  1426. if (set & TIOCM_DTR)
  1427. set_dtr(tty, 1);
  1428. else if (clear & TIOCM_DTR)
  1429. set_dtr(tty, 0);
  1430. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1431. return 0;
  1432. }
  1433. static int ntty_cflags_changed(struct port *port, unsigned long flags,
  1434. struct async_icount *cprev)
  1435. {
  1436. const struct async_icount cnow = port->tty_icount;
  1437. int ret;
  1438. ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng))
  1439. || ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr))
  1440. || ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd))
  1441. || ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
  1442. *cprev = cnow;
  1443. return ret;
  1444. }
  1445. static int ntty_tiocgicount(struct tty_struct *tty,
  1446. struct serial_icounter_struct *icount)
  1447. {
  1448. struct port *port = tty->driver_data;
  1449. const struct async_icount cnow = port->tty_icount;
  1450. icount->cts = cnow.cts;
  1451. icount->dsr = cnow.dsr;
  1452. icount->rng = cnow.rng;
  1453. icount->dcd = cnow.dcd;
  1454. icount->rx = cnow.rx;
  1455. icount->tx = cnow.tx;
  1456. icount->frame = cnow.frame;
  1457. icount->overrun = cnow.overrun;
  1458. icount->parity = cnow.parity;
  1459. icount->brk = cnow.brk;
  1460. icount->buf_overrun = cnow.buf_overrun;
  1461. return 0;
  1462. }
  1463. static int ntty_ioctl(struct tty_struct *tty,
  1464. unsigned int cmd, unsigned long arg)
  1465. {
  1466. struct port *port = tty->driver_data;
  1467. int rval = -ENOIOCTLCMD;
  1468. switch (cmd) {
  1469. case TIOCMIWAIT: {
  1470. struct async_icount cprev = port->tty_icount;
  1471. rval = wait_event_interruptible(port->tty_wait,
  1472. ntty_cflags_changed(port, arg, &cprev));
  1473. break;
  1474. }
  1475. default:
  1476. DBG1("ERR: 0x%08X, %d", cmd, cmd);
  1477. break;
  1478. }
  1479. return rval;
  1480. }
  1481. /*
  1482. * Called by the upper tty layer when tty buffers are ready
  1483. * to receive data again after a call to throttle.
  1484. */
  1485. static void ntty_unthrottle(struct tty_struct *tty)
  1486. {
  1487. struct nozomi *dc = get_dc_by_tty(tty);
  1488. unsigned long flags;
  1489. spin_lock_irqsave(&dc->spin_mutex, flags);
  1490. enable_transmit_dl(tty->index % MAX_PORT, dc);
  1491. set_rts(tty, 1);
  1492. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1493. }
  1494. /*
  1495. * Called by the upper tty layer when the tty buffers are almost full.
  1496. * The driver should stop send more data.
  1497. */
  1498. static void ntty_throttle(struct tty_struct *tty)
  1499. {
  1500. struct nozomi *dc = get_dc_by_tty(tty);
  1501. unsigned long flags;
  1502. spin_lock_irqsave(&dc->spin_mutex, flags);
  1503. set_rts(tty, 0);
  1504. spin_unlock_irqrestore(&dc->spin_mutex, flags);
  1505. }
  1506. /* Returns number of chars in buffer, called by tty layer */
  1507. static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
  1508. {
  1509. struct port *port = tty->driver_data;
  1510. struct nozomi *dc = get_dc_by_tty(tty);
  1511. if (unlikely(!dc || !port))
  1512. return 0;
  1513. return kfifo_len(&port->fifo_ul);
  1514. }
  1515. static const struct tty_port_operations noz_tty_port_ops = {
  1516. .activate = ntty_activate,
  1517. .shutdown = ntty_shutdown,
  1518. };
  1519. static const struct tty_operations tty_ops = {
  1520. .ioctl = ntty_ioctl,
  1521. .open = ntty_open,
  1522. .close = ntty_close,
  1523. .hangup = ntty_hangup,
  1524. .write = ntty_write,
  1525. .write_room = ntty_write_room,
  1526. .unthrottle = ntty_unthrottle,
  1527. .throttle = ntty_throttle,
  1528. .chars_in_buffer = ntty_chars_in_buffer,
  1529. .tiocmget = ntty_tiocmget,
  1530. .tiocmset = ntty_tiocmset,
  1531. .get_icount = ntty_tiocgicount,
  1532. .install = ntty_install,
  1533. .cleanup = ntty_cleanup,
  1534. };
  1535. /* Module initialization */
  1536. static struct pci_driver nozomi_driver = {
  1537. .name = NOZOMI_NAME,
  1538. .id_table = nozomi_pci_tbl,
  1539. .probe = nozomi_card_init,
  1540. .remove = nozomi_card_exit,
  1541. };
  1542. static __init int nozomi_init(void)
  1543. {
  1544. int ret;
  1545. ntty_driver = tty_alloc_driver(NTTY_TTY_MAXMINORS, TTY_DRIVER_REAL_RAW |
  1546. TTY_DRIVER_DYNAMIC_DEV);
  1547. if (IS_ERR(ntty_driver))
  1548. return PTR_ERR(ntty_driver);
  1549. ntty_driver->driver_name = NOZOMI_NAME_TTY;
  1550. ntty_driver->name = "noz";
  1551. ntty_driver->major = 0;
  1552. ntty_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1553. ntty_driver->subtype = SERIAL_TYPE_NORMAL;
  1554. ntty_driver->init_termios = tty_std_termios;
  1555. ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \
  1556. HUPCL | CLOCAL;
  1557. ntty_driver->init_termios.c_ispeed = 115200;
  1558. ntty_driver->init_termios.c_ospeed = 115200;
  1559. tty_set_operations(ntty_driver, &tty_ops);
  1560. ret = tty_register_driver(ntty_driver);
  1561. if (ret) {
  1562. printk(KERN_ERR "Nozomi: failed to register ntty driver\n");
  1563. goto free_tty;
  1564. }
  1565. ret = pci_register_driver(&nozomi_driver);
  1566. if (ret) {
  1567. printk(KERN_ERR "Nozomi: can't register pci driver\n");
  1568. goto unr_tty;
  1569. }
  1570. return 0;
  1571. unr_tty:
  1572. tty_unregister_driver(ntty_driver);
  1573. free_tty:
  1574. tty_driver_kref_put(ntty_driver);
  1575. return ret;
  1576. }
  1577. static __exit void nozomi_exit(void)
  1578. {
  1579. pci_unregister_driver(&nozomi_driver);
  1580. tty_unregister_driver(ntty_driver);
  1581. tty_driver_kref_put(ntty_driver);
  1582. }
  1583. module_init(nozomi_init);
  1584. module_exit(nozomi_exit);
  1585. MODULE_LICENSE("Dual BSD/GPL");
  1586. MODULE_DESCRIPTION("Nozomi driver");