Lines Matching refs:atusb

45 struct atusb {  struct
77 static int atusb_write_subreg(struct atusb *atusb, u8 reg, u8 mask, in atusb_write_subreg() argument
80 struct usb_device *usb_dev = atusb->usb_dev; in atusb_write_subreg()
104 static int atusb_read_subreg(struct atusb *lp, in atusb_read_subreg()
120 static int atusb_get_and_clear_error(struct atusb *atusb) in atusb_get_and_clear_error() argument
122 int err = atusb->err; in atusb_get_and_clear_error()
124 atusb->err = 0; in atusb_get_and_clear_error()
133 #define SKB_ATUSB(skb) (*(struct atusb **)(skb)->cb)
137 static int atusb_submit_rx_urb(struct atusb *atusb, struct urb *urb) in atusb_submit_rx_urb() argument
139 struct usb_device *usb_dev = atusb->usb_dev; in atusb_submit_rx_urb()
151 SKB_ATUSB(skb) = atusb; in atusb_submit_rx_urb()
156 usb_anchor_urb(urb, &atusb->rx_urbs); in atusb_submit_rx_urb()
169 struct atusb *atusb = in atusb_work_urbs() local
170 container_of(to_delayed_work(work), struct atusb, work); in atusb_work_urbs()
171 struct usb_device *usb_dev = atusb->usb_dev; in atusb_work_urbs()
175 if (atusb->shutdown) in atusb_work_urbs()
179 urb = usb_get_from_anchor(&atusb->idle_urbs); in atusb_work_urbs()
182 ret = atusb_submit_rx_urb(atusb, urb); in atusb_work_urbs()
185 usb_anchor_urb(urb, &atusb->idle_urbs); in atusb_work_urbs()
188 schedule_delayed_work(&atusb->work, in atusb_work_urbs()
194 static void atusb_tx_done(struct atusb *atusb, u8 seq, int reason) in atusb_tx_done() argument
196 struct usb_device *usb_dev = atusb->usb_dev; in atusb_tx_done()
197 u8 expect = atusb->tx_ack_seq; in atusb_tx_done()
203 ieee802154_xmit_complete(atusb->hw, atusb->tx_skb, false); in atusb_tx_done()
205 ieee802154_xmit_error(atusb->hw, atusb->tx_skb, reason); in atusb_tx_done()
212 ieee802154_xmit_hw_error(atusb->hw, atusb->tx_skb); in atusb_tx_done()
220 struct atusb *atusb = SKB_ATUSB(skb); in atusb_in_good() local
251 atusb_tx_done(atusb, len, result); in atusb_in_good()
270 ieee802154_rx_irqsafe(atusb->hw, skb, lqi); in atusb_in_good()
278 struct atusb *atusb = SKB_ATUSB(skb); in atusb_in() local
293 usb_anchor_urb(urb, &atusb->idle_urbs); in atusb_in()
294 if (!atusb->shutdown) in atusb_in()
295 schedule_delayed_work(&atusb->work, 0); in atusb_in()
300 static void atusb_free_urbs(struct atusb *atusb) in atusb_free_urbs() argument
305 urb = usb_get_from_anchor(&atusb->idle_urbs); in atusb_free_urbs()
313 static int atusb_alloc_urbs(struct atusb *atusb, int n) in atusb_alloc_urbs() argument
320 atusb_free_urbs(atusb); in atusb_alloc_urbs()
323 usb_anchor_urb(urb, &atusb->idle_urbs); in atusb_alloc_urbs()
339 struct atusb *atusb = hw->priv; in atusb_xmit() local
340 struct usb_device *usb_dev = atusb->usb_dev; in atusb_xmit()
344 atusb->tx_skb = skb; in atusb_xmit()
345 atusb->tx_ack_seq++; in atusb_xmit()
346 atusb->tx_dr.wIndex = cpu_to_le16(atusb->tx_ack_seq); in atusb_xmit()
347 atusb->tx_dr.wLength = cpu_to_le16(skb->len); in atusb_xmit()
349 usb_fill_control_urb(atusb->tx_urb, usb_dev, in atusb_xmit()
351 (unsigned char *)&atusb->tx_dr, skb->data, in atusb_xmit()
353 ret = usb_submit_urb(atusb->tx_urb, GFP_ATOMIC); in atusb_xmit()
369 struct atusb *atusb = hw->priv; in atusb_set_hw_addr_filt() local
370 struct device *dev = &atusb->usb_dev->dev; in atusb_set_hw_addr_filt()
376 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_set_hw_addr_filt()
379 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_set_hw_addr_filt()
387 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_set_hw_addr_filt()
390 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_set_hw_addr_filt()
400 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_set_hw_addr_filt()
408 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 1); in atusb_set_hw_addr_filt()
410 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 0); in atusb_set_hw_addr_filt()
413 return atusb_get_and_clear_error(atusb); in atusb_set_hw_addr_filt()
418 struct atusb *atusb = hw->priv; in atusb_start() local
419 struct usb_device *usb_dev = atusb->usb_dev; in atusb_start()
423 schedule_delayed_work(&atusb->work, 0); in atusb_start()
424 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_RX_MODE, ATUSB_REQ_TO_DEV, 1, 0, in atusb_start()
426 ret = atusb_get_and_clear_error(atusb); in atusb_start()
428 usb_kill_anchored_urbs(&atusb->idle_urbs); in atusb_start()
434 struct atusb *atusb = hw->priv; in atusb_stop() local
435 struct usb_device *usb_dev = atusb->usb_dev; in atusb_stop()
438 usb_kill_anchored_urbs(&atusb->idle_urbs); in atusb_stop()
439 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_RX_MODE, ATUSB_REQ_TO_DEV, 0, 0, in atusb_stop()
441 atusb_get_and_clear_error(atusb); in atusb_stop()
453 struct atusb *atusb = hw->priv; in atusb_txpower() local
455 if (atusb->data) in atusb_txpower()
456 return atusb->data->set_txpower(hw, mbm); in atusb_txpower()
464 struct atusb *atusb = hw->priv; in atusb_set_txpower() local
469 return atusb_write_subreg(atusb, SR_TX_PWR_23X, i); in atusb_set_txpower()
515 struct atusb *atusb = hw->priv; in atusb_set_cca_mode() local
542 return atusb_write_subreg(atusb, SR_CCA_MODE, val); in atusb_set_cca_mode()
545 static int hulusb_set_cca_ed_level(struct atusb *lp, int rssi_base_val) in hulusb_set_cca_ed_level()
574 struct atusb *atusb = hw->priv; in atusb_set_cca_ed_level() local
579 return atusb_write_subreg(atusb, SR_CCA_ED_THRES, i); in atusb_set_cca_ed_level()
587 struct atusb *atusb = hw->priv; in atusb_channel() local
590 if (atusb->data) { in atusb_channel()
591 ret = atusb->data->set_channel(hw, page, channel); in atusb_channel()
593 msleep(atusb->data->t_channel_switch); in atusb_channel()
601 struct atusb *atusb = hw->priv; in atusb_set_channel() local
604 ret = atusb_write_subreg(atusb, SR_CHANNEL, channel); in atusb_set_channel()
615 struct atusb *lp = hw->priv; in hulusb_set_channel()
644 struct atusb *atusb = hw->priv; in atusb_set_csma_params() local
647 ret = atusb_write_subreg(atusb, SR_MIN_BE, min_be); in atusb_set_csma_params()
651 ret = atusb_write_subreg(atusb, SR_MAX_BE, max_be); in atusb_set_csma_params()
655 return atusb_write_subreg(atusb, SR_MAX_CSMA_RETRIES, retries); in atusb_set_csma_params()
661 struct atusb *atusb = hw->priv; in hulusb_set_lbt() local
663 return atusb_write_subreg(atusb, SR_CSMA_LBT_MODE, on); in hulusb_set_lbt()
669 struct atusb *atusb = hw->priv; in atusb_set_frame_retries() local
671 return atusb_write_subreg(atusb, SR_MAX_FRAME_RETRIES, retries); in atusb_set_frame_retries()
677 struct atusb *atusb = hw->priv; in atusb_set_promiscuous_mode() local
681 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 1); in atusb_set_promiscuous_mode()
685 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 1); in atusb_set_promiscuous_mode()
689 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 0); in atusb_set_promiscuous_mode()
693 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 0); in atusb_set_promiscuous_mode()
734 static int atusb_get_and_show_revision(struct atusb *atusb) in atusb_get_and_show_revision() argument
736 struct usb_device *usb_dev = atusb->usb_dev; in atusb_get_and_show_revision()
742 ret = usb_control_msg_recv(atusb->usb_dev, 0, ATUSB_ID, ATUSB_REQ_FROM_DEV, 0, 0, in atusb_get_and_show_revision()
745 atusb->fw_ver_maj = buffer[0]; in atusb_get_and_show_revision()
746 atusb->fw_ver_min = buffer[1]; in atusb_get_and_show_revision()
747 atusb->fw_hw_type = buffer[2]; in atusb_get_and_show_revision()
749 switch (atusb->fw_hw_type) { in atusb_get_and_show_revision()
754 atusb->data = &atusb_chip_data; in atusb_get_and_show_revision()
758 atusb->data = &atusb_chip_data; in atusb_get_and_show_revision()
762 atusb->data = &hulusb_chip_data; in atusb_get_and_show_revision()
766 atusb->err = -ENOTSUPP; in atusb_get_and_show_revision()
773 atusb->fw_ver_maj, atusb->fw_ver_min, hw_name, in atusb_get_and_show_revision()
774 atusb->fw_hw_type); in atusb_get_and_show_revision()
776 if (atusb->fw_ver_maj == 0 && atusb->fw_ver_min < 2) { in atusb_get_and_show_revision()
779 atusb->fw_ver_maj, atusb->fw_ver_min); in atusb_get_and_show_revision()
786 static int atusb_get_and_show_build(struct atusb *atusb) in atusb_get_and_show_build() argument
788 struct usb_device *usb_dev = atusb->usb_dev; in atusb_get_and_show_build()
796 ret = usb_control_msg(atusb->usb_dev, usb_rcvctrlpipe(usb_dev, 0), ATUSB_BUILD, in atusb_get_and_show_build()
807 static int atusb_get_and_conf_chip(struct atusb *atusb) in atusb_get_and_conf_chip() argument
809 struct usb_device *usb_dev = atusb->usb_dev; in atusb_get_and_conf_chip()
812 struct ieee802154_hw *hw = atusb->hw; in atusb_get_and_conf_chip()
861 atusb->hw->phy->supported.channels[0] = 0x7FFF800; in atusb_get_and_conf_chip()
862 atusb->hw->phy->current_channel = 11; /* reset default */ in atusb_get_and_conf_chip()
863 atusb->hw->phy->supported.tx_powers = atusb_powers; in atusb_get_and_conf_chip()
864 atusb->hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers); in atusb_get_and_conf_chip()
870 atusb->hw->phy->supported.channels[0] = 0x7FFF800; in atusb_get_and_conf_chip()
871 atusb->hw->phy->current_channel = 11; /* reset default */ in atusb_get_and_conf_chip()
872 atusb->hw->phy->supported.tx_powers = atusb_powers; in atusb_get_and_conf_chip()
873 atusb->hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers); in atusb_get_and_conf_chip()
879 atusb->hw->flags |= IEEE802154_HW_LBT; in atusb_get_and_conf_chip()
880 atusb->hw->phy->supported.channels[0] = 0x00007FF; in atusb_get_and_conf_chip()
881 atusb->hw->phy->supported.channels[2] = 0x00007FF; in atusb_get_and_conf_chip()
882 atusb->hw->phy->current_channel = 5; in atusb_get_and_conf_chip()
883 atusb->hw->phy->supported.lbt = NL802154_SUPPORTED_BOOL_BOTH; in atusb_get_and_conf_chip()
884 atusb->hw->phy->supported.tx_powers = at86rf212_powers; in atusb_get_and_conf_chip()
885 atusb->hw->phy->supported.tx_powers_size = ARRAY_SIZE(at86rf212_powers); in atusb_get_and_conf_chip()
886 atusb->hw->phy->supported.cca_ed_levels = at86rf212_ed_levels_100; in atusb_get_and_conf_chip()
887 atusb->hw->phy->supported.cca_ed_levels_size = ARRAY_SIZE(at86rf212_ed_levels_100); in atusb_get_and_conf_chip()
904 atusb->err = -ENODEV; in atusb_get_and_conf_chip()
908 static int atusb_set_extended_addr(struct atusb *atusb) in atusb_set_extended_addr() argument
910 struct usb_device *usb_dev = atusb->usb_dev; in atusb_set_extended_addr()
919 if (atusb->fw_ver_maj == 0 && atusb->fw_ver_min < 3) { in atusb_set_extended_addr()
920 ieee802154_random_extended_addr(&atusb->hw->phy->perm_extended_addr); in atusb_set_extended_addr()
925 ret = usb_control_msg_recv(atusb->usb_dev, 0, ATUSB_EUI64_READ, ATUSB_REQ_FROM_DEV, 0, 0, in atusb_set_extended_addr()
929 ieee802154_random_extended_addr(&atusb->hw->phy->perm_extended_addr); in atusb_set_extended_addr()
937 ieee802154_random_extended_addr(&atusb->hw->phy->perm_extended_addr); in atusb_set_extended_addr()
939 atusb->hw->phy->perm_extended_addr = extended_addr; in atusb_set_extended_addr()
940 addr = swab64((__force u64)atusb->hw->phy->perm_extended_addr); in atusb_set_extended_addr()
955 struct atusb *atusb = NULL; in atusb_probe() local
958 hw = ieee802154_alloc_hw(sizeof(struct atusb), &atusb_ops); in atusb_probe()
962 atusb = hw->priv; in atusb_probe()
963 atusb->hw = hw; in atusb_probe()
964 atusb->usb_dev = usb_get_dev(usb_dev); in atusb_probe()
965 usb_set_intfdata(interface, atusb); in atusb_probe()
967 atusb->shutdown = 0; in atusb_probe()
968 atusb->err = 0; in atusb_probe()
969 INIT_DELAYED_WORK(&atusb->work, atusb_work_urbs); in atusb_probe()
970 init_usb_anchor(&atusb->idle_urbs); in atusb_probe()
971 init_usb_anchor(&atusb->rx_urbs); in atusb_probe()
973 if (atusb_alloc_urbs(atusb, ATUSB_NUM_RX_URBS)) in atusb_probe()
976 atusb->tx_dr.bRequestType = ATUSB_REQ_TO_DEV; in atusb_probe()
977 atusb->tx_dr.bRequest = ATUSB_TX; in atusb_probe()
978 atusb->tx_dr.wValue = cpu_to_le16(0); in atusb_probe()
980 atusb->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in atusb_probe()
981 if (!atusb->tx_urb) in atusb_probe()
986 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_RF_RESET, ATUSB_REQ_TO_DEV, 0, 0, in atusb_probe()
988 atusb_get_and_conf_chip(atusb); in atusb_probe()
989 atusb_get_and_show_revision(atusb); in atusb_probe()
990 atusb_get_and_show_build(atusb); in atusb_probe()
991 atusb_set_extended_addr(atusb); in atusb_probe()
993 if ((atusb->fw_ver_maj == 0 && atusb->fw_ver_min >= 3) || atusb->fw_ver_maj > 0) in atusb_probe()
996 ret = atusb_get_and_clear_error(atusb); in atusb_probe()
998 dev_err(&atusb->usb_dev->dev, in atusb_probe()
1012 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_probe()
1040 atusb_write_subreg(atusb, SR_RX_SAFE_MODE, 1); in atusb_probe()
1042 usb_control_msg_send(atusb->usb_dev, 0, ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV, in atusb_probe()
1045 ret = atusb_get_and_clear_error(atusb); in atusb_probe()
1049 dev_err(&atusb->usb_dev->dev, in atusb_probe()
1055 atusb_free_urbs(atusb); in atusb_probe()
1056 usb_kill_urb(atusb->tx_urb); in atusb_probe()
1057 usb_free_urb(atusb->tx_urb); in atusb_probe()
1065 struct atusb *atusb = usb_get_intfdata(interface); in atusb_disconnect() local
1067 dev_dbg(&atusb->usb_dev->dev, "%s\n", __func__); in atusb_disconnect()
1069 atusb->shutdown = 1; in atusb_disconnect()
1070 cancel_delayed_work_sync(&atusb->work); in atusb_disconnect()
1072 usb_kill_anchored_urbs(&atusb->rx_urbs); in atusb_disconnect()
1073 atusb_free_urbs(atusb); in atusb_disconnect()
1074 usb_kill_urb(atusb->tx_urb); in atusb_disconnect()
1075 usb_free_urb(atusb->tx_urb); in atusb_disconnect()
1077 ieee802154_unregister_hw(atusb->hw); in atusb_disconnect()
1079 usb_put_dev(atusb->usb_dev); in atusb_disconnect()
1081 ieee802154_free_hw(atusb->hw); in atusb_disconnect()