cxacru.c 36 KB

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