cxacru.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /******************************************************************************
  2. * cxacru.c - driver for USB ADSL modems based on
  3. * Conexant AccessRunner chipset
  4. *
  5. * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
  6. * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
  7. * Copyright (C) 2007 Simon Arlott
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. ******************************************************************************/
  24. /*
  25. * Credit is due for Josep Comas, who created the original patch to speedtch.c
  26. * to support the different padding used by the AccessRunner (now generalized
  27. * into usbatm), and the userspace firmware loading utility.
  28. */
  29. #include <linux/module.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/kernel.h>
  32. #include <linux/timer.h>
  33. #include <linux/errno.h>
  34. #include <linux/slab.h>
  35. #include <linux/init.h>
  36. #include <linux/device.h>
  37. #include <linux/firmware.h>
  38. #include <linux/mutex.h>
  39. #include "usbatm.h"
  40. #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
  41. #define DRIVER_VERSION "0.3"
  42. #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
  43. static const char cxacru_driver_name[] = "cxacru";
  44. #define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
  45. #define CXACRU_EP_DATA 0x02 /* Bulk in/out */
  46. #define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
  47. /* Addresses */
  48. #define PLLFCLK_ADDR 0x00350068
  49. #define PLLBCLK_ADDR 0x0035006c
  50. #define SDRAMEN_ADDR 0x00350010
  51. #define FW_ADDR 0x00801000
  52. #define BR_ADDR 0x00180600
  53. #define SIG_ADDR 0x00180500
  54. #define BR_STACK_ADDR 0x00187f10
  55. /* Values */
  56. #define SDRAM_ENA 0x1
  57. #define CMD_TIMEOUT 2000 /* msecs */
  58. #define POLL_INTERVAL 1 /* secs */
  59. /* commands for interaction with the modem through the control channel before
  60. * firmware is loaded */
  61. enum cxacru_fw_request {
  62. FW_CMD_ERR,
  63. FW_GET_VER,
  64. FW_READ_MEM,
  65. FW_WRITE_MEM,
  66. FW_RMW_MEM,
  67. FW_CHECKSUM_MEM,
  68. FW_GOTO_MEM,
  69. };
  70. /* commands for interaction with the modem through the control channel once
  71. * firmware is loaded */
  72. enum cxacru_cm_request {
  73. CM_REQUEST_UNDEFINED = 0x80,
  74. CM_REQUEST_TEST,
  75. CM_REQUEST_CHIP_GET_MAC_ADDRESS,
  76. CM_REQUEST_CHIP_GET_DP_VERSIONS,
  77. CM_REQUEST_CHIP_ADSL_LINE_START,
  78. CM_REQUEST_CHIP_ADSL_LINE_STOP,
  79. CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
  80. CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
  81. CM_REQUEST_CARD_INFO_GET,
  82. CM_REQUEST_CARD_DATA_GET,
  83. CM_REQUEST_CARD_DATA_SET,
  84. CM_REQUEST_COMMAND_HW_IO,
  85. CM_REQUEST_INTERFACE_HW_IO,
  86. CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
  87. CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
  88. CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
  89. CM_REQUEST_CARD_GET_STATUS,
  90. CM_REQUEST_CARD_GET_MAC_ADDRESS,
  91. CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
  92. CM_REQUEST_MAX,
  93. };
  94. /* reply codes to the commands above */
  95. enum cxacru_cm_status {
  96. CM_STATUS_UNDEFINED,
  97. CM_STATUS_SUCCESS,
  98. CM_STATUS_ERROR,
  99. CM_STATUS_UNSUPPORTED,
  100. CM_STATUS_UNIMPLEMENTED,
  101. CM_STATUS_PARAMETER_ERROR,
  102. CM_STATUS_DBG_LOOPBACK,
  103. CM_STATUS_MAX,
  104. };
  105. /* indices into CARD_INFO_GET return array */
  106. enum cxacru_info_idx {
  107. CXINF_DOWNSTREAM_RATE,
  108. CXINF_UPSTREAM_RATE,
  109. CXINF_LINK_STATUS,
  110. CXINF_LINE_STATUS,
  111. CXINF_MAC_ADDRESS_HIGH,
  112. CXINF_MAC_ADDRESS_LOW,
  113. CXINF_UPSTREAM_SNR_MARGIN,
  114. CXINF_DOWNSTREAM_SNR_MARGIN,
  115. CXINF_UPSTREAM_ATTENUATION,
  116. CXINF_DOWNSTREAM_ATTENUATION,
  117. CXINF_TRANSMITTER_POWER,
  118. CXINF_UPSTREAM_BITS_PER_FRAME,
  119. CXINF_DOWNSTREAM_BITS_PER_FRAME,
  120. CXINF_STARTUP_ATTEMPTS,
  121. CXINF_UPSTREAM_CRC_ERRORS,
  122. CXINF_DOWNSTREAM_CRC_ERRORS,
  123. CXINF_UPSTREAM_FEC_ERRORS,
  124. CXINF_DOWNSTREAM_FEC_ERRORS,
  125. CXINF_UPSTREAM_HEC_ERRORS,
  126. CXINF_DOWNSTREAM_HEC_ERRORS,
  127. CXINF_LINE_STARTABLE,
  128. CXINF_MODULATION,
  129. CXINF_ADSL_HEADEND,
  130. CXINF_ADSL_HEADEND_ENVIRONMENT,
  131. CXINF_CONTROLLER_VERSION,
  132. /* dunno what the missing two mean */
  133. CXINF_MAX = 0x1c,
  134. };
  135. enum cxacru_poll_state {
  136. CXPOLL_STOPPING,
  137. CXPOLL_STOPPED,
  138. CXPOLL_POLLING,
  139. CXPOLL_SHUTDOWN
  140. };
  141. struct cxacru_modem_type {
  142. u32 pll_f_clk;
  143. u32 pll_b_clk;
  144. int boot_rom_patch;
  145. };
  146. struct cxacru_data {
  147. struct usbatm_data *usbatm;
  148. const struct cxacru_modem_type *modem_type;
  149. int line_status;
  150. struct mutex adsl_state_serialize;
  151. int adsl_status;
  152. struct delayed_work poll_work;
  153. u32 card_info[CXINF_MAX];
  154. struct mutex poll_state_serialize;
  155. enum cxacru_poll_state poll_state;
  156. /* contol handles */
  157. struct mutex cm_serialize;
  158. u8 *rcv_buf;
  159. u8 *snd_buf;
  160. struct urb *rcv_urb;
  161. struct urb *snd_urb;
  162. struct completion rcv_done;
  163. struct completion snd_done;
  164. };
  165. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  166. u8 *wdata, int wsize, u8 *rdata, int rsize);
  167. static void cxacru_poll_status(struct work_struct *work);
  168. /* Card info exported through sysfs */
  169. #define CXACRU__ATTR_INIT(_name) \
  170. static DEVICE_ATTR(_name, S_IRUGO, cxacru_sysfs_show_##_name, NULL)
  171. #define CXACRU_CMD_INIT(_name) \
  172. static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \
  173. cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name)
  174. #define CXACRU_ATTR_INIT(_value, _type, _name) \
  175. static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \
  176. struct device_attribute *attr, char *buf) \
  177. { \
  178. struct usb_interface *intf = to_usb_interface(dev); \
  179. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); \
  180. struct cxacru_data *instance = usbatm_instance->driver_data; \
  181. return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \
  182. } \
  183. CXACRU__ATTR_INIT(_name)
  184. #define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name)
  185. #define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
  186. #define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
  187. #define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name)
  188. #define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
  189. #define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
  190. static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
  191. {
  192. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  193. }
  194. static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
  195. {
  196. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  197. }
  198. static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
  199. {
  200. return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
  201. value / 100, abs(value) % 100);
  202. }
  203. static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
  204. {
  205. static char *str[] = { "no", "yes" };
  206. if (unlikely(value >= ARRAY_SIZE(str)))
  207. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  208. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  209. }
  210. static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
  211. {
  212. static char *str[] = { NULL, "not connected", "connected", "lost" };
  213. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  214. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  215. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  216. }
  217. static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
  218. {
  219. static char *str[] = { "down", "attempting to activate",
  220. "training", "channel analysis", "exchange", "up",
  221. "waiting", "initialising"
  222. };
  223. if (unlikely(value >= ARRAY_SIZE(str)))
  224. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  225. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  226. }
  227. static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
  228. {
  229. static char *str[] = {
  230. NULL,
  231. "ANSI T1.413",
  232. "ITU-T G.992.1 (G.DMT)",
  233. "ITU-T G.992.2 (G.LITE)"
  234. };
  235. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  236. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  237. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  238. }
  239. /*
  240. * This could use MAC_ADDRESS_HIGH and MAC_ADDRESS_LOW, but since
  241. * this data is already in atm_dev there's no point.
  242. *
  243. * MAC_ADDRESS_HIGH = 0x????5544
  244. * MAC_ADDRESS_LOW = 0x33221100
  245. * Where 00-55 are bytes 0-5 of the MAC.
  246. */
  247. static ssize_t cxacru_sysfs_show_mac_address(struct device *dev,
  248. struct device_attribute *attr, char *buf)
  249. {
  250. struct usb_interface *intf = to_usb_interface(dev);
  251. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  252. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  253. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  254. atm_dev->esi[0], atm_dev->esi[1], atm_dev->esi[2],
  255. atm_dev->esi[3], atm_dev->esi[4], atm_dev->esi[5]);
  256. }
  257. static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
  258. struct device_attribute *attr, char *buf)
  259. {
  260. struct usb_interface *intf = to_usb_interface(dev);
  261. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  262. struct cxacru_data *instance = usbatm_instance->driver_data;
  263. u32 value = instance->card_info[CXINF_LINE_STARTABLE];
  264. static char *str[] = { "running", "stopped" };
  265. if (unlikely(value >= ARRAY_SIZE(str)))
  266. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  267. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  268. }
  269. static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
  270. struct device_attribute *attr, const char *buf, size_t count)
  271. {
  272. struct usb_interface *intf = to_usb_interface(dev);
  273. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  274. struct cxacru_data *instance = usbatm_instance->driver_data;
  275. int ret;
  276. int poll = -1;
  277. char str_cmd[8];
  278. int len = strlen(buf);
  279. if (!capable(CAP_NET_ADMIN))
  280. return -EACCES;
  281. ret = sscanf(buf, "%7s", str_cmd);
  282. if (ret != 1)
  283. return -EINVAL;
  284. ret = 0;
  285. if (mutex_lock_interruptible(&instance->adsl_state_serialize))
  286. return -ERESTARTSYS;
  287. if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) {
  288. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
  289. if (ret < 0) {
  290. atm_err(usbatm_instance, "change adsl state:"
  291. " CHIP_ADSL_LINE_STOP returned %d\n", ret);
  292. ret = -EIO;
  293. } else {
  294. ret = len;
  295. poll = CXPOLL_STOPPED;
  296. }
  297. }
  298. /* Line status is only updated every second
  299. * and the device appears to only react to
  300. * START/STOP every second too. Wait 1.5s to
  301. * be sure that restart will have an effect. */
  302. if (!strcmp(str_cmd, "restart"))
  303. msleep(1500);
  304. if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) {
  305. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  306. if (ret < 0) {
  307. atm_err(usbatm_instance, "change adsl state:"
  308. " CHIP_ADSL_LINE_START returned %d\n", ret);
  309. ret = -EIO;
  310. } else {
  311. ret = len;
  312. poll = CXPOLL_POLLING;
  313. }
  314. }
  315. if (!strcmp(str_cmd, "poll")) {
  316. ret = len;
  317. poll = CXPOLL_POLLING;
  318. }
  319. if (ret == 0) {
  320. ret = -EINVAL;
  321. poll = -1;
  322. }
  323. if (poll == CXPOLL_POLLING) {
  324. mutex_lock(&instance->poll_state_serialize);
  325. switch (instance->poll_state) {
  326. case CXPOLL_STOPPED:
  327. /* start polling */
  328. instance->poll_state = CXPOLL_POLLING;
  329. break;
  330. case CXPOLL_STOPPING:
  331. /* abort stop request */
  332. instance->poll_state = CXPOLL_POLLING;
  333. case CXPOLL_POLLING:
  334. case CXPOLL_SHUTDOWN:
  335. /* don't start polling */
  336. poll = -1;
  337. }
  338. mutex_unlock(&instance->poll_state_serialize);
  339. } else if (poll == CXPOLL_STOPPED) {
  340. mutex_lock(&instance->poll_state_serialize);
  341. /* request stop */
  342. if (instance->poll_state == CXPOLL_POLLING)
  343. instance->poll_state = CXPOLL_STOPPING;
  344. mutex_unlock(&instance->poll_state_serialize);
  345. }
  346. mutex_unlock(&instance->adsl_state_serialize);
  347. if (poll == CXPOLL_POLLING)
  348. cxacru_poll_status(&instance->poll_work.work);
  349. return ret;
  350. }
  351. /*
  352. * All device attributes are included in CXACRU_ALL_FILES
  353. * so that the same list can be used multiple times:
  354. * INIT (define the device attributes)
  355. * CREATE (create all the device files)
  356. * REMOVE (remove all the device files)
  357. *
  358. * With the last two being defined as needed in the functions
  359. * they are used in before calling CXACRU_ALL_FILES()
  360. */
  361. #define CXACRU_ALL_FILES(_action) \
  362. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE, u32, downstream_rate); \
  363. CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE, u32, upstream_rate); \
  364. CXACRU_ATTR_##_action(CXINF_LINK_STATUS, LINK, link_status); \
  365. CXACRU_ATTR_##_action(CXINF_LINE_STATUS, LINE, line_status); \
  366. CXACRU__ATTR_##_action( mac_address); \
  367. CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN, dB, upstream_snr_margin); \
  368. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN, dB, downstream_snr_margin); \
  369. CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION, dB, upstream_attenuation); \
  370. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION, dB, downstream_attenuation); \
  371. CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER, s8, transmitter_power); \
  372. CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME, u32, upstream_bits_per_frame); \
  373. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32, downstream_bits_per_frame); \
  374. CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS, u32, startup_attempts); \
  375. CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS, u32, upstream_crc_errors); \
  376. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS, u32, downstream_crc_errors); \
  377. CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS, u32, upstream_fec_errors); \
  378. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS, u32, downstream_fec_errors); \
  379. CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS, u32, upstream_hec_errors); \
  380. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS, u32, downstream_hec_errors); \
  381. CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE, bool, line_startable); \
  382. CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \
  383. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \
  384. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \
  385. CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \
  386. CXACRU_CMD_##_action( adsl_state);
  387. CXACRU_ALL_FILES(INIT);
  388. /* the following three functions are stolen from drivers/usb/core/message.c */
  389. static void cxacru_blocking_completion(struct urb *urb)
  390. {
  391. complete((struct completion *)urb->context);
  392. }
  393. static void cxacru_timeout_kill(unsigned long data)
  394. {
  395. usb_unlink_urb((struct urb *) data);
  396. }
  397. static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
  398. int* actual_length)
  399. {
  400. struct timer_list timer;
  401. int status;
  402. init_timer(&timer);
  403. timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
  404. timer.data = (unsigned long) urb;
  405. timer.function = cxacru_timeout_kill;
  406. add_timer(&timer);
  407. wait_for_completion(done);
  408. status = urb->status;
  409. del_timer_sync(&timer);
  410. if (actual_length)
  411. *actual_length = urb->actual_length;
  412. return status;
  413. }
  414. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  415. u8 *wdata, int wsize, u8 *rdata, int rsize)
  416. {
  417. int ret, actlen;
  418. int offb, offd;
  419. const int stride = CMD_PACKET_SIZE - 4;
  420. u8 *wbuf = instance->snd_buf;
  421. u8 *rbuf = instance->rcv_buf;
  422. int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  423. int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  424. if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
  425. dbg("too big transfer requested");
  426. ret = -ENOMEM;
  427. goto fail;
  428. }
  429. mutex_lock(&instance->cm_serialize);
  430. /* submit reading urb before the writing one */
  431. init_completion(&instance->rcv_done);
  432. ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
  433. if (ret < 0) {
  434. dbg("submitting read urb for cm %#x failed", cm);
  435. ret = ret;
  436. goto fail;
  437. }
  438. memset(wbuf, 0, wbuflen);
  439. /* handle wsize == 0 */
  440. wbuf[0] = cm;
  441. for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
  442. wbuf[offb] = cm;
  443. memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
  444. }
  445. instance->snd_urb->transfer_buffer_length = wbuflen;
  446. init_completion(&instance->snd_done);
  447. ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
  448. if (ret < 0) {
  449. dbg("submitting write urb for cm %#x failed", cm);
  450. ret = ret;
  451. goto fail;
  452. }
  453. ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
  454. if (ret < 0) {
  455. dbg("sending cm %#x failed", cm);
  456. ret = ret;
  457. goto fail;
  458. }
  459. ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
  460. if (ret < 0) {
  461. dbg("receiving cm %#x failed", cm);
  462. ret = ret;
  463. goto fail;
  464. }
  465. if (actlen % CMD_PACKET_SIZE || !actlen) {
  466. dbg("response is not a positive multiple of %d: %#x",
  467. CMD_PACKET_SIZE, actlen);
  468. ret = -EIO;
  469. goto fail;
  470. }
  471. /* check the return status and copy the data to the output buffer, if needed */
  472. for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
  473. if (rbuf[offb] != cm) {
  474. dbg("wrong cm %#x in response", rbuf[offb]);
  475. ret = -EIO;
  476. goto fail;
  477. }
  478. if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
  479. dbg("response failed: %#x", rbuf[offb + 1]);
  480. ret = -EIO;
  481. goto fail;
  482. }
  483. if (offd >= rsize)
  484. break;
  485. memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
  486. offd += stride;
  487. }
  488. ret = offd;
  489. dbg("cm %#x", cm);
  490. fail:
  491. mutex_unlock(&instance->cm_serialize);
  492. return ret;
  493. }
  494. static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
  495. u32 *data, int size)
  496. {
  497. int ret, len;
  498. u32 *buf;
  499. int offb, offd;
  500. const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
  501. int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
  502. buf = kmalloc(buflen, GFP_KERNEL);
  503. if (!buf)
  504. return -ENOMEM;
  505. ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
  506. if (ret < 0)
  507. goto cleanup;
  508. /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
  509. len = ret / 4;
  510. for (offb = 0; offb < len; ) {
  511. int l = le32_to_cpu(buf[offb++]);
  512. if (l > stride || l > (len - offb) / 2) {
  513. dbg("wrong data length %#x in response", l);
  514. ret = -EIO;
  515. goto cleanup;
  516. }
  517. while (l--) {
  518. offd = le32_to_cpu(buf[offb++]);
  519. if (offd >= size) {
  520. dbg("wrong index %#x in response", offd);
  521. ret = -EIO;
  522. goto cleanup;
  523. }
  524. data[offd] = le32_to_cpu(buf[offb++]);
  525. }
  526. }
  527. ret = 0;
  528. cleanup:
  529. kfree(buf);
  530. return ret;
  531. }
  532. static int cxacru_card_status(struct cxacru_data *instance)
  533. {
  534. int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  535. if (ret < 0) { /* firmware not loaded */
  536. dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
  537. return ret;
  538. }
  539. return 0;
  540. }
  541. static void cxacru_remove_device_files(struct usbatm_data *usbatm_instance,
  542. struct atm_dev *atm_dev)
  543. {
  544. struct usb_interface *intf = usbatm_instance->usb_intf;
  545. #define CXACRU_DEVICE_REMOVE_FILE(_name) \
  546. device_remove_file(&intf->dev, &dev_attr_##_name);
  547. CXACRU_ALL_FILES(REMOVE);
  548. #undef CXACRU_DEVICE_REMOVE_FILE
  549. }
  550. static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
  551. struct atm_dev *atm_dev)
  552. {
  553. struct cxacru_data *instance = usbatm_instance->driver_data;
  554. struct usb_interface *intf = usbatm_instance->usb_intf;
  555. /*
  556. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  557. */
  558. int ret;
  559. int start_polling = 1;
  560. dbg("cxacru_atm_start");
  561. /* Read MAC address */
  562. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
  563. atm_dev->esi, sizeof(atm_dev->esi));
  564. if (ret < 0) {
  565. atm_err(usbatm_instance, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
  566. return ret;
  567. }
  568. #define CXACRU_DEVICE_CREATE_FILE(_name) \
  569. ret = device_create_file(&intf->dev, &dev_attr_##_name); \
  570. if (unlikely(ret)) \
  571. goto fail_sysfs;
  572. CXACRU_ALL_FILES(CREATE);
  573. #undef CXACRU_DEVICE_CREATE_FILE
  574. /* start ADSL */
  575. mutex_lock(&instance->adsl_state_serialize);
  576. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  577. if (ret < 0)
  578. atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
  579. /* Start status polling */
  580. mutex_lock(&instance->poll_state_serialize);
  581. switch (instance->poll_state) {
  582. case CXPOLL_STOPPED:
  583. /* start polling */
  584. instance->poll_state = CXPOLL_POLLING;
  585. break;
  586. case CXPOLL_STOPPING:
  587. /* abort stop request */
  588. instance->poll_state = CXPOLL_POLLING;
  589. case CXPOLL_POLLING:
  590. case CXPOLL_SHUTDOWN:
  591. /* don't start polling */
  592. start_polling = 0;
  593. }
  594. mutex_unlock(&instance->poll_state_serialize);
  595. mutex_unlock(&instance->adsl_state_serialize);
  596. if (start_polling)
  597. cxacru_poll_status(&instance->poll_work.work);
  598. return 0;
  599. fail_sysfs:
  600. usb_err(usbatm_instance, "cxacru_atm_start: device_create_file failed (%d)\n", ret);
  601. cxacru_remove_device_files(usbatm_instance, atm_dev);
  602. return ret;
  603. }
  604. static void cxacru_poll_status(struct work_struct *work)
  605. {
  606. struct cxacru_data *instance =
  607. container_of(work, struct cxacru_data, poll_work.work);
  608. u32 buf[CXINF_MAX] = {};
  609. struct usbatm_data *usbatm = instance->usbatm;
  610. struct atm_dev *atm_dev = usbatm->atm_dev;
  611. int keep_polling = 1;
  612. int ret;
  613. ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
  614. if (ret < 0) {
  615. if (ret != -ESHUTDOWN)
  616. atm_warn(usbatm, "poll status: error %d\n", ret);
  617. mutex_lock(&instance->poll_state_serialize);
  618. if (instance->poll_state != CXPOLL_SHUTDOWN) {
  619. instance->poll_state = CXPOLL_STOPPED;
  620. if (ret != -ESHUTDOWN)
  621. atm_warn(usbatm, "polling disabled, set adsl_state"
  622. " to 'start' or 'poll' to resume\n");
  623. }
  624. mutex_unlock(&instance->poll_state_serialize);
  625. goto reschedule;
  626. }
  627. memcpy(instance->card_info, buf, sizeof(instance->card_info));
  628. if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) {
  629. instance->adsl_status = buf[CXINF_LINE_STARTABLE];
  630. switch (instance->adsl_status) {
  631. case 0:
  632. atm_printk(KERN_INFO, usbatm, "ADSL state: running\n");
  633. break;
  634. case 1:
  635. atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n");
  636. break;
  637. default:
  638. atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status);
  639. break;
  640. }
  641. }
  642. if (instance->line_status == buf[CXINF_LINE_STATUS])
  643. goto reschedule;
  644. instance->line_status = buf[CXINF_LINE_STATUS];
  645. switch (instance->line_status) {
  646. case 0:
  647. atm_dev->signal = ATM_PHY_SIG_LOST;
  648. atm_info(usbatm, "ADSL line: down\n");
  649. break;
  650. case 1:
  651. atm_dev->signal = ATM_PHY_SIG_LOST;
  652. atm_info(usbatm, "ADSL line: attempting to activate\n");
  653. break;
  654. case 2:
  655. atm_dev->signal = ATM_PHY_SIG_LOST;
  656. atm_info(usbatm, "ADSL line: training\n");
  657. break;
  658. case 3:
  659. atm_dev->signal = ATM_PHY_SIG_LOST;
  660. atm_info(usbatm, "ADSL line: channel analysis\n");
  661. break;
  662. case 4:
  663. atm_dev->signal = ATM_PHY_SIG_LOST;
  664. atm_info(usbatm, "ADSL line: exchange\n");
  665. break;
  666. case 5:
  667. atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
  668. atm_dev->signal = ATM_PHY_SIG_FOUND;
  669. atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
  670. buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
  671. break;
  672. case 6:
  673. atm_dev->signal = ATM_PHY_SIG_LOST;
  674. atm_info(usbatm, "ADSL line: waiting\n");
  675. break;
  676. case 7:
  677. atm_dev->signal = ATM_PHY_SIG_LOST;
  678. atm_info(usbatm, "ADSL line: initializing\n");
  679. break;
  680. default:
  681. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  682. atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
  683. break;
  684. }
  685. reschedule:
  686. mutex_lock(&instance->poll_state_serialize);
  687. if (instance->poll_state == CXPOLL_STOPPING &&
  688. instance->adsl_status == 1 && /* stopped */
  689. instance->line_status == 0) /* down */
  690. instance->poll_state = CXPOLL_STOPPED;
  691. if (instance->poll_state == CXPOLL_STOPPED)
  692. keep_polling = 0;
  693. mutex_unlock(&instance->poll_state_serialize);
  694. if (keep_polling)
  695. schedule_delayed_work(&instance->poll_work,
  696. round_jiffies_relative(POLL_INTERVAL*HZ));
  697. }
  698. static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
  699. u8 code1, u8 code2, u32 addr, u8 *data, int size)
  700. {
  701. int ret;
  702. u8 *buf;
  703. int offd, offb;
  704. const int stride = CMD_PACKET_SIZE - 8;
  705. buf = (u8 *) __get_free_page(GFP_KERNEL);
  706. if (!buf)
  707. return -ENOMEM;
  708. offb = offd = 0;
  709. do {
  710. int l = min_t(int, stride, size - offd);
  711. buf[offb++] = fw;
  712. buf[offb++] = l;
  713. buf[offb++] = code1;
  714. buf[offb++] = code2;
  715. *((u32 *) (buf + offb)) = cpu_to_le32(addr);
  716. offb += 4;
  717. addr += l;
  718. if(l)
  719. memcpy(buf + offb, data + offd, l);
  720. if (l < stride)
  721. memset(buf + offb + l, 0, stride - l);
  722. offb += stride;
  723. offd += stride;
  724. if ((offb >= PAGE_SIZE) || (offd >= size)) {
  725. ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
  726. buf, offb, NULL, CMD_TIMEOUT);
  727. if (ret < 0) {
  728. dbg("sending fw %#x failed", fw);
  729. goto cleanup;
  730. }
  731. offb = 0;
  732. }
  733. } while(offd < size);
  734. dbg("sent fw %#x", fw);
  735. ret = 0;
  736. cleanup:
  737. free_page((unsigned long) buf);
  738. return ret;
  739. }
  740. static void cxacru_upload_firmware(struct cxacru_data *instance,
  741. const struct firmware *fw,
  742. const struct firmware *bp,
  743. const struct firmware *cf)
  744. {
  745. int ret;
  746. int off;
  747. struct usbatm_data *usbatm = instance->usbatm;
  748. struct usb_device *usb_dev = usbatm->usb_dev;
  749. u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };
  750. u32 val;
  751. dbg("cxacru_upload_firmware");
  752. /* FirmwarePllFClkValue */
  753. val = cpu_to_le32(instance->modem_type->pll_f_clk);
  754. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
  755. if (ret) {
  756. usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
  757. return;
  758. }
  759. /* FirmwarePllBClkValue */
  760. val = cpu_to_le32(instance->modem_type->pll_b_clk);
  761. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
  762. if (ret) {
  763. usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
  764. return;
  765. }
  766. /* Enable SDRAM */
  767. val = cpu_to_le32(SDRAM_ENA);
  768. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
  769. if (ret) {
  770. usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
  771. return;
  772. }
  773. /* Firmware */
  774. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
  775. if (ret) {
  776. usb_err(usbatm, "Firmware upload failed: %d\n", ret);
  777. return;
  778. }
  779. /* Boot ROM patch */
  780. if (instance->modem_type->boot_rom_patch) {
  781. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
  782. if (ret) {
  783. usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
  784. return;
  785. }
  786. }
  787. /* Signature */
  788. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
  789. if (ret) {
  790. usb_err(usbatm, "Signature storing failed: %d\n", ret);
  791. return;
  792. }
  793. if (instance->modem_type->boot_rom_patch) {
  794. val = cpu_to_le32(BR_ADDR);
  795. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
  796. }
  797. else {
  798. ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
  799. }
  800. if (ret) {
  801. usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
  802. return;
  803. }
  804. /* Delay to allow firmware to start up. */
  805. msleep_interruptible(1000);
  806. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
  807. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
  808. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
  809. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
  810. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  811. if (ret < 0) {
  812. usb_err(usbatm, "modem failed to initialize: %d\n", ret);
  813. return;
  814. }
  815. /* Load config data (le32), doing one packet at a time */
  816. if (cf)
  817. for (off = 0; off < cf->size / 4; ) {
  818. u32 buf[CMD_PACKET_SIZE / 4 - 1];
  819. int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
  820. buf[0] = cpu_to_le32(len);
  821. for (i = 0; i < len; i++, off++) {
  822. buf[i * 2 + 1] = cpu_to_le32(off);
  823. memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
  824. }
  825. ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
  826. (u8 *) buf, len, NULL, 0);
  827. if (ret < 0) {
  828. usb_err(usbatm, "load config data failed: %d\n", ret);
  829. return;
  830. }
  831. }
  832. msleep_interruptible(4000);
  833. }
  834. static int cxacru_find_firmware(struct cxacru_data *instance,
  835. char* phase, const struct firmware **fw_p)
  836. {
  837. struct usbatm_data *usbatm = instance->usbatm;
  838. struct device *dev = &usbatm->usb_intf->dev;
  839. char buf[16];
  840. sprintf(buf, "cxacru-%s.bin", phase);
  841. dbg("cxacru_find_firmware: looking for %s", buf);
  842. if (request_firmware(fw_p, buf, dev)) {
  843. usb_dbg(usbatm, "no stage %s firmware found\n", phase);
  844. return -ENOENT;
  845. }
  846. usb_info(usbatm, "found firmware %s\n", buf);
  847. return 0;
  848. }
  849. static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
  850. struct usb_interface *usb_intf)
  851. {
  852. const struct firmware *fw, *bp, *cf;
  853. struct cxacru_data *instance = usbatm_instance->driver_data;
  854. int ret = cxacru_find_firmware(instance, "fw", &fw);
  855. if (ret) {
  856. usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
  857. return ret;
  858. }
  859. if (instance->modem_type->boot_rom_patch) {
  860. ret = cxacru_find_firmware(instance, "bp", &bp);
  861. if (ret) {
  862. usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
  863. release_firmware(fw);
  864. return ret;
  865. }
  866. }
  867. if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
  868. cf = NULL;
  869. cxacru_upload_firmware(instance, fw, bp, cf);
  870. if (cf)
  871. release_firmware(cf);
  872. if (instance->modem_type->boot_rom_patch)
  873. release_firmware(bp);
  874. release_firmware(fw);
  875. ret = cxacru_card_status(instance);
  876. if (ret)
  877. dbg("modem initialisation failed");
  878. else
  879. dbg("done setting up the modem");
  880. return ret;
  881. }
  882. static int cxacru_bind(struct usbatm_data *usbatm_instance,
  883. struct usb_interface *intf, const struct usb_device_id *id)
  884. {
  885. struct cxacru_data *instance;
  886. struct usb_device *usb_dev = interface_to_usbdev(intf);
  887. int ret;
  888. /* instance init */
  889. instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  890. if (!instance) {
  891. dbg("cxacru_bind: no memory for instance data");
  892. return -ENOMEM;
  893. }
  894. instance->usbatm = usbatm_instance;
  895. instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
  896. memset(instance->card_info, 0, sizeof(instance->card_info));
  897. mutex_init(&instance->poll_state_serialize);
  898. instance->poll_state = CXPOLL_STOPPED;
  899. instance->line_status = -1;
  900. instance->adsl_status = -1;
  901. mutex_init(&instance->adsl_state_serialize);
  902. instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
  903. if (!instance->rcv_buf) {
  904. dbg("cxacru_bind: no memory for rcv_buf");
  905. ret = -ENOMEM;
  906. goto fail;
  907. }
  908. instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
  909. if (!instance->snd_buf) {
  910. dbg("cxacru_bind: no memory for snd_buf");
  911. ret = -ENOMEM;
  912. goto fail;
  913. }
  914. instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
  915. if (!instance->rcv_urb) {
  916. dbg("cxacru_bind: no memory for rcv_urb");
  917. ret = -ENOMEM;
  918. goto fail;
  919. }
  920. instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
  921. if (!instance->snd_urb) {
  922. dbg("cxacru_bind: no memory for snd_urb");
  923. ret = -ENOMEM;
  924. goto fail;
  925. }
  926. usb_fill_int_urb(instance->rcv_urb,
  927. usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
  928. instance->rcv_buf, PAGE_SIZE,
  929. cxacru_blocking_completion, &instance->rcv_done, 1);
  930. usb_fill_int_urb(instance->snd_urb,
  931. usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
  932. instance->snd_buf, PAGE_SIZE,
  933. cxacru_blocking_completion, &instance->snd_done, 4);
  934. mutex_init(&instance->cm_serialize);
  935. INIT_DELAYED_WORK(&instance->poll_work, cxacru_poll_status);
  936. usbatm_instance->driver_data = instance;
  937. usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
  938. return 0;
  939. fail:
  940. free_page((unsigned long) instance->snd_buf);
  941. free_page((unsigned long) instance->rcv_buf);
  942. usb_free_urb(instance->snd_urb);
  943. usb_free_urb(instance->rcv_urb);
  944. kfree(instance);
  945. return ret;
  946. }
  947. static void cxacru_unbind(struct usbatm_data *usbatm_instance,
  948. struct usb_interface *intf)
  949. {
  950. struct cxacru_data *instance = usbatm_instance->driver_data;
  951. int is_polling = 1;
  952. dbg("cxacru_unbind entered");
  953. if (!instance) {
  954. dbg("cxacru_unbind: NULL instance!");
  955. return;
  956. }
  957. mutex_lock(&instance->poll_state_serialize);
  958. BUG_ON(instance->poll_state == CXPOLL_SHUTDOWN);
  959. /* ensure that status polling continues unless
  960. * it has already stopped */
  961. if (instance->poll_state == CXPOLL_STOPPED)
  962. is_polling = 0;
  963. /* stop polling from being stopped or started */
  964. instance->poll_state = CXPOLL_SHUTDOWN;
  965. mutex_unlock(&instance->poll_state_serialize);
  966. if (is_polling)
  967. cancel_rearming_delayed_work(&instance->poll_work);
  968. usb_kill_urb(instance->snd_urb);
  969. usb_kill_urb(instance->rcv_urb);
  970. usb_free_urb(instance->snd_urb);
  971. usb_free_urb(instance->rcv_urb);
  972. free_page((unsigned long) instance->snd_buf);
  973. free_page((unsigned long) instance->rcv_buf);
  974. kfree(instance);
  975. usbatm_instance->driver_data = NULL;
  976. }
  977. static const struct cxacru_modem_type cxacru_cafe = {
  978. .pll_f_clk = 0x02d874df,
  979. .pll_b_clk = 0x0196a51a,
  980. .boot_rom_patch = 1,
  981. };
  982. static const struct cxacru_modem_type cxacru_cb00 = {
  983. .pll_f_clk = 0x5,
  984. .pll_b_clk = 0x3,
  985. .boot_rom_patch = 0,
  986. };
  987. static const struct usb_device_id cxacru_usb_ids[] = {
  988. { /* V = Conexant P = ADSL modem (Euphrates project) */
  989. USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
  990. },
  991. { /* V = Conexant P = ADSL modem (Hasbani project) */
  992. USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
  993. },
  994. { /* V = Conexant P = ADSL modem */
  995. USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  996. },
  997. { /* V = Conexant P = ADSL modem (Well PTI-800) */
  998. USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
  999. },
  1000. { /* V = Conexant P = ADSL modem */
  1001. USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
  1002. },
  1003. { /* V = Conexant P = ADSL modem (ZTE ZXDSL 852) */
  1004. USB_DEVICE(0x0572, 0xcb07), .driver_info = (unsigned long) &cxacru_cb00
  1005. },
  1006. { /* V = Olitec P = ADSL modem version 2 */
  1007. USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
  1008. },
  1009. { /* V = Olitec P = ADSL modem version 3 */
  1010. USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
  1011. },
  1012. { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
  1013. USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
  1014. },
  1015. { /* V = Zoom P = 5510 */
  1016. USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
  1017. },
  1018. { /* V = Draytek P = Vigor 318 */
  1019. USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
  1020. },
  1021. { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
  1022. USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
  1023. },
  1024. { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
  1025. USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
  1026. },
  1027. { /* V = Aethra P = Starmodem UM1020 */
  1028. USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
  1029. },
  1030. { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
  1031. USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
  1032. },
  1033. { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
  1034. USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  1035. },
  1036. { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
  1037. USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
  1038. },
  1039. {}
  1040. };
  1041. MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
  1042. static struct usbatm_driver cxacru_driver = {
  1043. .driver_name = cxacru_driver_name,
  1044. .bind = cxacru_bind,
  1045. .heavy_init = cxacru_heavy_init,
  1046. .unbind = cxacru_unbind,
  1047. .atm_start = cxacru_atm_start,
  1048. .atm_stop = cxacru_remove_device_files,
  1049. .bulk_in = CXACRU_EP_DATA,
  1050. .bulk_out = CXACRU_EP_DATA,
  1051. .rx_padding = 3,
  1052. .tx_padding = 11,
  1053. };
  1054. static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1055. {
  1056. return usbatm_usb_probe(intf, id, &cxacru_driver);
  1057. }
  1058. static struct usb_driver cxacru_usb_driver = {
  1059. .name = cxacru_driver_name,
  1060. .probe = cxacru_usb_probe,
  1061. .disconnect = usbatm_usb_disconnect,
  1062. .id_table = cxacru_usb_ids
  1063. };
  1064. static int __init cxacru_init(void)
  1065. {
  1066. return usb_register(&cxacru_usb_driver);
  1067. }
  1068. static void __exit cxacru_cleanup(void)
  1069. {
  1070. usb_deregister(&cxacru_usb_driver);
  1071. }
  1072. module_init(cxacru_init);
  1073. module_exit(cxacru_cleanup);
  1074. MODULE_AUTHOR(DRIVER_AUTHOR);
  1075. MODULE_DESCRIPTION(DRIVER_DESC);
  1076. MODULE_LICENSE("GPL");
  1077. MODULE_VERSION(DRIVER_VERSION);