qmi_wwan.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. /*
  2. * Copyright (c) 2012 Bjørn Mork <bjorn@mork.no>
  3. *
  4. * The probing code is heavily inspired by cdc_ether, which is:
  5. * Copyright (C) 2003-2005 by David Brownell
  6. * Copyright (C) 2006 by Ole Andre Vadla Ravnas (ActiveSync)
  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/sched/signal.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/ethtool.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/mii.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/usb.h>
  21. #include <linux/usb/cdc.h>
  22. #include <linux/usb/usbnet.h>
  23. #include <linux/usb/cdc-wdm.h>
  24. /* This driver supports wwan (3G/LTE/?) devices using a vendor
  25. * specific management protocol called Qualcomm MSM Interface (QMI) -
  26. * in addition to the more common AT commands over serial interface
  27. * management
  28. *
  29. * QMI is wrapped in CDC, using CDC encapsulated commands on the
  30. * control ("master") interface of a two-interface CDC Union
  31. * resembling standard CDC ECM. The devices do not use the control
  32. * interface for any other CDC messages. Most likely because the
  33. * management protocol is used in place of the standard CDC
  34. * notifications NOTIFY_NETWORK_CONNECTION and NOTIFY_SPEED_CHANGE
  35. *
  36. * Alternatively, control and data functions can be combined in a
  37. * single USB interface.
  38. *
  39. * Handling a protocol like QMI is out of the scope for any driver.
  40. * It is exported as a character device using the cdc-wdm driver as
  41. * a subdriver, enabling userspace applications ("modem managers") to
  42. * handle it.
  43. *
  44. * These devices may alternatively/additionally be configured using AT
  45. * commands on a serial interface
  46. */
  47. /* driver specific data */
  48. struct qmi_wwan_state {
  49. struct usb_driver *subdriver;
  50. atomic_t pmcount;
  51. unsigned long flags;
  52. struct usb_interface *control;
  53. struct usb_interface *data;
  54. };
  55. enum qmi_wwan_flags {
  56. QMI_WWAN_FLAG_RAWIP = 1 << 0,
  57. QMI_WWAN_FLAG_MUX = 1 << 1,
  58. };
  59. enum qmi_wwan_quirks {
  60. QMI_WWAN_QUIRK_DTR = 1 << 0, /* needs "set DTR" request */
  61. };
  62. struct qmimux_hdr {
  63. u8 pad;
  64. u8 mux_id;
  65. __be16 pkt_len;
  66. };
  67. struct qmimux_priv {
  68. struct net_device *real_dev;
  69. u8 mux_id;
  70. };
  71. static int qmimux_open(struct net_device *dev)
  72. {
  73. struct qmimux_priv *priv = netdev_priv(dev);
  74. struct net_device *real_dev = priv->real_dev;
  75. if (!(priv->real_dev->flags & IFF_UP))
  76. return -ENETDOWN;
  77. if (netif_carrier_ok(real_dev))
  78. netif_carrier_on(dev);
  79. return 0;
  80. }
  81. static int qmimux_stop(struct net_device *dev)
  82. {
  83. netif_carrier_off(dev);
  84. return 0;
  85. }
  86. static netdev_tx_t qmimux_start_xmit(struct sk_buff *skb, struct net_device *dev)
  87. {
  88. struct qmimux_priv *priv = netdev_priv(dev);
  89. unsigned int len = skb->len;
  90. struct qmimux_hdr *hdr;
  91. hdr = skb_push(skb, sizeof(struct qmimux_hdr));
  92. hdr->pad = 0;
  93. hdr->mux_id = priv->mux_id;
  94. hdr->pkt_len = cpu_to_be16(len);
  95. skb->dev = priv->real_dev;
  96. return dev_queue_xmit(skb);
  97. }
  98. static const struct net_device_ops qmimux_netdev_ops = {
  99. .ndo_open = qmimux_open,
  100. .ndo_stop = qmimux_stop,
  101. .ndo_start_xmit = qmimux_start_xmit,
  102. };
  103. static void qmimux_setup(struct net_device *dev)
  104. {
  105. dev->header_ops = NULL; /* No header */
  106. dev->type = ARPHRD_NONE;
  107. dev->hard_header_len = 0;
  108. dev->addr_len = 0;
  109. dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
  110. dev->netdev_ops = &qmimux_netdev_ops;
  111. dev->mtu = 1500;
  112. dev->needs_free_netdev = true;
  113. }
  114. static struct net_device *qmimux_find_dev(struct usbnet *dev, u8 mux_id)
  115. {
  116. struct qmimux_priv *priv;
  117. struct list_head *iter;
  118. struct net_device *ldev;
  119. rcu_read_lock();
  120. netdev_for_each_upper_dev_rcu(dev->net, ldev, iter) {
  121. priv = netdev_priv(ldev);
  122. if (priv->mux_id == mux_id) {
  123. rcu_read_unlock();
  124. return ldev;
  125. }
  126. }
  127. rcu_read_unlock();
  128. return NULL;
  129. }
  130. static bool qmimux_has_slaves(struct usbnet *dev)
  131. {
  132. return !list_empty(&dev->net->adj_list.upper);
  133. }
  134. static int qmimux_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  135. {
  136. unsigned int len, offset = 0, pad_len, pkt_len;
  137. struct qmimux_hdr *hdr;
  138. struct net_device *net;
  139. struct sk_buff *skbn;
  140. u8 qmimux_hdr_sz = sizeof(*hdr);
  141. while (offset + qmimux_hdr_sz < skb->len) {
  142. hdr = (struct qmimux_hdr *)(skb->data + offset);
  143. len = be16_to_cpu(hdr->pkt_len);
  144. /* drop the packet, bogus length */
  145. if (offset + len + qmimux_hdr_sz > skb->len)
  146. return 0;
  147. /* control packet, we do not know what to do */
  148. if (hdr->pad & 0x80)
  149. goto skip;
  150. /* extract padding length and check for valid length info */
  151. pad_len = hdr->pad & 0x3f;
  152. if (len == 0 || pad_len >= len)
  153. goto skip;
  154. pkt_len = len - pad_len;
  155. net = qmimux_find_dev(dev, hdr->mux_id);
  156. if (!net)
  157. goto skip;
  158. skbn = netdev_alloc_skb(net, pkt_len);
  159. if (!skbn)
  160. return 0;
  161. skbn->dev = net;
  162. switch (skb->data[offset + qmimux_hdr_sz] & 0xf0) {
  163. case 0x40:
  164. skbn->protocol = htons(ETH_P_IP);
  165. break;
  166. case 0x60:
  167. skbn->protocol = htons(ETH_P_IPV6);
  168. break;
  169. default:
  170. /* not ip - do not know what to do */
  171. goto skip;
  172. }
  173. skb_put_data(skbn, skb->data + offset + qmimux_hdr_sz, pkt_len);
  174. if (netif_rx(skbn) != NET_RX_SUCCESS)
  175. return 0;
  176. skip:
  177. offset += len + qmimux_hdr_sz;
  178. }
  179. return 1;
  180. }
  181. static int qmimux_register_device(struct net_device *real_dev, u8 mux_id)
  182. {
  183. struct net_device *new_dev;
  184. struct qmimux_priv *priv;
  185. int err;
  186. new_dev = alloc_netdev(sizeof(struct qmimux_priv),
  187. "qmimux%d", NET_NAME_UNKNOWN, qmimux_setup);
  188. if (!new_dev)
  189. return -ENOBUFS;
  190. dev_net_set(new_dev, dev_net(real_dev));
  191. priv = netdev_priv(new_dev);
  192. priv->mux_id = mux_id;
  193. priv->real_dev = real_dev;
  194. err = register_netdevice(new_dev);
  195. if (err < 0)
  196. goto out_free_newdev;
  197. /* Account for reference in struct qmimux_priv_priv */
  198. dev_hold(real_dev);
  199. err = netdev_upper_dev_link(real_dev, new_dev, NULL);
  200. if (err)
  201. goto out_unregister_netdev;
  202. netif_stacked_transfer_operstate(real_dev, new_dev);
  203. return 0;
  204. out_unregister_netdev:
  205. unregister_netdevice(new_dev);
  206. dev_put(real_dev);
  207. out_free_newdev:
  208. free_netdev(new_dev);
  209. return err;
  210. }
  211. static void qmimux_unregister_device(struct net_device *dev,
  212. struct list_head *head)
  213. {
  214. struct qmimux_priv *priv = netdev_priv(dev);
  215. struct net_device *real_dev = priv->real_dev;
  216. netdev_upper_dev_unlink(real_dev, dev);
  217. unregister_netdevice_queue(dev, head);
  218. /* Get rid of the reference to real_dev */
  219. dev_put(real_dev);
  220. }
  221. static void qmi_wwan_netdev_setup(struct net_device *net)
  222. {
  223. struct usbnet *dev = netdev_priv(net);
  224. struct qmi_wwan_state *info = (void *)&dev->data;
  225. if (info->flags & QMI_WWAN_FLAG_RAWIP) {
  226. net->header_ops = NULL; /* No header */
  227. net->type = ARPHRD_NONE;
  228. net->hard_header_len = 0;
  229. net->addr_len = 0;
  230. net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
  231. set_bit(EVENT_NO_IP_ALIGN, &dev->flags);
  232. netdev_dbg(net, "mode: raw IP\n");
  233. } else if (!net->header_ops) { /* don't bother if already set */
  234. ether_setup(net);
  235. /* Restoring min/max mtu values set originally by usbnet */
  236. net->min_mtu = 0;
  237. net->max_mtu = ETH_MAX_MTU;
  238. clear_bit(EVENT_NO_IP_ALIGN, &dev->flags);
  239. netdev_dbg(net, "mode: Ethernet\n");
  240. }
  241. /* recalculate buffers after changing hard_header_len */
  242. usbnet_change_mtu(net, net->mtu);
  243. }
  244. static ssize_t raw_ip_show(struct device *d, struct device_attribute *attr, char *buf)
  245. {
  246. struct usbnet *dev = netdev_priv(to_net_dev(d));
  247. struct qmi_wwan_state *info = (void *)&dev->data;
  248. return sprintf(buf, "%c\n", info->flags & QMI_WWAN_FLAG_RAWIP ? 'Y' : 'N');
  249. }
  250. static ssize_t raw_ip_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
  251. {
  252. struct usbnet *dev = netdev_priv(to_net_dev(d));
  253. struct qmi_wwan_state *info = (void *)&dev->data;
  254. bool enable;
  255. int ret;
  256. if (strtobool(buf, &enable))
  257. return -EINVAL;
  258. /* no change? */
  259. if (enable == (info->flags & QMI_WWAN_FLAG_RAWIP))
  260. return len;
  261. if (!rtnl_trylock())
  262. return restart_syscall();
  263. /* we don't want to modify a running netdev */
  264. if (netif_running(dev->net)) {
  265. netdev_err(dev->net, "Cannot change a running device\n");
  266. ret = -EBUSY;
  267. goto err;
  268. }
  269. /* let other drivers deny the change */
  270. ret = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev->net);
  271. ret = notifier_to_errno(ret);
  272. if (ret) {
  273. netdev_err(dev->net, "Type change was refused\n");
  274. goto err;
  275. }
  276. if (enable)
  277. info->flags |= QMI_WWAN_FLAG_RAWIP;
  278. else
  279. info->flags &= ~QMI_WWAN_FLAG_RAWIP;
  280. qmi_wwan_netdev_setup(dev->net);
  281. call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev->net);
  282. ret = len;
  283. err:
  284. rtnl_unlock();
  285. return ret;
  286. }
  287. static ssize_t add_mux_show(struct device *d, struct device_attribute *attr, char *buf)
  288. {
  289. struct net_device *dev = to_net_dev(d);
  290. struct qmimux_priv *priv;
  291. struct list_head *iter;
  292. struct net_device *ldev;
  293. ssize_t count = 0;
  294. rcu_read_lock();
  295. netdev_for_each_upper_dev_rcu(dev, ldev, iter) {
  296. priv = netdev_priv(ldev);
  297. count += scnprintf(&buf[count], PAGE_SIZE - count,
  298. "0x%02x\n", priv->mux_id);
  299. }
  300. rcu_read_unlock();
  301. return count;
  302. }
  303. static ssize_t add_mux_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
  304. {
  305. struct usbnet *dev = netdev_priv(to_net_dev(d));
  306. struct qmi_wwan_state *info = (void *)&dev->data;
  307. u8 mux_id;
  308. int ret;
  309. if (kstrtou8(buf, 0, &mux_id))
  310. return -EINVAL;
  311. /* mux_id [1 - 254] for compatibility with ip(8) and the rmnet driver */
  312. if (mux_id < 1 || mux_id > 254)
  313. return -EINVAL;
  314. if (!rtnl_trylock())
  315. return restart_syscall();
  316. if (qmimux_find_dev(dev, mux_id)) {
  317. netdev_err(dev->net, "mux_id already present\n");
  318. ret = -EINVAL;
  319. goto err;
  320. }
  321. ret = qmimux_register_device(dev->net, mux_id);
  322. if (!ret) {
  323. info->flags |= QMI_WWAN_FLAG_MUX;
  324. ret = len;
  325. }
  326. err:
  327. rtnl_unlock();
  328. return ret;
  329. }
  330. static ssize_t del_mux_show(struct device *d, struct device_attribute *attr, char *buf)
  331. {
  332. return add_mux_show(d, attr, buf);
  333. }
  334. static ssize_t del_mux_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
  335. {
  336. struct usbnet *dev = netdev_priv(to_net_dev(d));
  337. struct qmi_wwan_state *info = (void *)&dev->data;
  338. struct net_device *del_dev;
  339. u8 mux_id;
  340. int ret = 0;
  341. if (kstrtou8(buf, 0, &mux_id))
  342. return -EINVAL;
  343. if (!rtnl_trylock())
  344. return restart_syscall();
  345. del_dev = qmimux_find_dev(dev, mux_id);
  346. if (!del_dev) {
  347. netdev_err(dev->net, "mux_id not present\n");
  348. ret = -EINVAL;
  349. goto err;
  350. }
  351. qmimux_unregister_device(del_dev, NULL);
  352. if (!qmimux_has_slaves(dev))
  353. info->flags &= ~QMI_WWAN_FLAG_MUX;
  354. ret = len;
  355. err:
  356. rtnl_unlock();
  357. return ret;
  358. }
  359. static DEVICE_ATTR_RW(raw_ip);
  360. static DEVICE_ATTR_RW(add_mux);
  361. static DEVICE_ATTR_RW(del_mux);
  362. static struct attribute *qmi_wwan_sysfs_attrs[] = {
  363. &dev_attr_raw_ip.attr,
  364. &dev_attr_add_mux.attr,
  365. &dev_attr_del_mux.attr,
  366. NULL,
  367. };
  368. static struct attribute_group qmi_wwan_sysfs_attr_group = {
  369. .name = "qmi",
  370. .attrs = qmi_wwan_sysfs_attrs,
  371. };
  372. /* default ethernet address used by the modem */
  373. static const u8 default_modem_addr[ETH_ALEN] = {0x02, 0x50, 0xf3};
  374. static const u8 buggy_fw_addr[ETH_ALEN] = {0x00, 0xa0, 0xc6, 0x00, 0x00, 0x00};
  375. /* Make up an ethernet header if the packet doesn't have one.
  376. *
  377. * A firmware bug common among several devices cause them to send raw
  378. * IP packets under some circumstances. There is no way for the
  379. * driver/host to know when this will happen. And even when the bug
  380. * hits, some packets will still arrive with an intact header.
  381. *
  382. * The supported devices are only capably of sending IPv4, IPv6 and
  383. * ARP packets on a point-to-point link. Any packet with an ethernet
  384. * header will have either our address or a broadcast/multicast
  385. * address as destination. ARP packets will always have a header.
  386. *
  387. * This means that this function will reliably add the appropriate
  388. * header iff necessary, provided our hardware address does not start
  389. * with 4 or 6.
  390. *
  391. * Another common firmware bug results in all packets being addressed
  392. * to 00:a0:c6:00:00:00 despite the host address being different.
  393. * This function will also fixup such packets.
  394. */
  395. static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  396. {
  397. struct qmi_wwan_state *info = (void *)&dev->data;
  398. bool rawip = info->flags & QMI_WWAN_FLAG_RAWIP;
  399. __be16 proto;
  400. /* This check is no longer done by usbnet */
  401. if (skb->len < dev->net->hard_header_len)
  402. return 0;
  403. if (info->flags & QMI_WWAN_FLAG_MUX)
  404. return qmimux_rx_fixup(dev, skb);
  405. switch (skb->data[0] & 0xf0) {
  406. case 0x40:
  407. proto = htons(ETH_P_IP);
  408. break;
  409. case 0x60:
  410. proto = htons(ETH_P_IPV6);
  411. break;
  412. case 0x00:
  413. if (rawip)
  414. return 0;
  415. if (is_multicast_ether_addr(skb->data))
  416. return 1;
  417. /* possibly bogus destination - rewrite just in case */
  418. skb_reset_mac_header(skb);
  419. goto fix_dest;
  420. default:
  421. if (rawip)
  422. return 0;
  423. /* pass along other packets without modifications */
  424. return 1;
  425. }
  426. if (rawip) {
  427. skb_reset_mac_header(skb);
  428. skb->dev = dev->net; /* normally set by eth_type_trans */
  429. skb->protocol = proto;
  430. return 1;
  431. }
  432. if (skb_headroom(skb) < ETH_HLEN)
  433. return 0;
  434. skb_push(skb, ETH_HLEN);
  435. skb_reset_mac_header(skb);
  436. eth_hdr(skb)->h_proto = proto;
  437. eth_zero_addr(eth_hdr(skb)->h_source);
  438. fix_dest:
  439. memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN);
  440. return 1;
  441. }
  442. /* very simplistic detection of IPv4 or IPv6 headers */
  443. static bool possibly_iphdr(const char *data)
  444. {
  445. return (data[0] & 0xd0) == 0x40;
  446. }
  447. /* disallow addresses which may be confused with IP headers */
  448. static int qmi_wwan_mac_addr(struct net_device *dev, void *p)
  449. {
  450. int ret;
  451. struct sockaddr *addr = p;
  452. ret = eth_prepare_mac_addr_change(dev, p);
  453. if (ret < 0)
  454. return ret;
  455. if (possibly_iphdr(addr->sa_data))
  456. return -EADDRNOTAVAIL;
  457. eth_commit_mac_addr_change(dev, p);
  458. return 0;
  459. }
  460. static const struct net_device_ops qmi_wwan_netdev_ops = {
  461. .ndo_open = usbnet_open,
  462. .ndo_stop = usbnet_stop,
  463. .ndo_start_xmit = usbnet_start_xmit,
  464. .ndo_tx_timeout = usbnet_tx_timeout,
  465. .ndo_change_mtu = usbnet_change_mtu,
  466. .ndo_get_stats64 = usbnet_get_stats64,
  467. .ndo_set_mac_address = qmi_wwan_mac_addr,
  468. .ndo_validate_addr = eth_validate_addr,
  469. };
  470. /* using a counter to merge subdriver requests with our own into a
  471. * combined state
  472. */
  473. static int qmi_wwan_manage_power(struct usbnet *dev, int on)
  474. {
  475. struct qmi_wwan_state *info = (void *)&dev->data;
  476. int rv;
  477. dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__,
  478. atomic_read(&info->pmcount), on);
  479. if ((on && atomic_add_return(1, &info->pmcount) == 1) ||
  480. (!on && atomic_dec_and_test(&info->pmcount))) {
  481. /* need autopm_get/put here to ensure the usbcore sees
  482. * the new value
  483. */
  484. rv = usb_autopm_get_interface(dev->intf);
  485. dev->intf->needs_remote_wakeup = on;
  486. if (!rv)
  487. usb_autopm_put_interface(dev->intf);
  488. }
  489. return 0;
  490. }
  491. static int qmi_wwan_cdc_wdm_manage_power(struct usb_interface *intf, int on)
  492. {
  493. struct usbnet *dev = usb_get_intfdata(intf);
  494. /* can be called while disconnecting */
  495. if (!dev)
  496. return 0;
  497. return qmi_wwan_manage_power(dev, on);
  498. }
  499. /* collect all three endpoints and register subdriver */
  500. static int qmi_wwan_register_subdriver(struct usbnet *dev)
  501. {
  502. int rv;
  503. struct usb_driver *subdriver = NULL;
  504. struct qmi_wwan_state *info = (void *)&dev->data;
  505. /* collect bulk endpoints */
  506. rv = usbnet_get_endpoints(dev, info->data);
  507. if (rv < 0)
  508. goto err;
  509. /* update status endpoint if separate control interface */
  510. if (info->control != info->data)
  511. dev->status = &info->control->cur_altsetting->endpoint[0];
  512. /* require interrupt endpoint for subdriver */
  513. if (!dev->status) {
  514. rv = -EINVAL;
  515. goto err;
  516. }
  517. /* for subdriver power management */
  518. atomic_set(&info->pmcount, 0);
  519. /* register subdriver */
  520. subdriver = usb_cdc_wdm_register(info->control, &dev->status->desc,
  521. 4096, &qmi_wwan_cdc_wdm_manage_power);
  522. if (IS_ERR(subdriver)) {
  523. dev_err(&info->control->dev, "subdriver registration failed\n");
  524. rv = PTR_ERR(subdriver);
  525. goto err;
  526. }
  527. /* prevent usbnet from using status endpoint */
  528. dev->status = NULL;
  529. /* save subdriver struct for suspend/resume wrappers */
  530. info->subdriver = subdriver;
  531. err:
  532. return rv;
  533. }
  534. /* Send CDC SetControlLineState request, setting or clearing the DTR.
  535. * "Required for Autoconnect and 9x30 to wake up" according to the
  536. * GobiNet driver. The requirement has been verified on an MDM9230
  537. * based Sierra Wireless MC7455
  538. */
  539. static int qmi_wwan_change_dtr(struct usbnet *dev, bool on)
  540. {
  541. u8 intf = dev->intf->cur_altsetting->desc.bInterfaceNumber;
  542. return usbnet_write_cmd(dev, USB_CDC_REQ_SET_CONTROL_LINE_STATE,
  543. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  544. on ? 0x01 : 0x00, intf, NULL, 0);
  545. }
  546. static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
  547. {
  548. int status = -1;
  549. u8 *buf = intf->cur_altsetting->extra;
  550. int len = intf->cur_altsetting->extralen;
  551. struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc;
  552. struct usb_cdc_union_desc *cdc_union;
  553. struct usb_cdc_ether_desc *cdc_ether;
  554. struct usb_driver *driver = driver_of(intf);
  555. struct qmi_wwan_state *info = (void *)&dev->data;
  556. struct usb_cdc_parsed_header hdr;
  557. BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) <
  558. sizeof(struct qmi_wwan_state)));
  559. /* set up initial state */
  560. info->control = intf;
  561. info->data = intf;
  562. /* and a number of CDC descriptors */
  563. cdc_parse_cdc_header(&hdr, intf, buf, len);
  564. cdc_union = hdr.usb_cdc_union_desc;
  565. cdc_ether = hdr.usb_cdc_ether_desc;
  566. /* Use separate control and data interfaces if we found a CDC Union */
  567. if (cdc_union) {
  568. info->data = usb_ifnum_to_if(dev->udev,
  569. cdc_union->bSlaveInterface0);
  570. if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 ||
  571. !info->data) {
  572. dev_err(&intf->dev,
  573. "bogus CDC Union: master=%u, slave=%u\n",
  574. cdc_union->bMasterInterface0,
  575. cdc_union->bSlaveInterface0);
  576. /* ignore and continue... */
  577. cdc_union = NULL;
  578. info->data = intf;
  579. }
  580. }
  581. /* errors aren't fatal - we can live with the dynamic address */
  582. if (cdc_ether && cdc_ether->wMaxSegmentSize) {
  583. dev->hard_mtu = le16_to_cpu(cdc_ether->wMaxSegmentSize);
  584. usbnet_get_ethernet_addr(dev, cdc_ether->iMACAddress);
  585. }
  586. /* claim data interface and set it up */
  587. if (info->control != info->data) {
  588. status = usb_driver_claim_interface(driver, info->data, dev);
  589. if (status < 0)
  590. goto err;
  591. }
  592. status = qmi_wwan_register_subdriver(dev);
  593. if (status < 0 && info->control != info->data) {
  594. usb_set_intfdata(info->data, NULL);
  595. usb_driver_release_interface(driver, info->data);
  596. }
  597. /* disabling remote wakeup on MDM9x30 devices has the same
  598. * effect as clearing DTR. The device will not respond to QMI
  599. * requests until we set DTR again. This is similar to a
  600. * QMI_CTL SYNC request, clearing a lot of firmware state
  601. * including the client ID allocations.
  602. *
  603. * Our usage model allows a session to span multiple
  604. * open/close events, so we must prevent the firmware from
  605. * clearing out state the clients might need.
  606. *
  607. * MDM9x30 is the first QMI chipset with USB3 support. Abuse
  608. * this fact to enable the quirk for all USB3 devices.
  609. *
  610. * There are also chipsets with the same "set DTR" requirement
  611. * but without USB3 support. Devices based on these chips
  612. * need a quirk flag in the device ID table.
  613. */
  614. if (dev->driver_info->data & QMI_WWAN_QUIRK_DTR ||
  615. le16_to_cpu(dev->udev->descriptor.bcdUSB) >= 0x0201) {
  616. qmi_wwan_manage_power(dev, 1);
  617. qmi_wwan_change_dtr(dev, true);
  618. }
  619. /* Never use the same address on both ends of the link, even if the
  620. * buggy firmware told us to. Or, if device is assigned the well-known
  621. * buggy firmware MAC address, replace it with a random address,
  622. */
  623. if (ether_addr_equal(dev->net->dev_addr, default_modem_addr) ||
  624. ether_addr_equal(dev->net->dev_addr, buggy_fw_addr))
  625. eth_hw_addr_random(dev->net);
  626. /* make MAC addr easily distinguishable from an IP header */
  627. if (possibly_iphdr(dev->net->dev_addr)) {
  628. dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */
  629. dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */
  630. }
  631. dev->net->netdev_ops = &qmi_wwan_netdev_ops;
  632. dev->net->sysfs_groups[0] = &qmi_wwan_sysfs_attr_group;
  633. err:
  634. return status;
  635. }
  636. static void qmi_wwan_unbind(struct usbnet *dev, struct usb_interface *intf)
  637. {
  638. struct qmi_wwan_state *info = (void *)&dev->data;
  639. struct usb_driver *driver = driver_of(intf);
  640. struct usb_interface *other;
  641. if (info->subdriver && info->subdriver->disconnect)
  642. info->subdriver->disconnect(info->control);
  643. /* disable MDM9x30 quirk */
  644. if (le16_to_cpu(dev->udev->descriptor.bcdUSB) >= 0x0201) {
  645. qmi_wwan_change_dtr(dev, false);
  646. qmi_wwan_manage_power(dev, 0);
  647. }
  648. /* allow user to unbind using either control or data */
  649. if (intf == info->control)
  650. other = info->data;
  651. else
  652. other = info->control;
  653. /* only if not shared */
  654. if (other && intf != other) {
  655. usb_set_intfdata(other, NULL);
  656. usb_driver_release_interface(driver, other);
  657. }
  658. info->subdriver = NULL;
  659. info->data = NULL;
  660. info->control = NULL;
  661. }
  662. /* suspend/resume wrappers calling both usbnet and the cdc-wdm
  663. * subdriver if present.
  664. *
  665. * NOTE: cdc-wdm also supports pre/post_reset, but we cannot provide
  666. * wrappers for those without adding usbnet reset support first.
  667. */
  668. static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)
  669. {
  670. struct usbnet *dev = usb_get_intfdata(intf);
  671. struct qmi_wwan_state *info = (void *)&dev->data;
  672. int ret;
  673. /* Both usbnet_suspend() and subdriver->suspend() MUST return 0
  674. * in system sleep context, otherwise, the resume callback has
  675. * to recover device from previous suspend failure.
  676. */
  677. ret = usbnet_suspend(intf, message);
  678. if (ret < 0)
  679. goto err;
  680. if (intf == info->control && info->subdriver &&
  681. info->subdriver->suspend)
  682. ret = info->subdriver->suspend(intf, message);
  683. if (ret < 0)
  684. usbnet_resume(intf);
  685. err:
  686. return ret;
  687. }
  688. static int qmi_wwan_resume(struct usb_interface *intf)
  689. {
  690. struct usbnet *dev = usb_get_intfdata(intf);
  691. struct qmi_wwan_state *info = (void *)&dev->data;
  692. int ret = 0;
  693. bool callsub = (intf == info->control && info->subdriver &&
  694. info->subdriver->resume);
  695. if (callsub)
  696. ret = info->subdriver->resume(intf);
  697. if (ret < 0)
  698. goto err;
  699. ret = usbnet_resume(intf);
  700. if (ret < 0 && callsub)
  701. info->subdriver->suspend(intf, PMSG_SUSPEND);
  702. err:
  703. return ret;
  704. }
  705. static const struct driver_info qmi_wwan_info = {
  706. .description = "WWAN/QMI device",
  707. .flags = FLAG_WWAN | FLAG_SEND_ZLP,
  708. .bind = qmi_wwan_bind,
  709. .unbind = qmi_wwan_unbind,
  710. .manage_power = qmi_wwan_manage_power,
  711. .rx_fixup = qmi_wwan_rx_fixup,
  712. };
  713. static const struct driver_info qmi_wwan_info_quirk_dtr = {
  714. .description = "WWAN/QMI device",
  715. .flags = FLAG_WWAN | FLAG_SEND_ZLP,
  716. .bind = qmi_wwan_bind,
  717. .unbind = qmi_wwan_unbind,
  718. .manage_power = qmi_wwan_manage_power,
  719. .rx_fixup = qmi_wwan_rx_fixup,
  720. .data = QMI_WWAN_QUIRK_DTR,
  721. };
  722. #define HUAWEI_VENDOR_ID 0x12D1
  723. /* map QMI/wwan function by a fixed interface number */
  724. #define QMI_FIXED_INTF(vend, prod, num) \
  725. USB_DEVICE_INTERFACE_NUMBER(vend, prod, num), \
  726. .driver_info = (unsigned long)&qmi_wwan_info
  727. /* devices requiring "set DTR" quirk */
  728. #define QMI_QUIRK_SET_DTR(vend, prod, num) \
  729. USB_DEVICE_INTERFACE_NUMBER(vend, prod, num), \
  730. .driver_info = (unsigned long)&qmi_wwan_info_quirk_dtr
  731. /* Gobi 1000 QMI/wwan interface number is 3 according to qcserial */
  732. #define QMI_GOBI1K_DEVICE(vend, prod) \
  733. QMI_FIXED_INTF(vend, prod, 3)
  734. /* Gobi 2000/3000 QMI/wwan interface number is 0 according to qcserial */
  735. #define QMI_GOBI_DEVICE(vend, prod) \
  736. QMI_FIXED_INTF(vend, prod, 0)
  737. /* Many devices have QMI and DIAG functions which are distinguishable
  738. * from other vendor specific functions by class, subclass and
  739. * protocol all being 0xff. The DIAG function has exactly 2 endpoints
  740. * and is silently rejected when probed.
  741. *
  742. * This makes it possible to match dynamically numbered QMI functions
  743. * as seen on e.g. many Quectel modems.
  744. */
  745. #define QMI_MATCH_FF_FF_FF(vend, prod) \
  746. USB_DEVICE_AND_INTERFACE_INFO(vend, prod, USB_CLASS_VENDOR_SPEC, \
  747. USB_SUBCLASS_VENDOR_SPEC, 0xff), \
  748. .driver_info = (unsigned long)&qmi_wwan_info_quirk_dtr
  749. static const struct usb_device_id products[] = {
  750. /* 1. CDC ECM like devices match on the control interface */
  751. { /* Huawei E392, E398 and possibly others sharing both device id and more... */
  752. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 9),
  753. .driver_info = (unsigned long)&qmi_wwan_info,
  754. },
  755. { /* Vodafone/Huawei K5005 (12d1:14c8) and similar modems */
  756. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 57),
  757. .driver_info = (unsigned long)&qmi_wwan_info,
  758. },
  759. { /* HUAWEI_INTERFACE_NDIS_CONTROL_QUALCOMM */
  760. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 0x01, 0x69),
  761. .driver_info = (unsigned long)&qmi_wwan_info,
  762. },
  763. { /* Motorola Mapphone devices with MDM6600 */
  764. USB_VENDOR_AND_INTERFACE_INFO(0x22b8, USB_CLASS_VENDOR_SPEC, 0xfb, 0xff),
  765. .driver_info = (unsigned long)&qmi_wwan_info,
  766. },
  767. /* 2. Combined interface devices matching on class+protocol */
  768. { /* Huawei E367 and possibly others in "Windows mode" */
  769. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 7),
  770. .driver_info = (unsigned long)&qmi_wwan_info,
  771. },
  772. { /* Huawei E392, E398 and possibly others in "Windows mode" */
  773. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 1, 17),
  774. .driver_info = (unsigned long)&qmi_wwan_info,
  775. },
  776. { /* HUAWEI_NDIS_SINGLE_INTERFACE_VDF */
  777. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 0x01, 0x37),
  778. .driver_info = (unsigned long)&qmi_wwan_info,
  779. },
  780. { /* HUAWEI_INTERFACE_NDIS_HW_QUALCOMM */
  781. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_VENDOR_SPEC, 0x01, 0x67),
  782. .driver_info = (unsigned long)&qmi_wwan_info,
  783. },
  784. { /* Pantech UML290, P4200 and more */
  785. USB_VENDOR_AND_INTERFACE_INFO(0x106c, USB_CLASS_VENDOR_SPEC, 0xf0, 0xff),
  786. .driver_info = (unsigned long)&qmi_wwan_info,
  787. },
  788. { /* Pantech UML290 - newer firmware */
  789. USB_VENDOR_AND_INTERFACE_INFO(0x106c, USB_CLASS_VENDOR_SPEC, 0xf1, 0xff),
  790. .driver_info = (unsigned long)&qmi_wwan_info,
  791. },
  792. { /* Novatel USB551L and MC551 */
  793. USB_DEVICE_AND_INTERFACE_INFO(0x1410, 0xb001,
  794. USB_CLASS_COMM,
  795. USB_CDC_SUBCLASS_ETHERNET,
  796. USB_CDC_PROTO_NONE),
  797. .driver_info = (unsigned long)&qmi_wwan_info,
  798. },
  799. { /* Novatel E362 */
  800. USB_DEVICE_AND_INTERFACE_INFO(0x1410, 0x9010,
  801. USB_CLASS_COMM,
  802. USB_CDC_SUBCLASS_ETHERNET,
  803. USB_CDC_PROTO_NONE),
  804. .driver_info = (unsigned long)&qmi_wwan_info,
  805. },
  806. { /* Novatel Expedite E371 */
  807. USB_DEVICE_AND_INTERFACE_INFO(0x1410, 0x9011,
  808. USB_CLASS_COMM,
  809. USB_CDC_SUBCLASS_ETHERNET,
  810. USB_CDC_PROTO_NONE),
  811. .driver_info = (unsigned long)&qmi_wwan_info,
  812. },
  813. { /* Dell Wireless 5800 (Novatel E362) */
  814. USB_DEVICE_AND_INTERFACE_INFO(0x413C, 0x8195,
  815. USB_CLASS_COMM,
  816. USB_CDC_SUBCLASS_ETHERNET,
  817. USB_CDC_PROTO_NONE),
  818. .driver_info = (unsigned long)&qmi_wwan_info,
  819. },
  820. { /* Dell Wireless 5800 V2 (Novatel E362) */
  821. USB_DEVICE_AND_INTERFACE_INFO(0x413C, 0x8196,
  822. USB_CLASS_COMM,
  823. USB_CDC_SUBCLASS_ETHERNET,
  824. USB_CDC_PROTO_NONE),
  825. .driver_info = (unsigned long)&qmi_wwan_info,
  826. },
  827. { /* Dell Wireless 5804 (Novatel E371) */
  828. USB_DEVICE_AND_INTERFACE_INFO(0x413C, 0x819b,
  829. USB_CLASS_COMM,
  830. USB_CDC_SUBCLASS_ETHERNET,
  831. USB_CDC_PROTO_NONE),
  832. .driver_info = (unsigned long)&qmi_wwan_info,
  833. },
  834. { /* ADU960S */
  835. USB_DEVICE_AND_INTERFACE_INFO(0x16d5, 0x650a,
  836. USB_CLASS_COMM,
  837. USB_CDC_SUBCLASS_ETHERNET,
  838. USB_CDC_PROTO_NONE),
  839. .driver_info = (unsigned long)&qmi_wwan_info,
  840. },
  841. { /* HP lt2523 (Novatel E371) */
  842. USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0x421d,
  843. USB_CLASS_COMM,
  844. USB_CDC_SUBCLASS_ETHERNET,
  845. USB_CDC_PROTO_NONE),
  846. .driver_info = (unsigned long)&qmi_wwan_info,
  847. },
  848. { /* HP lt4112 LTE/HSPA+ Gobi 4G Module (Huawei me906e) */
  849. USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0x581d, USB_CLASS_VENDOR_SPEC, 1, 7),
  850. .driver_info = (unsigned long)&qmi_wwan_info,
  851. },
  852. {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0125)}, /* Quectel EC25, EC20 R2.0 Mini PCIe */
  853. {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0306)}, /* Quectel EP06/EG06/EM06 */
  854. {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0512)}, /* Quectel EG12/EM12 */
  855. {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0620)}, /* Quectel EM160R-GL */
  856. {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0800)}, /* Quectel RM500Q-GL */
  857. /* 3. Combined interface devices matching on interface number */
  858. {QMI_FIXED_INTF(0x0408, 0xea42, 4)}, /* Yota / Megafon M100-1 */
  859. {QMI_FIXED_INTF(0x05c6, 0x6001, 3)}, /* 4G LTE usb-modem U901 */
  860. {QMI_FIXED_INTF(0x05c6, 0x7000, 0)},
  861. {QMI_FIXED_INTF(0x05c6, 0x7001, 1)},
  862. {QMI_FIXED_INTF(0x05c6, 0x7002, 1)},
  863. {QMI_FIXED_INTF(0x05c6, 0x7101, 1)},
  864. {QMI_FIXED_INTF(0x05c6, 0x7101, 2)},
  865. {QMI_FIXED_INTF(0x05c6, 0x7101, 3)},
  866. {QMI_FIXED_INTF(0x05c6, 0x7102, 1)},
  867. {QMI_FIXED_INTF(0x05c6, 0x7102, 2)},
  868. {QMI_FIXED_INTF(0x05c6, 0x7102, 3)},
  869. {QMI_FIXED_INTF(0x05c6, 0x8000, 7)},
  870. {QMI_FIXED_INTF(0x05c6, 0x8001, 6)},
  871. {QMI_FIXED_INTF(0x05c6, 0x9000, 4)},
  872. {QMI_FIXED_INTF(0x05c6, 0x9003, 4)},
  873. {QMI_FIXED_INTF(0x05c6, 0x9005, 2)},
  874. {QMI_FIXED_INTF(0x05c6, 0x900a, 4)},
  875. {QMI_FIXED_INTF(0x05c6, 0x900b, 2)},
  876. {QMI_FIXED_INTF(0x05c6, 0x900c, 4)},
  877. {QMI_FIXED_INTF(0x05c6, 0x900c, 5)},
  878. {QMI_FIXED_INTF(0x05c6, 0x900c, 6)},
  879. {QMI_FIXED_INTF(0x05c6, 0x900d, 5)},
  880. {QMI_FIXED_INTF(0x05c6, 0x900f, 3)},
  881. {QMI_FIXED_INTF(0x05c6, 0x900f, 4)},
  882. {QMI_FIXED_INTF(0x05c6, 0x900f, 5)},
  883. {QMI_FIXED_INTF(0x05c6, 0x9010, 4)},
  884. {QMI_FIXED_INTF(0x05c6, 0x9010, 5)},
  885. {QMI_FIXED_INTF(0x05c6, 0x9011, 3)},
  886. {QMI_FIXED_INTF(0x05c6, 0x9011, 4)},
  887. {QMI_FIXED_INTF(0x05c6, 0x9021, 1)},
  888. {QMI_FIXED_INTF(0x05c6, 0x9022, 2)},
  889. {QMI_QUIRK_SET_DTR(0x05c6, 0x9025, 4)}, /* Alcatel-sbell ASB TL131 TDD LTE (China Mobile) */
  890. {QMI_FIXED_INTF(0x05c6, 0x9026, 3)},
  891. {QMI_FIXED_INTF(0x05c6, 0x902e, 5)},
  892. {QMI_FIXED_INTF(0x05c6, 0x9031, 5)},
  893. {QMI_FIXED_INTF(0x05c6, 0x9032, 4)},
  894. {QMI_FIXED_INTF(0x05c6, 0x9033, 3)},
  895. {QMI_FIXED_INTF(0x05c6, 0x9033, 4)},
  896. {QMI_FIXED_INTF(0x05c6, 0x9033, 5)},
  897. {QMI_FIXED_INTF(0x05c6, 0x9033, 6)},
  898. {QMI_FIXED_INTF(0x05c6, 0x9034, 3)},
  899. {QMI_FIXED_INTF(0x05c6, 0x9034, 4)},
  900. {QMI_FIXED_INTF(0x05c6, 0x9034, 5)},
  901. {QMI_FIXED_INTF(0x05c6, 0x9034, 6)},
  902. {QMI_FIXED_INTF(0x05c6, 0x9034, 7)},
  903. {QMI_FIXED_INTF(0x05c6, 0x9035, 4)},
  904. {QMI_FIXED_INTF(0x05c6, 0x9036, 3)},
  905. {QMI_FIXED_INTF(0x05c6, 0x9037, 5)},
  906. {QMI_FIXED_INTF(0x05c6, 0x9038, 4)},
  907. {QMI_FIXED_INTF(0x05c6, 0x903b, 7)},
  908. {QMI_FIXED_INTF(0x05c6, 0x903c, 6)},
  909. {QMI_FIXED_INTF(0x05c6, 0x903d, 6)},
  910. {QMI_FIXED_INTF(0x05c6, 0x903e, 5)},
  911. {QMI_FIXED_INTF(0x05c6, 0x9043, 3)},
  912. {QMI_FIXED_INTF(0x05c6, 0x9046, 3)},
  913. {QMI_FIXED_INTF(0x05c6, 0x9046, 4)},
  914. {QMI_FIXED_INTF(0x05c6, 0x9046, 5)},
  915. {QMI_FIXED_INTF(0x05c6, 0x9047, 2)},
  916. {QMI_FIXED_INTF(0x05c6, 0x9047, 3)},
  917. {QMI_FIXED_INTF(0x05c6, 0x9047, 4)},
  918. {QMI_FIXED_INTF(0x05c6, 0x9048, 4)},
  919. {QMI_FIXED_INTF(0x05c6, 0x9048, 5)},
  920. {QMI_FIXED_INTF(0x05c6, 0x9048, 6)},
  921. {QMI_FIXED_INTF(0x05c6, 0x9048, 7)},
  922. {QMI_FIXED_INTF(0x05c6, 0x9048, 8)},
  923. {QMI_FIXED_INTF(0x05c6, 0x904c, 5)},
  924. {QMI_FIXED_INTF(0x05c6, 0x904c, 6)},
  925. {QMI_FIXED_INTF(0x05c6, 0x904c, 7)},
  926. {QMI_FIXED_INTF(0x05c6, 0x904c, 8)},
  927. {QMI_FIXED_INTF(0x05c6, 0x9050, 3)},
  928. {QMI_FIXED_INTF(0x05c6, 0x9052, 4)},
  929. {QMI_FIXED_INTF(0x05c6, 0x9053, 6)},
  930. {QMI_FIXED_INTF(0x05c6, 0x9053, 7)},
  931. {QMI_FIXED_INTF(0x05c6, 0x9054, 5)},
  932. {QMI_FIXED_INTF(0x05c6, 0x9054, 6)},
  933. {QMI_FIXED_INTF(0x05c6, 0x9055, 3)},
  934. {QMI_FIXED_INTF(0x05c6, 0x9055, 4)},
  935. {QMI_FIXED_INTF(0x05c6, 0x9055, 5)},
  936. {QMI_FIXED_INTF(0x05c6, 0x9055, 6)},
  937. {QMI_FIXED_INTF(0x05c6, 0x9055, 7)},
  938. {QMI_FIXED_INTF(0x05c6, 0x9056, 3)},
  939. {QMI_FIXED_INTF(0x05c6, 0x9062, 2)},
  940. {QMI_FIXED_INTF(0x05c6, 0x9062, 3)},
  941. {QMI_FIXED_INTF(0x05c6, 0x9062, 4)},
  942. {QMI_FIXED_INTF(0x05c6, 0x9062, 5)},
  943. {QMI_FIXED_INTF(0x05c6, 0x9062, 6)},
  944. {QMI_FIXED_INTF(0x05c6, 0x9062, 7)},
  945. {QMI_FIXED_INTF(0x05c6, 0x9062, 8)},
  946. {QMI_FIXED_INTF(0x05c6, 0x9062, 9)},
  947. {QMI_FIXED_INTF(0x05c6, 0x9064, 3)},
  948. {QMI_FIXED_INTF(0x05c6, 0x9065, 6)},
  949. {QMI_FIXED_INTF(0x05c6, 0x9065, 7)},
  950. {QMI_FIXED_INTF(0x05c6, 0x9066, 5)},
  951. {QMI_FIXED_INTF(0x05c6, 0x9066, 6)},
  952. {QMI_FIXED_INTF(0x05c6, 0x9067, 1)},
  953. {QMI_FIXED_INTF(0x05c6, 0x9068, 2)},
  954. {QMI_FIXED_INTF(0x05c6, 0x9068, 3)},
  955. {QMI_FIXED_INTF(0x05c6, 0x9068, 4)},
  956. {QMI_FIXED_INTF(0x05c6, 0x9068, 5)},
  957. {QMI_FIXED_INTF(0x05c6, 0x9068, 6)},
  958. {QMI_FIXED_INTF(0x05c6, 0x9068, 7)},
  959. {QMI_FIXED_INTF(0x05c6, 0x9069, 5)},
  960. {QMI_FIXED_INTF(0x05c6, 0x9069, 6)},
  961. {QMI_FIXED_INTF(0x05c6, 0x9069, 7)},
  962. {QMI_FIXED_INTF(0x05c6, 0x9069, 8)},
  963. {QMI_FIXED_INTF(0x05c6, 0x9070, 4)},
  964. {QMI_FIXED_INTF(0x05c6, 0x9070, 5)},
  965. {QMI_FIXED_INTF(0x05c6, 0x9075, 5)},
  966. {QMI_FIXED_INTF(0x05c6, 0x9076, 4)},
  967. {QMI_FIXED_INTF(0x05c6, 0x9076, 5)},
  968. {QMI_FIXED_INTF(0x05c6, 0x9076, 6)},
  969. {QMI_FIXED_INTF(0x05c6, 0x9076, 7)},
  970. {QMI_FIXED_INTF(0x05c6, 0x9076, 8)},
  971. {QMI_FIXED_INTF(0x05c6, 0x9077, 3)},
  972. {QMI_FIXED_INTF(0x05c6, 0x9077, 4)},
  973. {QMI_FIXED_INTF(0x05c6, 0x9077, 5)},
  974. {QMI_FIXED_INTF(0x05c6, 0x9077, 6)},
  975. {QMI_FIXED_INTF(0x05c6, 0x9078, 3)},
  976. {QMI_FIXED_INTF(0x05c6, 0x9079, 4)},
  977. {QMI_FIXED_INTF(0x05c6, 0x9079, 5)},
  978. {QMI_FIXED_INTF(0x05c6, 0x9079, 6)},
  979. {QMI_FIXED_INTF(0x05c6, 0x9079, 7)},
  980. {QMI_FIXED_INTF(0x05c6, 0x9079, 8)},
  981. {QMI_FIXED_INTF(0x05c6, 0x9080, 5)},
  982. {QMI_FIXED_INTF(0x05c6, 0x9080, 6)},
  983. {QMI_FIXED_INTF(0x05c6, 0x9080, 7)},
  984. {QMI_FIXED_INTF(0x05c6, 0x9080, 8)},
  985. {QMI_FIXED_INTF(0x05c6, 0x9083, 3)},
  986. {QMI_FIXED_INTF(0x05c6, 0x9084, 4)},
  987. {QMI_FIXED_INTF(0x05c6, 0x90b2, 3)}, /* ublox R410M */
  988. {QMI_FIXED_INTF(0x05c6, 0x920d, 0)},
  989. {QMI_FIXED_INTF(0x05c6, 0x920d, 5)},
  990. {QMI_QUIRK_SET_DTR(0x05c6, 0x9625, 4)}, /* YUGA CLM920-NC5 */
  991. {QMI_FIXED_INTF(0x0846, 0x68a2, 8)},
  992. {QMI_FIXED_INTF(0x0846, 0x68d3, 8)}, /* Netgear Aircard 779S */
  993. {QMI_FIXED_INTF(0x12d1, 0x140c, 1)}, /* Huawei E173 */
  994. {QMI_FIXED_INTF(0x12d1, 0x14ac, 1)}, /* Huawei E1820 */
  995. {QMI_FIXED_INTF(0x1435, 0x0918, 3)}, /* Wistron NeWeb D16Q1 */
  996. {QMI_FIXED_INTF(0x1435, 0x0918, 4)}, /* Wistron NeWeb D16Q1 */
  997. {QMI_FIXED_INTF(0x1435, 0x0918, 5)}, /* Wistron NeWeb D16Q1 */
  998. {QMI_FIXED_INTF(0x1435, 0x3185, 4)}, /* Wistron NeWeb M18Q5 */
  999. {QMI_FIXED_INTF(0x1435, 0xd111, 4)}, /* M9615A DM11-1 D51QC */
  1000. {QMI_FIXED_INTF(0x1435, 0xd181, 3)}, /* Wistron NeWeb D18Q1 */
  1001. {QMI_FIXED_INTF(0x1435, 0xd181, 4)}, /* Wistron NeWeb D18Q1 */
  1002. {QMI_FIXED_INTF(0x1435, 0xd181, 5)}, /* Wistron NeWeb D18Q1 */
  1003. {QMI_FIXED_INTF(0x1435, 0xd182, 4)}, /* Wistron NeWeb D18 */
  1004. {QMI_FIXED_INTF(0x1435, 0xd182, 5)}, /* Wistron NeWeb D18 */
  1005. {QMI_FIXED_INTF(0x1435, 0xd191, 4)}, /* Wistron NeWeb D19Q1 */
  1006. {QMI_QUIRK_SET_DTR(0x1508, 0x1001, 4)}, /* Fibocom NL668 series */
  1007. {QMI_FIXED_INTF(0x1690, 0x7588, 4)}, /* ASKEY WWHC050 */
  1008. {QMI_FIXED_INTF(0x16d8, 0x6003, 0)}, /* CMOTech 6003 */
  1009. {QMI_FIXED_INTF(0x16d8, 0x6007, 0)}, /* CMOTech CHE-628S */
  1010. {QMI_FIXED_INTF(0x16d8, 0x6008, 0)}, /* CMOTech CMU-301 */
  1011. {QMI_FIXED_INTF(0x16d8, 0x6280, 0)}, /* CMOTech CHU-628 */
  1012. {QMI_FIXED_INTF(0x16d8, 0x7001, 0)}, /* CMOTech CHU-720S */
  1013. {QMI_FIXED_INTF(0x16d8, 0x7002, 0)}, /* CMOTech 7002 */
  1014. {QMI_FIXED_INTF(0x16d8, 0x7003, 4)}, /* CMOTech CHU-629K */
  1015. {QMI_FIXED_INTF(0x16d8, 0x7004, 3)}, /* CMOTech 7004 */
  1016. {QMI_FIXED_INTF(0x16d8, 0x7006, 5)}, /* CMOTech CGU-629 */
  1017. {QMI_FIXED_INTF(0x16d8, 0x700a, 4)}, /* CMOTech CHU-629S */
  1018. {QMI_FIXED_INTF(0x16d8, 0x7211, 0)}, /* CMOTech CHU-720I */
  1019. {QMI_FIXED_INTF(0x16d8, 0x7212, 0)}, /* CMOTech 7212 */
  1020. {QMI_FIXED_INTF(0x16d8, 0x7213, 0)}, /* CMOTech 7213 */
  1021. {QMI_FIXED_INTF(0x16d8, 0x7251, 1)}, /* CMOTech 7251 */
  1022. {QMI_FIXED_INTF(0x16d8, 0x7252, 1)}, /* CMOTech 7252 */
  1023. {QMI_FIXED_INTF(0x16d8, 0x7253, 1)}, /* CMOTech 7253 */
  1024. {QMI_FIXED_INTF(0x19d2, 0x0002, 1)},
  1025. {QMI_FIXED_INTF(0x19d2, 0x0012, 1)},
  1026. {QMI_FIXED_INTF(0x19d2, 0x0017, 3)},
  1027. {QMI_FIXED_INTF(0x19d2, 0x0019, 3)}, /* ONDA MT689DC */
  1028. {QMI_FIXED_INTF(0x19d2, 0x0021, 4)},
  1029. {QMI_FIXED_INTF(0x19d2, 0x0025, 1)},
  1030. {QMI_FIXED_INTF(0x19d2, 0x0031, 4)},
  1031. {QMI_FIXED_INTF(0x19d2, 0x0042, 4)},
  1032. {QMI_FIXED_INTF(0x19d2, 0x0049, 5)},
  1033. {QMI_FIXED_INTF(0x19d2, 0x0052, 4)},
  1034. {QMI_FIXED_INTF(0x19d2, 0x0055, 1)}, /* ZTE (Vodafone) K3520-Z */
  1035. {QMI_FIXED_INTF(0x19d2, 0x0058, 4)},
  1036. {QMI_FIXED_INTF(0x19d2, 0x0063, 4)}, /* ZTE (Vodafone) K3565-Z */
  1037. {QMI_FIXED_INTF(0x19d2, 0x0104, 4)}, /* ZTE (Vodafone) K4505-Z */
  1038. {QMI_FIXED_INTF(0x19d2, 0x0113, 5)},
  1039. {QMI_FIXED_INTF(0x19d2, 0x0118, 5)},
  1040. {QMI_FIXED_INTF(0x19d2, 0x0121, 5)},
  1041. {QMI_FIXED_INTF(0x19d2, 0x0123, 4)},
  1042. {QMI_FIXED_INTF(0x19d2, 0x0124, 5)},
  1043. {QMI_FIXED_INTF(0x19d2, 0x0125, 6)},
  1044. {QMI_FIXED_INTF(0x19d2, 0x0126, 5)},
  1045. {QMI_FIXED_INTF(0x19d2, 0x0130, 1)},
  1046. {QMI_FIXED_INTF(0x19d2, 0x0133, 3)},
  1047. {QMI_FIXED_INTF(0x19d2, 0x0141, 5)},
  1048. {QMI_FIXED_INTF(0x19d2, 0x0157, 5)}, /* ZTE MF683 */
  1049. {QMI_FIXED_INTF(0x19d2, 0x0158, 3)},
  1050. {QMI_FIXED_INTF(0x19d2, 0x0167, 4)}, /* ZTE MF820D */
  1051. {QMI_FIXED_INTF(0x19d2, 0x0168, 4)},
  1052. {QMI_FIXED_INTF(0x19d2, 0x0176, 3)},
  1053. {QMI_FIXED_INTF(0x19d2, 0x0178, 3)},
  1054. {QMI_FIXED_INTF(0x19d2, 0x0191, 4)}, /* ZTE EuFi890 */
  1055. {QMI_FIXED_INTF(0x19d2, 0x0199, 1)}, /* ZTE MF820S */
  1056. {QMI_FIXED_INTF(0x19d2, 0x0200, 1)},
  1057. {QMI_FIXED_INTF(0x19d2, 0x0257, 3)}, /* ZTE MF821 */
  1058. {QMI_FIXED_INTF(0x19d2, 0x0265, 4)}, /* ONDA MT8205 4G LTE */
  1059. {QMI_FIXED_INTF(0x19d2, 0x0284, 4)}, /* ZTE MF880 */
  1060. {QMI_FIXED_INTF(0x19d2, 0x0326, 4)}, /* ZTE MF821D */
  1061. {QMI_FIXED_INTF(0x19d2, 0x0396, 3)}, /* ZTE ZM8620 */
  1062. {QMI_FIXED_INTF(0x19d2, 0x0412, 4)}, /* Telewell TW-LTE 4G */
  1063. {QMI_FIXED_INTF(0x19d2, 0x1008, 4)}, /* ZTE (Vodafone) K3570-Z */
  1064. {QMI_FIXED_INTF(0x19d2, 0x1010, 4)}, /* ZTE (Vodafone) K3571-Z */
  1065. {QMI_FIXED_INTF(0x19d2, 0x1012, 4)},
  1066. {QMI_FIXED_INTF(0x19d2, 0x1018, 3)}, /* ZTE (Vodafone) K5006-Z */
  1067. {QMI_FIXED_INTF(0x19d2, 0x1021, 2)},
  1068. {QMI_FIXED_INTF(0x19d2, 0x1245, 4)},
  1069. {QMI_FIXED_INTF(0x19d2, 0x1247, 4)},
  1070. {QMI_FIXED_INTF(0x19d2, 0x1252, 4)},
  1071. {QMI_FIXED_INTF(0x19d2, 0x1254, 4)},
  1072. {QMI_FIXED_INTF(0x19d2, 0x1255, 3)},
  1073. {QMI_FIXED_INTF(0x19d2, 0x1255, 4)},
  1074. {QMI_FIXED_INTF(0x19d2, 0x1256, 4)},
  1075. {QMI_FIXED_INTF(0x19d2, 0x1270, 5)}, /* ZTE MF667 */
  1076. {QMI_FIXED_INTF(0x19d2, 0x1275, 3)}, /* ZTE P685M */
  1077. {QMI_FIXED_INTF(0x19d2, 0x1401, 2)},
  1078. {QMI_FIXED_INTF(0x19d2, 0x1402, 2)}, /* ZTE MF60 */
  1079. {QMI_FIXED_INTF(0x19d2, 0x1424, 2)},
  1080. {QMI_FIXED_INTF(0x19d2, 0x1425, 2)},
  1081. {QMI_FIXED_INTF(0x19d2, 0x1426, 2)}, /* ZTE MF91 */
  1082. {QMI_FIXED_INTF(0x19d2, 0x1428, 2)}, /* Telewell TW-LTE 4G v2 */
  1083. {QMI_FIXED_INTF(0x19d2, 0x1432, 3)}, /* ZTE ME3620 */
  1084. {QMI_FIXED_INTF(0x19d2, 0x2002, 4)}, /* ZTE (Vodafone) K3765-Z */
  1085. {QMI_FIXED_INTF(0x2001, 0x7e16, 3)}, /* D-Link DWM-221 */
  1086. {QMI_FIXED_INTF(0x2001, 0x7e19, 4)}, /* D-Link DWM-221 B1 */
  1087. {QMI_FIXED_INTF(0x2001, 0x7e35, 4)}, /* D-Link DWM-222 */
  1088. {QMI_FIXED_INTF(0x2001, 0x7e3d, 4)}, /* D-Link DWM-222 A2 */
  1089. {QMI_FIXED_INTF(0x2020, 0x2031, 4)}, /* Olicard 600 */
  1090. {QMI_FIXED_INTF(0x2020, 0x2033, 4)}, /* BroadMobi BM806U */
  1091. {QMI_FIXED_INTF(0x2020, 0x2060, 4)}, /* BroadMobi BM818 */
  1092. {QMI_FIXED_INTF(0x0f3d, 0x68a2, 8)}, /* Sierra Wireless MC7700 */
  1093. {QMI_FIXED_INTF(0x114f, 0x68a2, 8)}, /* Sierra Wireless MC7750 */
  1094. {QMI_FIXED_INTF(0x1199, 0x68a2, 8)}, /* Sierra Wireless MC7710 in QMI mode */
  1095. {QMI_FIXED_INTF(0x1199, 0x68a2, 19)}, /* Sierra Wireless MC7710 in QMI mode */
  1096. {QMI_QUIRK_SET_DTR(0x1199, 0x68c0, 8)}, /* Sierra Wireless MC7304/MC7354, WP76xx */
  1097. {QMI_QUIRK_SET_DTR(0x1199, 0x68c0, 10)},/* Sierra Wireless MC7304/MC7354 */
  1098. {QMI_FIXED_INTF(0x1199, 0x901c, 8)}, /* Sierra Wireless EM7700 */
  1099. {QMI_FIXED_INTF(0x1199, 0x901f, 8)}, /* Sierra Wireless EM7355 */
  1100. {QMI_FIXED_INTF(0x1199, 0x9041, 8)}, /* Sierra Wireless MC7305/MC7355 */
  1101. {QMI_FIXED_INTF(0x1199, 0x9041, 10)}, /* Sierra Wireless MC7305/MC7355 */
  1102. {QMI_FIXED_INTF(0x1199, 0x9051, 8)}, /* Netgear AirCard 340U */
  1103. {QMI_FIXED_INTF(0x1199, 0x9053, 8)}, /* Sierra Wireless Modem */
  1104. {QMI_FIXED_INTF(0x1199, 0x9054, 8)}, /* Sierra Wireless Modem */
  1105. {QMI_FIXED_INTF(0x1199, 0x9055, 8)}, /* Netgear AirCard 341U */
  1106. {QMI_FIXED_INTF(0x1199, 0x9056, 8)}, /* Sierra Wireless Modem */
  1107. {QMI_FIXED_INTF(0x1199, 0x9057, 8)},
  1108. {QMI_FIXED_INTF(0x1199, 0x9061, 8)}, /* Sierra Wireless Modem */
  1109. {QMI_FIXED_INTF(0x1199, 0x9063, 8)}, /* Sierra Wireless EM7305 */
  1110. {QMI_FIXED_INTF(0x1199, 0x9063, 10)}, /* Sierra Wireless EM7305 */
  1111. {QMI_QUIRK_SET_DTR(0x1199, 0x9071, 8)}, /* Sierra Wireless MC74xx */
  1112. {QMI_QUIRK_SET_DTR(0x1199, 0x9071, 10)},/* Sierra Wireless MC74xx */
  1113. {QMI_QUIRK_SET_DTR(0x1199, 0x9079, 8)}, /* Sierra Wireless EM74xx */
  1114. {QMI_QUIRK_SET_DTR(0x1199, 0x9079, 10)},/* Sierra Wireless EM74xx */
  1115. {QMI_QUIRK_SET_DTR(0x1199, 0x907b, 8)}, /* Sierra Wireless EM74xx */
  1116. {QMI_QUIRK_SET_DTR(0x1199, 0x907b, 10)},/* Sierra Wireless EM74xx */
  1117. {QMI_QUIRK_SET_DTR(0x1199, 0x9091, 8)}, /* Sierra Wireless EM7565 */
  1118. {QMI_FIXED_INTF(0x1bbb, 0x011e, 4)}, /* Telekom Speedstick LTE II (Alcatel One Touch L100V LTE) */
  1119. {QMI_FIXED_INTF(0x1bbb, 0x0203, 2)}, /* Alcatel L800MA */
  1120. {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */
  1121. {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */
  1122. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1031, 3)}, /* Telit LE910C1-EUX */
  1123. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1040, 2)}, /* Telit LE922A */
  1124. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1050, 2)}, /* Telit FN980 */
  1125. {QMI_FIXED_INTF(0x1bc7, 0x1100, 3)}, /* Telit ME910 */
  1126. {QMI_FIXED_INTF(0x1bc7, 0x1101, 3)}, /* Telit ME910 dual modem */
  1127. {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */
  1128. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1201, 2)}, /* Telit LE920, LE920A4 */
  1129. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1230, 2)}, /* Telit LE910Cx */
  1130. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1260, 2)}, /* Telit LE910Cx */
  1131. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1261, 2)}, /* Telit LE910Cx */
  1132. {QMI_QUIRK_SET_DTR(0x1bc7, 0x1900, 1)}, /* Telit LN940 series */
  1133. {QMI_FIXED_INTF(0x1c9e, 0x9801, 3)}, /* Telewell TW-3G HSPA+ */
  1134. {QMI_FIXED_INTF(0x1c9e, 0x9803, 4)}, /* Telewell TW-3G HSPA+ */
  1135. {QMI_FIXED_INTF(0x1c9e, 0x9b01, 3)}, /* XS Stick W100-2 from 4G Systems */
  1136. {QMI_FIXED_INTF(0x0b3c, 0xc000, 4)}, /* Olivetti Olicard 100 */
  1137. {QMI_FIXED_INTF(0x0b3c, 0xc001, 4)}, /* Olivetti Olicard 120 */
  1138. {QMI_FIXED_INTF(0x0b3c, 0xc002, 4)}, /* Olivetti Olicard 140 */
  1139. {QMI_FIXED_INTF(0x0b3c, 0xc004, 6)}, /* Olivetti Olicard 155 */
  1140. {QMI_FIXED_INTF(0x0b3c, 0xc005, 6)}, /* Olivetti Olicard 200 */
  1141. {QMI_FIXED_INTF(0x0b3c, 0xc00a, 6)}, /* Olivetti Olicard 160 */
  1142. {QMI_FIXED_INTF(0x0b3c, 0xc00b, 4)}, /* Olivetti Olicard 500 */
  1143. {QMI_FIXED_INTF(0x1e2d, 0x0060, 4)}, /* Cinterion PLxx */
  1144. {QMI_QUIRK_SET_DTR(0x1e2d, 0x006f, 8)}, /* Cinterion PLS83/PLS63 */
  1145. {QMI_FIXED_INTF(0x1e2d, 0x0053, 4)}, /* Cinterion PHxx,PXxx */
  1146. {QMI_FIXED_INTF(0x1e2d, 0x0063, 10)}, /* Cinterion ALASxx (1 RmNet) */
  1147. {QMI_FIXED_INTF(0x1e2d, 0x0082, 4)}, /* Cinterion PHxx,PXxx (2 RmNet) */
  1148. {QMI_FIXED_INTF(0x1e2d, 0x0082, 5)}, /* Cinterion PHxx,PXxx (2 RmNet) */
  1149. {QMI_FIXED_INTF(0x1e2d, 0x0083, 4)}, /* Cinterion PHxx,PXxx (1 RmNet + USB Audio)*/
  1150. {QMI_QUIRK_SET_DTR(0x1e2d, 0x00b0, 4)}, /* Cinterion CLS8 */
  1151. {QMI_FIXED_INTF(0x1e2d, 0x00b7, 0)}, /* Cinterion MV31 RmNet */
  1152. {QMI_FIXED_INTF(0x413c, 0x81a2, 8)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */
  1153. {QMI_FIXED_INTF(0x413c, 0x81a3, 8)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */
  1154. {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
  1155. {QMI_FIXED_INTF(0x413c, 0x81a8, 8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */
  1156. {QMI_FIXED_INTF(0x413c, 0x81a9, 8)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */
  1157. {QMI_FIXED_INTF(0x413c, 0x81b1, 8)}, /* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card */
  1158. {QMI_FIXED_INTF(0x413c, 0x81b3, 8)}, /* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card (rev3) */
  1159. {QMI_FIXED_INTF(0x413c, 0x81b6, 8)}, /* Dell Wireless 5811e */
  1160. {QMI_FIXED_INTF(0x413c, 0x81b6, 10)}, /* Dell Wireless 5811e */
  1161. {QMI_FIXED_INTF(0x413c, 0x81cc, 8)}, /* Dell Wireless 5816e */
  1162. {QMI_FIXED_INTF(0x413c, 0x81d7, 0)}, /* Dell Wireless 5821e */
  1163. {QMI_FIXED_INTF(0x413c, 0x81d7, 1)}, /* Dell Wireless 5821e preproduction config */
  1164. {QMI_FIXED_INTF(0x413c, 0x81e0, 0)}, /* Dell Wireless 5821e with eSIM support*/
  1165. {QMI_FIXED_INTF(0x03f0, 0x4e1d, 8)}, /* HP lt4111 LTE/EV-DO/HSPA+ Gobi 4G Module */
  1166. {QMI_FIXED_INTF(0x03f0, 0x9d1d, 1)}, /* HP lt4120 Snapdragon X5 LTE */
  1167. {QMI_FIXED_INTF(0x22de, 0x9061, 3)}, /* WeTelecom WPD-600N */
  1168. {QMI_QUIRK_SET_DTR(0x1e0e, 0x9001, 5)}, /* SIMCom 7100E, 7230E, 7600E ++ */
  1169. {QMI_QUIRK_SET_DTR(0x2c7c, 0x0121, 4)}, /* Quectel EC21 Mini PCIe */
  1170. {QMI_QUIRK_SET_DTR(0x2c7c, 0x0191, 4)}, /* Quectel EG91 */
  1171. {QMI_QUIRK_SET_DTR(0x2c7c, 0x0195, 4)}, /* Quectel EG95 */
  1172. {QMI_FIXED_INTF(0x2c7c, 0x0296, 4)}, /* Quectel BG96 */
  1173. {QMI_QUIRK_SET_DTR(0x2cb7, 0x0104, 4)}, /* Fibocom NL678 series */
  1174. {QMI_FIXED_INTF(0x0489, 0xe0b4, 0)}, /* Foxconn T77W968 LTE */
  1175. {QMI_FIXED_INTF(0x0489, 0xe0b5, 0)}, /* Foxconn T77W968 LTE with eSIM support*/
  1176. {QMI_FIXED_INTF(0x2692, 0x9025, 4)}, /* Cellient MPL200 (rebranded Qualcomm 05c6:9025) */
  1177. /* 4. Gobi 1000 devices */
  1178. {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
  1179. {QMI_GOBI1K_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
  1180. {QMI_GOBI1K_DEVICE(0x04da, 0x250d)}, /* Panasonic Gobi Modem device */
  1181. {QMI_GOBI1K_DEVICE(0x413c, 0x8172)}, /* Dell Gobi Modem device */
  1182. {QMI_GOBI1K_DEVICE(0x1410, 0xa001)}, /* Novatel/Verizon USB-1000 */
  1183. {QMI_GOBI1K_DEVICE(0x1410, 0xa002)}, /* Novatel Gobi Modem device */
  1184. {QMI_GOBI1K_DEVICE(0x1410, 0xa003)}, /* Novatel Gobi Modem device */
  1185. {QMI_GOBI1K_DEVICE(0x1410, 0xa004)}, /* Novatel Gobi Modem device */
  1186. {QMI_GOBI1K_DEVICE(0x1410, 0xa005)}, /* Novatel Gobi Modem device */
  1187. {QMI_GOBI1K_DEVICE(0x1410, 0xa006)}, /* Novatel Gobi Modem device */
  1188. {QMI_GOBI1K_DEVICE(0x1410, 0xa007)}, /* Novatel Gobi Modem device */
  1189. {QMI_GOBI1K_DEVICE(0x0b05, 0x1776)}, /* Asus Gobi Modem device */
  1190. {QMI_GOBI1K_DEVICE(0x19d2, 0xfff3)}, /* ONDA Gobi Modem device */
  1191. {QMI_GOBI1K_DEVICE(0x05c6, 0x9001)}, /* Generic Gobi Modem device */
  1192. {QMI_GOBI1K_DEVICE(0x05c6, 0x9002)}, /* Generic Gobi Modem device */
  1193. {QMI_GOBI1K_DEVICE(0x05c6, 0x9202)}, /* Generic Gobi Modem device */
  1194. {QMI_GOBI1K_DEVICE(0x05c6, 0x9203)}, /* Generic Gobi Modem device */
  1195. {QMI_GOBI1K_DEVICE(0x05c6, 0x9222)}, /* Generic Gobi Modem device */
  1196. {QMI_GOBI1K_DEVICE(0x05c6, 0x9009)}, /* Generic Gobi Modem device */
  1197. /* 5. Gobi 2000 and 3000 devices */
  1198. {QMI_GOBI_DEVICE(0x413c, 0x8186)}, /* Dell Gobi 2000 Modem device (N0218, VU936) */
  1199. {QMI_GOBI_DEVICE(0x413c, 0x8194)}, /* Dell Gobi 3000 Composite */
  1200. {QMI_GOBI_DEVICE(0x05c6, 0x920b)}, /* Generic Gobi 2000 Modem device */
  1201. {QMI_GOBI_DEVICE(0x05c6, 0x9225)}, /* Sony Gobi 2000 Modem device (N0279, VU730) */
  1202. {QMI_GOBI_DEVICE(0x05c6, 0x9245)}, /* Samsung Gobi 2000 Modem device (VL176) */
  1203. {QMI_GOBI_DEVICE(0x03f0, 0x251d)}, /* HP Gobi 2000 Modem device (VP412) */
  1204. {QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */
  1205. {QMI_FIXED_INTF(0x05c6, 0x9215, 4)}, /* Quectel EC20 Mini PCIe */
  1206. {QMI_GOBI_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modem device (VR305) */
  1207. {QMI_GOBI_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000 Modem device (VR306) */
  1208. {QMI_GOBI_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi 2000 Modem device (VR307) */
  1209. {QMI_GOBI_DEVICE(0x0af0, 0x8120)}, /* Option GTM681W */
  1210. {QMI_GOBI_DEVICE(0x1199, 0x68a5)}, /* Sierra Wireless Modem */
  1211. {QMI_GOBI_DEVICE(0x1199, 0x68a9)}, /* Sierra Wireless Modem */
  1212. {QMI_GOBI_DEVICE(0x1199, 0x9001)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1213. {QMI_GOBI_DEVICE(0x1199, 0x9002)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1214. {QMI_GOBI_DEVICE(0x1199, 0x9003)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1215. {QMI_GOBI_DEVICE(0x1199, 0x9004)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1216. {QMI_GOBI_DEVICE(0x1199, 0x9005)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1217. {QMI_GOBI_DEVICE(0x1199, 0x9006)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1218. {QMI_GOBI_DEVICE(0x1199, 0x9007)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1219. {QMI_GOBI_DEVICE(0x1199, 0x9008)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1220. {QMI_GOBI_DEVICE(0x1199, 0x9009)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1221. {QMI_GOBI_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
  1222. {QMI_GOBI_DEVICE(0x1199, 0x9011)}, /* Sierra Wireless Gobi 2000 Modem device (MC8305) */
  1223. {QMI_GOBI_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */
  1224. {QMI_GOBI_DEVICE(0x05c6, 0x9205)}, /* Gobi 2000 Modem device */
  1225. {QMI_GOBI_DEVICE(0x1199, 0x9013)}, /* Sierra Wireless Gobi 3000 Modem device (MC8355) */
  1226. {QMI_GOBI_DEVICE(0x03f0, 0x371d)}, /* HP un2430 Mobile Broadband Module */
  1227. {QMI_GOBI_DEVICE(0x1199, 0x9015)}, /* Sierra Wireless Gobi 3000 Modem device */
  1228. {QMI_GOBI_DEVICE(0x1199, 0x9019)}, /* Sierra Wireless Gobi 3000 Modem device */
  1229. {QMI_GOBI_DEVICE(0x1199, 0x901b)}, /* Sierra Wireless MC7770 */
  1230. {QMI_GOBI_DEVICE(0x12d1, 0x14f1)}, /* Sony Gobi 3000 Composite */
  1231. {QMI_GOBI_DEVICE(0x1410, 0xa021)}, /* Foxconn Gobi 3000 Modem device (Novatel E396) */
  1232. { } /* END */
  1233. };
  1234. MODULE_DEVICE_TABLE(usb, products);
  1235. static bool quectel_ec20_detected(struct usb_interface *intf)
  1236. {
  1237. struct usb_device *dev = interface_to_usbdev(intf);
  1238. if (dev->actconfig &&
  1239. le16_to_cpu(dev->descriptor.idVendor) == 0x05c6 &&
  1240. le16_to_cpu(dev->descriptor.idProduct) == 0x9215 &&
  1241. dev->actconfig->desc.bNumInterfaces == 5)
  1242. return true;
  1243. return false;
  1244. }
  1245. static int qmi_wwan_probe(struct usb_interface *intf,
  1246. const struct usb_device_id *prod)
  1247. {
  1248. struct usb_device_id *id = (struct usb_device_id *)prod;
  1249. struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc;
  1250. /* Workaround to enable dynamic IDs. This disables usbnet
  1251. * blacklisting functionality. Which, if required, can be
  1252. * reimplemented here by using a magic "blacklist" value
  1253. * instead of 0 in the static device id table
  1254. */
  1255. if (!id->driver_info) {
  1256. dev_dbg(&intf->dev, "setting defaults for dynamic device id\n");
  1257. id->driver_info = (unsigned long)&qmi_wwan_info;
  1258. }
  1259. /* There are devices where the same interface number can be
  1260. * configured as different functions. We should only bind to
  1261. * vendor specific functions when matching on interface number
  1262. */
  1263. if (id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER &&
  1264. desc->bInterfaceClass != USB_CLASS_VENDOR_SPEC) {
  1265. dev_dbg(&intf->dev,
  1266. "Rejecting interface number match for class %02x\n",
  1267. desc->bInterfaceClass);
  1268. return -ENODEV;
  1269. }
  1270. /* Quectel EC20 quirk where we've QMI on interface 4 instead of 0 */
  1271. if (quectel_ec20_detected(intf) && desc->bInterfaceNumber == 0) {
  1272. dev_dbg(&intf->dev, "Quectel EC20 quirk, skipping interface 0\n");
  1273. return -ENODEV;
  1274. }
  1275. /* Several Quectel modems supports dynamic interface configuration, so
  1276. * we need to match on class/subclass/protocol. These values are
  1277. * identical for the diagnostic- and QMI-interface, but bNumEndpoints is
  1278. * different. Ignore the current interface if the number of endpoints
  1279. * equals the number for the diag interface (two).
  1280. */
  1281. if (desc->bNumEndpoints == 2)
  1282. return -ENODEV;
  1283. return usbnet_probe(intf, id);
  1284. }
  1285. static void qmi_wwan_disconnect(struct usb_interface *intf)
  1286. {
  1287. struct usbnet *dev = usb_get_intfdata(intf);
  1288. struct qmi_wwan_state *info;
  1289. struct list_head *iter;
  1290. struct net_device *ldev;
  1291. LIST_HEAD(list);
  1292. /* called twice if separate control and data intf */
  1293. if (!dev)
  1294. return;
  1295. info = (void *)&dev->data;
  1296. if (info->flags & QMI_WWAN_FLAG_MUX) {
  1297. if (!rtnl_trylock()) {
  1298. restart_syscall();
  1299. return;
  1300. }
  1301. rcu_read_lock();
  1302. netdev_for_each_upper_dev_rcu(dev->net, ldev, iter)
  1303. qmimux_unregister_device(ldev, &list);
  1304. rcu_read_unlock();
  1305. unregister_netdevice_many(&list);
  1306. rtnl_unlock();
  1307. info->flags &= ~QMI_WWAN_FLAG_MUX;
  1308. }
  1309. usbnet_disconnect(intf);
  1310. }
  1311. static struct usb_driver qmi_wwan_driver = {
  1312. .name = "qmi_wwan",
  1313. .id_table = products,
  1314. .probe = qmi_wwan_probe,
  1315. .disconnect = qmi_wwan_disconnect,
  1316. .suspend = qmi_wwan_suspend,
  1317. .resume = qmi_wwan_resume,
  1318. .reset_resume = qmi_wwan_resume,
  1319. .supports_autosuspend = 1,
  1320. .disable_hub_initiated_lpm = 1,
  1321. };
  1322. module_usb_driver(qmi_wwan_driver);
  1323. MODULE_AUTHOR("Bjørn Mork <bjorn@mork.no>");
  1324. MODULE_DESCRIPTION("Qualcomm MSM Interface (QMI) WWAN driver");
  1325. MODULE_LICENSE("GPL");