cdc_mbim.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright (c) 2012 Smith Micro Software, Inc.
  3. * Copyright (c) 2012 Bjørn Mork <bjorn@mork.no>
  4. *
  5. * This driver is based on and reuse most of cdc_ncm, which is
  6. * Copyright (C) ST-Ericsson 2010-2012
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/ethtool.h>
  15. #include <linux/if_vlan.h>
  16. #include <linux/ip.h>
  17. #include <linux/mii.h>
  18. #include <linux/usb.h>
  19. #include <linux/usb/cdc.h>
  20. #include <linux/usb/usbnet.h>
  21. #include <linux/usb/cdc-wdm.h>
  22. #include <linux/usb/cdc_ncm.h>
  23. #include <net/ipv6.h>
  24. #include <net/addrconf.h>
  25. /* alternative VLAN for IP session 0 if not untagged */
  26. #define MBIM_IPS0_VID 4094
  27. /* driver specific data - must match cdc_ncm usage */
  28. struct cdc_mbim_state {
  29. struct cdc_ncm_ctx *ctx;
  30. atomic_t pmcount;
  31. struct usb_driver *subdriver;
  32. unsigned long _unused;
  33. unsigned long flags;
  34. };
  35. /* flags for the cdc_mbim_state.flags field */
  36. enum cdc_mbim_flags {
  37. FLAG_IPS0_VLAN = 1 << 0, /* IP session 0 is tagged */
  38. };
  39. /* using a counter to merge subdriver requests with our own into a combined state */
  40. static int cdc_mbim_manage_power(struct usbnet *dev, int on)
  41. {
  42. struct cdc_mbim_state *info = (void *)&dev->data;
  43. int rv = 0;
  44. dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__, atomic_read(&info->pmcount), on);
  45. if ((on && atomic_add_return(1, &info->pmcount) == 1) || (!on && atomic_dec_and_test(&info->pmcount))) {
  46. /* need autopm_get/put here to ensure the usbcore sees the new value */
  47. rv = usb_autopm_get_interface(dev->intf);
  48. dev->intf->needs_remote_wakeup = on;
  49. if (!rv)
  50. usb_autopm_put_interface(dev->intf);
  51. }
  52. return 0;
  53. }
  54. static int cdc_mbim_wdm_manage_power(struct usb_interface *intf, int status)
  55. {
  56. struct usbnet *dev = usb_get_intfdata(intf);
  57. /* can be called while disconnecting */
  58. if (!dev)
  59. return 0;
  60. return cdc_mbim_manage_power(dev, status);
  61. }
  62. static int cdc_mbim_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
  63. {
  64. struct usbnet *dev = netdev_priv(netdev);
  65. struct cdc_mbim_state *info = (void *)&dev->data;
  66. /* creation of this VLAN is a request to tag IP session 0 */
  67. if (vid == MBIM_IPS0_VID)
  68. info->flags |= FLAG_IPS0_VLAN;
  69. else
  70. if (vid >= 512) /* we don't map these to MBIM session */
  71. return -EINVAL;
  72. return 0;
  73. }
  74. static int cdc_mbim_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
  75. {
  76. struct usbnet *dev = netdev_priv(netdev);
  77. struct cdc_mbim_state *info = (void *)&dev->data;
  78. /* this is a request for an untagged IP session 0 */
  79. if (vid == MBIM_IPS0_VID)
  80. info->flags &= ~FLAG_IPS0_VLAN;
  81. return 0;
  82. }
  83. static const struct net_device_ops cdc_mbim_netdev_ops = {
  84. .ndo_open = usbnet_open,
  85. .ndo_stop = usbnet_stop,
  86. .ndo_start_xmit = usbnet_start_xmit,
  87. .ndo_tx_timeout = usbnet_tx_timeout,
  88. .ndo_change_mtu = cdc_ncm_change_mtu,
  89. .ndo_set_mac_address = eth_mac_addr,
  90. .ndo_validate_addr = eth_validate_addr,
  91. .ndo_vlan_rx_add_vid = cdc_mbim_rx_add_vid,
  92. .ndo_vlan_rx_kill_vid = cdc_mbim_rx_kill_vid,
  93. };
  94. /* Change the control interface altsetting and update the .driver_info
  95. * pointer if the matching entry after changing class codes points to
  96. * a different struct
  97. */
  98. static int cdc_mbim_set_ctrlalt(struct usbnet *dev, struct usb_interface *intf, u8 alt)
  99. {
  100. struct usb_driver *driver = to_usb_driver(intf->dev.driver);
  101. const struct usb_device_id *id;
  102. struct driver_info *info;
  103. int ret;
  104. ret = usb_set_interface(dev->udev,
  105. intf->cur_altsetting->desc.bInterfaceNumber,
  106. alt);
  107. if (ret)
  108. return ret;
  109. id = usb_match_id(intf, driver->id_table);
  110. if (!id)
  111. return -ENODEV;
  112. info = (struct driver_info *)id->driver_info;
  113. if (info != dev->driver_info) {
  114. dev_dbg(&intf->dev, "driver_info updated to '%s'\n",
  115. info->description);
  116. dev->driver_info = info;
  117. }
  118. return 0;
  119. }
  120. static int cdc_mbim_bind(struct usbnet *dev, struct usb_interface *intf)
  121. {
  122. struct cdc_ncm_ctx *ctx;
  123. struct usb_driver *subdriver = ERR_PTR(-ENODEV);
  124. int ret = -ENODEV;
  125. u8 data_altsetting = 1;
  126. struct cdc_mbim_state *info = (void *)&dev->data;
  127. /* should we change control altsetting on a NCM/MBIM function? */
  128. if (cdc_ncm_select_altsetting(intf) == CDC_NCM_COMM_ALTSETTING_MBIM) {
  129. data_altsetting = CDC_NCM_DATA_ALTSETTING_MBIM;
  130. ret = cdc_mbim_set_ctrlalt(dev, intf, CDC_NCM_COMM_ALTSETTING_MBIM);
  131. if (ret)
  132. goto err;
  133. ret = -ENODEV;
  134. }
  135. /* we will hit this for NCM/MBIM functions if prefer_mbim is false */
  136. if (!cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
  137. goto err;
  138. ret = cdc_ncm_bind_common(dev, intf, data_altsetting, dev->driver_info->data);
  139. if (ret)
  140. goto err;
  141. ctx = info->ctx;
  142. /* The MBIM descriptor and the status endpoint are required */
  143. if (ctx->mbim_desc && dev->status)
  144. subdriver = usb_cdc_wdm_register(ctx->control,
  145. &dev->status->desc,
  146. le16_to_cpu(ctx->mbim_desc->wMaxControlMessage),
  147. cdc_mbim_wdm_manage_power);
  148. if (IS_ERR(subdriver)) {
  149. ret = PTR_ERR(subdriver);
  150. cdc_ncm_unbind(dev, intf);
  151. goto err;
  152. }
  153. /* can't let usbnet use the interrupt endpoint */
  154. dev->status = NULL;
  155. info->subdriver = subdriver;
  156. /* MBIM cannot do ARP */
  157. dev->net->flags |= IFF_NOARP;
  158. /* no need to put the VLAN tci in the packet headers */
  159. dev->net->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_FILTER;
  160. /* monitor VLAN additions and removals */
  161. dev->net->netdev_ops = &cdc_mbim_netdev_ops;
  162. err:
  163. return ret;
  164. }
  165. static void cdc_mbim_unbind(struct usbnet *dev, struct usb_interface *intf)
  166. {
  167. struct cdc_mbim_state *info = (void *)&dev->data;
  168. struct cdc_ncm_ctx *ctx = info->ctx;
  169. /* disconnect subdriver from control interface */
  170. if (info->subdriver && info->subdriver->disconnect)
  171. info->subdriver->disconnect(ctx->control);
  172. info->subdriver = NULL;
  173. /* let NCM unbind clean up both control and data interface */
  174. cdc_ncm_unbind(dev, intf);
  175. }
  176. /* verify that the ethernet protocol is IPv4 or IPv6 */
  177. static bool is_ip_proto(__be16 proto)
  178. {
  179. switch (proto) {
  180. case htons(ETH_P_IP):
  181. case htons(ETH_P_IPV6):
  182. return true;
  183. }
  184. return false;
  185. }
  186. static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
  187. {
  188. struct sk_buff *skb_out;
  189. struct cdc_mbim_state *info = (void *)&dev->data;
  190. struct cdc_ncm_ctx *ctx = info->ctx;
  191. __le32 sign = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN);
  192. u16 tci = 0;
  193. bool is_ip;
  194. u8 *c;
  195. if (!ctx)
  196. goto error;
  197. if (skb) {
  198. if (skb->len <= ETH_HLEN)
  199. goto error;
  200. /* Some applications using e.g. packet sockets will
  201. * bypass the VLAN acceleration and create tagged
  202. * ethernet frames directly. We primarily look for
  203. * the accelerated out-of-band tag, but fall back if
  204. * required
  205. */
  206. skb_reset_mac_header(skb);
  207. if (vlan_get_tag(skb, &tci) < 0 && skb->len > VLAN_ETH_HLEN &&
  208. __vlan_get_tag(skb, &tci) == 0) {
  209. is_ip = is_ip_proto(vlan_eth_hdr(skb)->h_vlan_encapsulated_proto);
  210. skb_pull(skb, VLAN_ETH_HLEN);
  211. } else {
  212. is_ip = is_ip_proto(eth_hdr(skb)->h_proto);
  213. skb_pull(skb, ETH_HLEN);
  214. }
  215. /* Is IP session <0> tagged too? */
  216. if (info->flags & FLAG_IPS0_VLAN) {
  217. /* drop all untagged packets */
  218. if (!tci)
  219. goto error;
  220. /* map MBIM_IPS0_VID to IPS<0> */
  221. if (tci == MBIM_IPS0_VID)
  222. tci = 0;
  223. }
  224. /* mapping VLANs to MBIM sessions:
  225. * no tag => IPS session <0> if !FLAG_IPS0_VLAN
  226. * 1 - 255 => IPS session <vlanid>
  227. * 256 - 511 => DSS session <vlanid - 256>
  228. * 512 - 4093 => unsupported, drop
  229. * 4094 => IPS session <0> if FLAG_IPS0_VLAN
  230. */
  231. switch (tci & 0x0f00) {
  232. case 0x0000: /* VLAN ID 0 - 255 */
  233. if (!is_ip)
  234. goto error;
  235. c = (u8 *)&sign;
  236. c[3] = tci;
  237. break;
  238. case 0x0100: /* VLAN ID 256 - 511 */
  239. if (is_ip)
  240. goto error;
  241. sign = cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN);
  242. c = (u8 *)&sign;
  243. c[3] = tci;
  244. break;
  245. default:
  246. netif_err(dev, tx_err, dev->net,
  247. "unsupported tci=0x%04x\n", tci);
  248. goto error;
  249. }
  250. }
  251. spin_lock_bh(&ctx->mtx);
  252. skb_out = cdc_ncm_fill_tx_frame(dev, skb, sign);
  253. spin_unlock_bh(&ctx->mtx);
  254. return skb_out;
  255. error:
  256. if (skb)
  257. dev_kfree_skb_any(skb);
  258. return NULL;
  259. }
  260. /* Some devices are known to send Neigbor Solicitation messages and
  261. * require Neigbor Advertisement replies. The IPv6 core will not
  262. * respond since IFF_NOARP is set, so we must handle them ourselves.
  263. */
  264. static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci)
  265. {
  266. struct ipv6hdr *iph = (void *)buf;
  267. struct nd_msg *msg = (void *)(iph + 1);
  268. struct net_device *netdev;
  269. struct inet6_dev *in6_dev;
  270. bool is_router;
  271. /* we'll only respond to requests from unicast addresses to
  272. * our solicited node addresses.
  273. */
  274. if (!ipv6_addr_is_solict_mult(&iph->daddr) ||
  275. !(ipv6_addr_type(&iph->saddr) & IPV6_ADDR_UNICAST))
  276. return;
  277. /* need to send the NA on the VLAN dev, if any */
  278. rcu_read_lock();
  279. if (tci) {
  280. netdev = __vlan_find_dev_deep_rcu(dev->net, htons(ETH_P_8021Q),
  281. tci);
  282. if (!netdev) {
  283. rcu_read_unlock();
  284. return;
  285. }
  286. } else {
  287. netdev = dev->net;
  288. }
  289. dev_hold(netdev);
  290. rcu_read_unlock();
  291. in6_dev = in6_dev_get(netdev);
  292. if (!in6_dev)
  293. goto out;
  294. is_router = !!in6_dev->cnf.forwarding;
  295. in6_dev_put(in6_dev);
  296. /* ipv6_stub != NULL if in6_dev_get returned an inet6_dev */
  297. ipv6_stub->ndisc_send_na(netdev, &iph->saddr, &msg->target,
  298. is_router /* router */,
  299. true /* solicited */,
  300. false /* override */,
  301. true /* inc_opt */);
  302. out:
  303. dev_put(netdev);
  304. }
  305. static bool is_neigh_solicit(u8 *buf, size_t len)
  306. {
  307. struct ipv6hdr *iph = (void *)buf;
  308. struct nd_msg *msg = (void *)(iph + 1);
  309. return (len >= sizeof(struct ipv6hdr) + sizeof(struct nd_msg) &&
  310. iph->nexthdr == IPPROTO_ICMPV6 &&
  311. msg->icmph.icmp6_code == 0 &&
  312. msg->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION);
  313. }
  314. static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_t len, u16 tci)
  315. {
  316. __be16 proto = htons(ETH_P_802_3);
  317. struct sk_buff *skb = NULL;
  318. if (tci < 256 || tci == MBIM_IPS0_VID) { /* IPS session? */
  319. if (len < sizeof(struct iphdr))
  320. goto err;
  321. switch (*buf & 0xf0) {
  322. case 0x40:
  323. proto = htons(ETH_P_IP);
  324. break;
  325. case 0x60:
  326. if (is_neigh_solicit(buf, len))
  327. do_neigh_solicit(dev, buf, tci);
  328. proto = htons(ETH_P_IPV6);
  329. break;
  330. default:
  331. goto err;
  332. }
  333. }
  334. skb = netdev_alloc_skb_ip_align(dev->net, len + ETH_HLEN);
  335. if (!skb)
  336. goto err;
  337. /* add an ethernet header */
  338. skb_put(skb, ETH_HLEN);
  339. skb_reset_mac_header(skb);
  340. eth_hdr(skb)->h_proto = proto;
  341. eth_zero_addr(eth_hdr(skb)->h_source);
  342. memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN);
  343. /* add datagram */
  344. memcpy(skb_put(skb, len), buf, len);
  345. /* map MBIM session to VLAN */
  346. if (tci)
  347. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tci);
  348. err:
  349. return skb;
  350. }
  351. static int cdc_mbim_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
  352. {
  353. struct sk_buff *skb;
  354. struct cdc_mbim_state *info = (void *)&dev->data;
  355. struct cdc_ncm_ctx *ctx = info->ctx;
  356. int len;
  357. int nframes;
  358. int x;
  359. int offset;
  360. struct usb_cdc_ncm_ndp16 *ndp16;
  361. struct usb_cdc_ncm_dpe16 *dpe16;
  362. int ndpoffset;
  363. int loopcount = 50; /* arbitrary max preventing infinite loop */
  364. u32 payload = 0;
  365. u8 *c;
  366. u16 tci;
  367. ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in);
  368. if (ndpoffset < 0)
  369. goto error;
  370. next_ndp:
  371. nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset);
  372. if (nframes < 0)
  373. goto error;
  374. ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
  375. switch (ndp16->dwSignature & cpu_to_le32(0x00ffffff)) {
  376. case cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN):
  377. c = (u8 *)&ndp16->dwSignature;
  378. tci = c[3];
  379. /* tag IPS<0> packets too if MBIM_IPS0_VID exists */
  380. if (!tci && info->flags & FLAG_IPS0_VLAN)
  381. tci = MBIM_IPS0_VID;
  382. break;
  383. case cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN):
  384. c = (u8 *)&ndp16->dwSignature;
  385. tci = c[3] + 256;
  386. break;
  387. default:
  388. netif_dbg(dev, rx_err, dev->net,
  389. "unsupported NDP signature <0x%08x>\n",
  390. le32_to_cpu(ndp16->dwSignature));
  391. goto err_ndp;
  392. }
  393. dpe16 = ndp16->dpe16;
  394. for (x = 0; x < nframes; x++, dpe16++) {
  395. offset = le16_to_cpu(dpe16->wDatagramIndex);
  396. len = le16_to_cpu(dpe16->wDatagramLength);
  397. /*
  398. * CDC NCM ch. 3.7
  399. * All entries after first NULL entry are to be ignored
  400. */
  401. if ((offset == 0) || (len == 0)) {
  402. if (!x)
  403. goto err_ndp; /* empty NTB */
  404. break;
  405. }
  406. /* sanity checking */
  407. if (((offset + len) > skb_in->len) || (len > ctx->rx_max)) {
  408. netif_dbg(dev, rx_err, dev->net,
  409. "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",
  410. x, offset, len, skb_in);
  411. if (!x)
  412. goto err_ndp;
  413. break;
  414. } else {
  415. skb = cdc_mbim_process_dgram(dev, skb_in->data + offset, len, tci);
  416. if (!skb)
  417. goto error;
  418. usbnet_skb_return(dev, skb);
  419. payload += len; /* count payload bytes in this NTB */
  420. }
  421. }
  422. err_ndp:
  423. /* are there more NDPs to process? */
  424. ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex);
  425. if (ndpoffset && loopcount--)
  426. goto next_ndp;
  427. /* update stats */
  428. ctx->rx_overhead += skb_in->len - payload;
  429. ctx->rx_ntbs++;
  430. return 1;
  431. error:
  432. return 0;
  433. }
  434. static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message)
  435. {
  436. int ret = -ENODEV;
  437. struct usbnet *dev = usb_get_intfdata(intf);
  438. struct cdc_mbim_state *info = (void *)&dev->data;
  439. struct cdc_ncm_ctx *ctx = info->ctx;
  440. if (!ctx)
  441. goto error;
  442. /*
  443. * Both usbnet_suspend() and subdriver->suspend() MUST return 0
  444. * in system sleep context, otherwise, the resume callback has
  445. * to recover device from previous suspend failure.
  446. */
  447. ret = usbnet_suspend(intf, message);
  448. if (ret < 0)
  449. goto error;
  450. if (intf == ctx->control && info->subdriver && info->subdriver->suspend)
  451. ret = info->subdriver->suspend(intf, message);
  452. if (ret < 0)
  453. usbnet_resume(intf);
  454. error:
  455. return ret;
  456. }
  457. static int cdc_mbim_resume(struct usb_interface *intf)
  458. {
  459. int ret = 0;
  460. struct usbnet *dev = usb_get_intfdata(intf);
  461. struct cdc_mbim_state *info = (void *)&dev->data;
  462. struct cdc_ncm_ctx *ctx = info->ctx;
  463. bool callsub = (intf == ctx->control && info->subdriver && info->subdriver->resume);
  464. if (callsub)
  465. ret = info->subdriver->resume(intf);
  466. if (ret < 0)
  467. goto err;
  468. ret = usbnet_resume(intf);
  469. if (ret < 0 && callsub)
  470. info->subdriver->suspend(intf, PMSG_SUSPEND);
  471. err:
  472. return ret;
  473. }
  474. static const struct driver_info cdc_mbim_info = {
  475. .description = "CDC MBIM",
  476. .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
  477. .bind = cdc_mbim_bind,
  478. .unbind = cdc_mbim_unbind,
  479. .manage_power = cdc_mbim_manage_power,
  480. .rx_fixup = cdc_mbim_rx_fixup,
  481. .tx_fixup = cdc_mbim_tx_fixup,
  482. };
  483. /* MBIM and NCM devices should not need a ZLP after NTBs with
  484. * dwNtbOutMaxSize length. Nevertheless, a number of devices from
  485. * different vendor IDs will fail unless we send ZLPs, forcing us
  486. * to make this the default.
  487. *
  488. * This default may cause a performance penalty for spec conforming
  489. * devices wanting to take advantage of optimizations possible without
  490. * ZLPs. A whitelist is added in an attempt to avoid this for devices
  491. * known to conform to the MBIM specification.
  492. *
  493. * All known devices supporting NCM compatibility mode are also
  494. * conforming to the NCM and MBIM specifications. For this reason, the
  495. * NCM subclass entry is also in the ZLP whitelist.
  496. */
  497. static const struct driver_info cdc_mbim_info_zlp = {
  498. .description = "CDC MBIM",
  499. .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN | FLAG_SEND_ZLP,
  500. .bind = cdc_mbim_bind,
  501. .unbind = cdc_mbim_unbind,
  502. .manage_power = cdc_mbim_manage_power,
  503. .rx_fixup = cdc_mbim_rx_fixup,
  504. .tx_fixup = cdc_mbim_tx_fixup,
  505. };
  506. /* The spefication explicitly allows NDPs to be placed anywhere in the
  507. * frame, but some devices fail unless the NDP is placed after the IP
  508. * packets. Using the CDC_NCM_FLAG_NDP_TO_END flags to force this
  509. * behaviour.
  510. *
  511. * Note: The current implementation of this feature restricts each NTB
  512. * to a single NDP, implying that multiplexed sessions cannot share an
  513. * NTB. This might affect performace for multiplexed sessions.
  514. */
  515. static const struct driver_info cdc_mbim_info_ndp_to_end = {
  516. .description = "CDC MBIM",
  517. .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN | FLAG_SEND_ZLP,
  518. .bind = cdc_mbim_bind,
  519. .unbind = cdc_mbim_unbind,
  520. .manage_power = cdc_mbim_manage_power,
  521. .rx_fixup = cdc_mbim_rx_fixup,
  522. .tx_fixup = cdc_mbim_tx_fixup,
  523. .data = CDC_NCM_FLAG_NDP_TO_END,
  524. };
  525. static const struct usb_device_id mbim_devs[] = {
  526. /* This duplicate NCM entry is intentional. MBIM devices can
  527. * be disguised as NCM by default, and this is necessary to
  528. * allow us to bind the correct driver_info to such devices.
  529. *
  530. * bind() will sort out this for us, selecting the correct
  531. * entry and reject the other
  532. */
  533. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
  534. .driver_info = (unsigned long)&cdc_mbim_info,
  535. },
  536. /* ZLP conformance whitelist: All Ericsson MBIM devices */
  537. { USB_VENDOR_AND_INTERFACE_INFO(0x0bdb, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
  538. .driver_info = (unsigned long)&cdc_mbim_info,
  539. },
  540. /* Some Huawei devices, ME906s-158 (12d1:15c1) and E3372
  541. * (12d1:157d), are known to fail unless the NDP is placed
  542. * after the IP packets. Applying the quirk to all Huawei
  543. * devices is broader than necessary, but harmless.
  544. */
  545. { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
  546. .driver_info = (unsigned long)&cdc_mbim_info_ndp_to_end,
  547. },
  548. /* default entry */
  549. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
  550. .driver_info = (unsigned long)&cdc_mbim_info_zlp,
  551. },
  552. {
  553. },
  554. };
  555. MODULE_DEVICE_TABLE(usb, mbim_devs);
  556. static struct usb_driver cdc_mbim_driver = {
  557. .name = "cdc_mbim",
  558. .id_table = mbim_devs,
  559. .probe = usbnet_probe,
  560. .disconnect = usbnet_disconnect,
  561. .suspend = cdc_mbim_suspend,
  562. .resume = cdc_mbim_resume,
  563. .reset_resume = cdc_mbim_resume,
  564. .supports_autosuspend = 1,
  565. .disable_hub_initiated_lpm = 1,
  566. };
  567. module_usb_driver(cdc_mbim_driver);
  568. MODULE_AUTHOR("Greg Suarez <gsuarez@smithmicro.com>");
  569. MODULE_AUTHOR("Bjørn Mork <bjorn@mork.no>");
  570. MODULE_DESCRIPTION("USB CDC MBIM host driver");
  571. MODULE_LICENSE("GPL");